Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite86c8ef

Browse files
Use "low key" terminology in nbtsort.c.
nbtree index builds once stashed the "minimum key" for a page, which wasused as the basis of the pivot tuple that gets placed in the next levelup (i.e. the tuple that stores the downlink to the page in question).It doesn't quite work that way anymore, so the "minimum key" terminologynow seems misleading (these days the minimum key is actually a straightcopy of the high key from the left sibling, which is a distinct thing insubtle but important ways). Rename this concept to "low key". Thisname is a lot clearer given that there is now a sharp distinctionbetween pivot and non-pivot tuples. Also remove comments that describeobsolete details about how the minimum key concept used to work.Rather than generating the minus infinity item for the leftmost page ona level by copying the new item and truncating that copy, simplyallocate a small buffer. The old approach confusingly created theimpression that the new item had some kind of significance. This wasanother artifact of how things used to work before commits8224de4 anddd299df.
1 parentc10fae2 commite86c8ef

File tree

1 file changed

+29
-40
lines changed

1 file changed

+29
-40
lines changed

‎src/backend/access/nbtree/nbtsort.c

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,12 @@ typedef struct BTBuildState
236236
/*
237237
* Status record for a btree page being built. We have one of these
238238
* for each active tree level.
239-
*
240-
* The reason we need to store a copy of the minimum key is that we'll
241-
* need to propagate it to the parent node when this page is linked
242-
* into its parent. However, if the page is not a leaf page, the first
243-
* entry on the page doesn't need to contain a key, so we will not have
244-
* stored the key itself on the page. (You might think we could skip
245-
* copying the minimum key on leaf pages, but actually we must have a
246-
* writable copy anyway because we'll poke the page's address into it
247-
* before passing it up to the parent...)
248239
*/
249240
typedefstructBTPageState
250241
{
251242
Pagebtps_page;/* workspace for page building */
252243
BlockNumberbtps_blkno;/* block # to write this page at */
253-
IndexTuplebtps_minkey;/*copy of minimum key (first item) on page */
244+
IndexTuplebtps_lowkey;/*page's strict lower bound pivot tuple */
254245
OffsetNumberbtps_lastoff;/* last item offset loaded */
255246
uint32btps_level;/* tree level (0 = leaf) */
256247
Sizebtps_full;/* "full" if less than this much free space */
@@ -717,7 +708,7 @@ _bt_pagestate(BTWriteState *wstate, uint32 level)
717708
/* and assign it a page position */
718709
state->btps_blkno=wstate->btws_pages_alloced++;
719710

720-
state->btps_minkey=NULL;
711+
state->btps_lowkey=NULL;
721712
/* initialize lastoff so first item goes into P_FIRSTKEY */
722713
state->btps_lastoff=P_HIKEY;
723714
state->btps_level=level;
@@ -980,28 +971,27 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
980971
}
981972

982973
/*
983-
* Link the old page into its parent, using its minimum key. If we
984-
* don't have a parent, we have to create one; this adds a new btree
985-
* level.
974+
* Link the old page into its parent, using its low key. If we don't
975+
* have a parent, we have to create one; this adds a new btree level.
986976
*/
987977
if (state->btps_next==NULL)
988978
state->btps_next=_bt_pagestate(wstate,state->btps_level+1);
989979

990-
Assert((BTreeTupleGetNAtts(state->btps_minkey,wstate->index) <=
980+
Assert((BTreeTupleGetNAtts(state->btps_lowkey,wstate->index) <=
991981
IndexRelationGetNumberOfKeyAttributes(wstate->index)&&
992-
BTreeTupleGetNAtts(state->btps_minkey,wstate->index)>0)||
982+
BTreeTupleGetNAtts(state->btps_lowkey,wstate->index)>0)||
993983
P_LEFTMOST((BTPageOpaque)PageGetSpecialPointer(opage)));
994-
Assert(BTreeTupleGetNAtts(state->btps_minkey,wstate->index)==0||
984+
Assert(BTreeTupleGetNAtts(state->btps_lowkey,wstate->index)==0||
995985
!P_LEFTMOST((BTPageOpaque)PageGetSpecialPointer(opage)));
996-
BTreeInnerTupleSetDownLink(state->btps_minkey,oblkno);
997-
_bt_buildadd(wstate,state->btps_next,state->btps_minkey);
998-
pfree(state->btps_minkey);
986+
BTreeInnerTupleSetDownLink(state->btps_lowkey,oblkno);
987+
_bt_buildadd(wstate,state->btps_next,state->btps_lowkey);
988+
pfree(state->btps_lowkey);
999989

1000990
/*
1001-
* Save a copy of the high key from the old page. It is alsoused as
1002-
*the minimumkey for the new page.
991+
* Save a copy of the high key from the old page. It is alsothe low
992+
* key for the new page.
1003993
*/
1004-
state->btps_minkey=CopyIndexTuple(oitup);
994+
state->btps_lowkey=CopyIndexTuple(oitup);
1005995

1006996
/*
1007997
* Set the sibling links for both pages.
@@ -1032,18 +1022,17 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
10321022
* was created that became the current page. Either way, the current page
10331023
* definitely has space for new item.
10341024
*
1035-
* If the new item is the first for its page, stash a copy for later. Note
1036-
* this will only happen for the first item on a level; on later pages,
1037-
* the first item for a page is copied from the prior page in the code
1038-
* above. The minimum key for an entire level is nothing more than a
1039-
* minus infinity (downlink only) pivot tuple placeholder.
1025+
* If the new item is the first for its page, it must also be the first
1026+
* item on its entire level. On later same-level pages, a low key for a
1027+
* page will be copied from the prior page in the code above. Generate a
1028+
* minus infinity low key here instead.
10401029
*/
10411030
if (last_off==P_HIKEY)
10421031
{
1043-
Assert(state->btps_minkey==NULL);
1044-
state->btps_minkey=CopyIndexTuple(itup);
1045-
/* _bt_sortaddtup() will perform full truncation later */
1046-
BTreeTupleSetNAtts(state->btps_minkey,0);
1032+
Assert(state->btps_lowkey==NULL);
1033+
state->btps_lowkey=palloc0(sizeof(IndexTupleData));
1034+
state->btps_lowkey->t_info=sizeof(IndexTupleData);
1035+
BTreeTupleSetNAtts(state->btps_lowkey,0);
10471036
}
10481037

10491038
/*
@@ -1083,7 +1072,7 @@ _bt_uppershutdown(BTWriteState *wstate, BTPageState *state)
10831072
* We have to link the last page on this level to somewhere.
10841073
*
10851074
* If we're at the top, it's the root, so attach it to the metapage.
1086-
* Otherwise, add an entry for it to its parent using itsminimum key.
1075+
* Otherwise, add an entry for it to its parent using itslow key.
10871076
* This may cause the last page of the parent level to split, but
10881077
* that's not a problem -- we haven't gotten to it yet.
10891078
*/
@@ -1095,16 +1084,16 @@ _bt_uppershutdown(BTWriteState *wstate, BTPageState *state)
10951084
}
10961085
else
10971086
{
1098-
Assert((BTreeTupleGetNAtts(s->btps_minkey,wstate->index) <=
1087+
Assert((BTreeTupleGetNAtts(s->btps_lowkey,wstate->index) <=
10991088
IndexRelationGetNumberOfKeyAttributes(wstate->index)&&
1100-
BTreeTupleGetNAtts(s->btps_minkey,wstate->index)>0)||
1089+
BTreeTupleGetNAtts(s->btps_lowkey,wstate->index)>0)||
11011090
P_LEFTMOST(opaque));
1102-
Assert(BTreeTupleGetNAtts(s->btps_minkey,wstate->index)==0||
1091+
Assert(BTreeTupleGetNAtts(s->btps_lowkey,wstate->index)==0||
11031092
!P_LEFTMOST(opaque));
1104-
BTreeInnerTupleSetDownLink(s->btps_minkey,blkno);
1105-
_bt_buildadd(wstate,s->btps_next,s->btps_minkey);
1106-
pfree(s->btps_minkey);
1107-
s->btps_minkey=NULL;
1093+
BTreeInnerTupleSetDownLink(s->btps_lowkey,blkno);
1094+
_bt_buildadd(wstate,s->btps_next,s->btps_lowkey);
1095+
pfree(s->btps_lowkey);
1096+
s->btps_lowkey=NULL;
11081097
}
11091098

11101099
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp