Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2a9e04f

Browse files
committed
Don't truncate away non-key attributes for leftmost downlinks.
nbtsort.c does not need to truncate away non-key attributes for the minimum key of the leftmost page on a level, since this is only used to build a minus infinity downlink for the level's leftmost page. Truncating away non-key attributes in advance of truncating away all attributes in _bt_sortaddtup() does not affect the correctness of CREATE INDEX, but it is misleading. Author: Peter Geoghegan Discussion: https://www.postgresql.org/message-id/CAH2-WzkAS2M3ussHG-s_Av=Zo6dPjOxyu5fNRkYnxQV+YzGQ4w@mail.gmail.com
1 parent 0bef1c0 commit 2a9e04f

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/backend/access/nbtree/nbtsort.c

+14-16
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,10 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
934934
state->btps_next = _bt_pagestate(wstate, state->btps_level + 1);
935935

936936
Assert(BTreeTupleGetNAtts(state->btps_minkey, wstate->index) ==
937-
IndexRelationGetNumberOfKeyAttributes(wstate->index));
937+
IndexRelationGetNumberOfKeyAttributes(wstate->index) ||
938+
P_LEFTMOST(opageop));
939+
Assert(BTreeTupleGetNAtts(state->btps_minkey, wstate->index) == 0 ||
940+
!P_LEFTMOST(opageop));
938941
BTreeInnerTupleSetDownLink(state->btps_minkey, oblkno);
939942
_bt_buildadd(wstate, state->btps_next, state->btps_minkey);
940943
pfree(state->btps_minkey);
@@ -974,24 +977,16 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
974977
* If the new item is the first for its page, stash a copy for later. Note
975978
* this will only happen for the first item on a level; on later pages,
976979
* the first item for a page is copied from the prior page in the code
977-
* above.
980+
* above. Since the minimum key for an entire level is only used as a
981+
* minus infinity downlink, and never as a high key, there is no need to
982+
* truncate away non-key attributes at this point.
978983
*/
979984
if (last_off == P_HIKEY)
980985
{
981-
BTPageOpaque npageop;
982-
983986
Assert(state->btps_minkey == NULL);
984-
985-
npageop = (BTPageOpaque) PageGetSpecialPointer(npage);
986-
987-
/*
988-
* Truncate included attributes of the tuple that we're going to
989-
* insert into the parent page as a downlink
990-
*/
991-
if (indnkeyatts != indnatts && P_ISLEAF(npageop))
992-
state->btps_minkey = _bt_nonkey_truncate(wstate->index, itup);
993-
else
994-
state->btps_minkey = CopyIndexTuple(itup);
987+
state->btps_minkey = CopyIndexTuple(itup);
988+
/* _bt_sortaddtup() will perform full truncation later */
989+
BTreeTupleSetNAtts(state->btps_minkey, 0);
995990
}
996991

997992
/*
@@ -1044,7 +1039,10 @@ _bt_uppershutdown(BTWriteState *wstate, BTPageState *state)
10441039
else
10451040
{
10461041
Assert(BTreeTupleGetNAtts(s->btps_minkey, wstate->index) ==
1047-
IndexRelationGetNumberOfKeyAttributes(wstate->index));
1042+
IndexRelationGetNumberOfKeyAttributes(wstate->index) ||
1043+
P_LEFTMOST(opaque));
1044+
Assert(BTreeTupleGetNAtts(s->btps_minkey, wstate->index) == 0 ||
1045+
!P_LEFTMOST(opaque));
10481046
BTreeInnerTupleSetDownLink(s->btps_minkey, blkno);
10491047
_bt_buildadd(wstate, s->btps_next, s->btps_minkey);
10501048
pfree(s->btps_minkey);

0 commit comments

Comments
 (0)