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

Commitaf0ba49

Browse files
Use PageIndexTupleOverwrite() within nbtree.
Use the PageIndexTupleOverwrite() bufpage.c routine within nbtreeinstead of deleting a tuple and re-inserting its replacement. Thismakes the intent of affected code slightly clearer. It also makesCREATE INDEX slightly faster, since there is no longer a need to shiftevery leaf page's line pointer array back and forth during index builds.Author: Peter Geoghegan, Anastasia LubennikovaReviewed-By: Anastasia LubennikovaDiscussion:https://postgr.es/m/CAH2-Wz=Zk=B9+Vwm376WuO7YTjFc2SSskifQm4Nme3RRRPtOSQ@mail.gmail.com
1 parent815ef2f commitaf0ba49

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,18 +1653,17 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
16531653
opaque= (BTPageOpaque)PageGetSpecialPointer(page);
16541654
opaque->btpo_flags |=BTP_HALF_DEAD;
16551655

1656-
PageIndexTupleDelete(page,P_HIKEY);
1657-
Assert(PageGetMaxOffsetNumber(page)==0);
1656+
Assert(PageGetMaxOffsetNumber(page)==P_HIKEY);
16581657
MemSet(&trunctuple,0,sizeof(IndexTupleData));
16591658
trunctuple.t_info=sizeof(IndexTupleData);
16601659
if (target!=leafblkno)
16611660
BTreeTupleSetTopParent(&trunctuple,target);
16621661
else
16631662
BTreeTupleSetTopParent(&trunctuple,InvalidBlockNumber);
16641663

1665-
if (PageAddItem(page, (Item)&trunctuple,sizeof(IndexTupleData),P_HIKEY,
1666-
false, false)==InvalidOffsetNumber)
1667-
elog(ERROR,"could notadd dummyhigh keyto half-dead page");
1664+
if (!PageIndexTupleOverwrite(page,P_HIKEY,(Item)&trunctuple,
1665+
IndexTupleSize(&trunctuple)))
1666+
elog(ERROR,"could notoverwritehigh keyin half-dead page");
16681667

16691668
/* Must mark buffers dirty before XLogInsert */
16701669
MarkBufferDirty(topparent);

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,6 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
943943
{
944944
IndexTuplelastleft;
945945
IndexTupletruncated;
946-
Sizetruncsz;
947946

948947
/*
949948
* Truncate away any unneeded attributes from high key on leaf
@@ -961,26 +960,18 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
961960
* choosing a split point here for a benefit that is bound to be
962961
* much smaller.
963962
*
964-
* Since the truncated tuple is often smaller than the original
965-
* tuple, it cannot just be copied in place (besides, we want to
966-
* actually save space on the leaf page). We delete the original
967-
* high key, and add our own truncated high key at the same
968-
* offset.
969-
*
970-
* Note that the page layout won't be changed very much. oitup is
971-
* already located at the physical beginning of tuple space, so we
972-
* only shift the line pointer array back and forth, and overwrite
973-
* the tuple space previously occupied by oitup. This is fairly
974-
* cheap.
963+
* Overwrite the old item with new truncated high key directly.
964+
* oitup is already located at the physical beginning of tuple
965+
* space, so this should directly reuse the existing tuple space.
975966
*/
976967
ii=PageGetItemId(opage,OffsetNumberPrev(last_off));
977968
lastleft= (IndexTuple)PageGetItem(opage,ii);
978969

979970
truncated=_bt_truncate(wstate->index,lastleft,oitup,
980971
wstate->inskey);
981-
truncsz=IndexTupleSize(truncated);
982-
PageIndexTupleDelete(opage,P_HIKEY);
983-
_bt_sortaddtup(opage,truncsz,truncated,P_HIKEY);
972+
if (!PageIndexTupleOverwrite(opage,P_HIKEY, (Item)truncated,
973+
IndexTupleSize(truncated)))
974+
elog(ERROR,"failed to add high key to the index page");
984975
pfree(truncated);
985976

986977
/* oitup should continue to point to the page's high key */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp