Skip to content

Commit 0d9c224

Browse files
committed
Bugfix for covering indexes, Fixes work with more than 3-level indexes
1 parent 18061a5 commit 0d9c224

File tree

7 files changed

+11
-17
lines changed

7 files changed

+11
-17
lines changed

contrib/tcn/tcn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ triggered_change_notification(PG_FUNCTION_ARGS)
138138
/* we're only interested if it is the primary key and valid */
139139
if (index->indisprimary && IndexIsValid(index))
140140
{
141-
int indnkeyatts = index->indnkeyatts;
141+
int indnkeyatts = index->indnkeyatts;
142142

143143
if (indnkeyatts > 0)
144144
{

src/backend/access/index/genam.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ IndexScanEnd(IndexScanDesc scan)
157157
*
158158
* Construct a string describing the contents of an index entry, in the
159159
* form "(key_name, ...)=(key_value, ...)". This is currently used
160-
* for building unique-constraint and exclusion-constraint error messages.
160+
* for building unique-constraint and exclusion-constraint error messages,
161+
* so only key columns of index are checked and printed.
161162
*
162163
* Note that if the user does not have permissions to view all of the
163164
* columns involved then a NULL is returned. Returning a partial key seems
@@ -183,7 +184,6 @@ BuildIndexValueDescription(Relation indexRelation,
183184
AclResult aclresult;
184185

185186
indnkeyatts = IndexRelationGetNumberOfKeyAttributes(indexRelation);
186-
187187
/*
188188
* Check permissions- if the user does not have access to view all of the
189189
* key columns then return NULL to avoid leaking data.

src/backend/access/nbtree/nbtinsert.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,6 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
19821982
itemid = PageGetItemId(lpage, P_HIKEY);
19831983
right_item_sz = ItemIdGetLength(itemid);
19841984
item = (IndexTuple) PageGetItem(lpage, itemid);
1985-
19861985
right_item = CopyIndexTuple(item);
19871986
ItemPointerSet(&(right_item->t_tid), rbkno, P_HIKEY);
19881987

src/backend/access/nbtree/nbtsearch.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,6 @@ _bt_compare(Relation rel,
431431

432432
itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
433433

434-
Assert (keysz <= rel->rd_index->indnkeyatts);
435-
436434
/*
437435
* The scan key is set up with the attribute number associated with each
438436
* term in the key. It is important that, if the index is multi-key, the

src/backend/access/nbtree/nbtsort.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -580,15 +580,12 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
580580
* Save a copy of the minimum key for the new page. We have to copy
581581
* it off the old page, not the new one, in case we are not at leaf
582582
* level.
583-
* If tuple contains non-key attributes, truncate them.
584-
* We perform truncation only for leaf pages,
585-
* beacuse all tuples at inner pages will be already
586-
* truncated by the time we handle them.
583+
* Despite oitup is already initialized, it's important to get high
584+
* key from the page, since we could have replaced it with truncated
585+
* copy. See comment above.
587586
*/
588-
if (indnkeyatts != indnatts && P_ISLEAF(opageop))
589-
state->btps_minkey = index_truncate_tuple(wstate->index, oitup);
590-
else
591-
state->btps_minkey = CopyIndexTuple(oitup);
587+
oitup = (IndexTuple) PageGetItem(opage,PageGetItemId(opage, P_HIKEY));
588+
state->btps_minkey = CopyIndexTuple(oitup);
592589

593590
/*
594591
* Set the sibling links for both pages.

src/backend/access/nbtree/nbtutils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ _bt_mkscankey(Relation rel, IndexTuple itup)
6464
{
6565
ScanKey skey;
6666
TupleDesc itupdesc;
67-
int indnatts,
67+
int indnatts,
6868
indnkeyatts;
6969
int16 *indoption;
7070
int i;
@@ -125,7 +125,7 @@ ScanKey
125125
_bt_mkscankey_nodata(Relation rel)
126126
{
127127
ScanKey skey;
128-
int indnkeyatts;
128+
int indnkeyatts;
129129
int16 *indoption;
130130
int i;
131131

src/backend/optimizer/util/plancat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ infer_arbiter_indexes(PlannerInfo *root)
586586

587587
/* Build BMS representation of plain (non expression) index attrs */
588588
indexedAttrs = NULL;
589-
for (natt = 0; natt < idxForm->indnatts; natt++)
589+
for (natt = 0; natt < idxForm->indnkeyatts; natt++)
590590
{
591591
int attno = idxRel->rd_index->indkey.values[natt];
592592

0 commit comments

Comments
 (0)