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

Commit28c16f4

Browse files
Remove unnecessary PageIsEmpty() nbtree build check.
nbtree index builds cannot write out an empty page. That would meanthat there was no way to create a pivot tuple pointing to the page onelevel up, since _bt_truncate() generates one based on page's firstrighttuple.Replace the unnecessary PageIsEmpty() check with an assertion thatchecks that the page has space for at least two line pointers (thewould-be high key line pointer, plus at least one valid "data item"tuple line pointer).The PageIsEmpty() check was added by commit5d9f146 over 20 years ago.It looks like it has always been unnecessary.
1 parentf7f70d5 commit28c16f4

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ static void _bt_build_callback(Relation index, ItemPointer tid, Datum *values,
267267
bool*isnull,booltupleIsAlive,void*state);
268268
staticPage_bt_blnewpage(uint32level);
269269
staticBTPageState*_bt_pagestate(BTWriteState*wstate,uint32level);
270-
staticvoid_bt_slideleft(Pagepage);
270+
staticvoid_bt_slideleft(Pagerightmostpage);
271271
staticvoid_bt_sortaddtup(Pagepage,Sizeitemsize,
272272
IndexTupleitup,OffsetNumberitup_off,
273273
boolnewfirstdataitem);
@@ -721,31 +721,32 @@ _bt_pagestate(BTWriteState *wstate, uint32 level)
721721
}
722722

723723
/*
724-
* slide an array of ItemIds back one slot (from P_FIRSTKEY to
725-
* P_HIKEY, overwriting P_HIKEY). we need to do this when we discover
726-
* that we have built an ItemId array in what has turned out to be a
727-
* P_RIGHTMOST page.
724+
* Slide the array of ItemIds from the page back one slot (from P_FIRSTKEY to
725+
* P_HIKEY, overwriting P_HIKEY).
726+
*
727+
* _bt_blnewpage() makes the P_HIKEY line pointer appear allocated, but the
728+
* rightmost page on its level is not supposed to get a high key. Now that
729+
* it's clear that this page is a rightmost page, remove the unneeded empty
730+
* P_HIKEY line pointer space.
728731
*/
729732
staticvoid
730-
_bt_slideleft(Pagepage)
733+
_bt_slideleft(Pagerightmostpage)
731734
{
732735
OffsetNumberoff;
733736
OffsetNumbermaxoff;
734737
ItemIdprevii;
735-
ItemIdthisii;
736738

737-
if (!PageIsEmpty(page))
739+
maxoff=PageGetMaxOffsetNumber(rightmostpage);
740+
Assert(maxoff >=P_FIRSTKEY);
741+
previi=PageGetItemId(rightmostpage,P_HIKEY);
742+
for (off=P_FIRSTKEY;off <=maxoff;off=OffsetNumberNext(off))
738743
{
739-
maxoff=PageGetMaxOffsetNumber(page);
740-
previi=PageGetItemId(page,P_HIKEY);
741-
for (off=P_FIRSTKEY;off <=maxoff;off=OffsetNumberNext(off))
742-
{
743-
thisii=PageGetItemId(page,off);
744-
*previi=*thisii;
745-
previi=thisii;
746-
}
747-
((PageHeader)page)->pd_lower-=sizeof(ItemIdData);
744+
ItemIdthisii=PageGetItemId(rightmostpage,off);
745+
746+
*previi=*thisii;
747+
previi=thisii;
748748
}
749+
((PageHeader)rightmostpage)->pd_lower-=sizeof(ItemIdData);
749750
}
750751

751752
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp