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

Commit013c1f6

Browse files
nbtree: Pass down MAXALIGN()'d itemsz for new item.
Refactor nbtinsert.c so that the final itemsz of each new non-pivottuple (the MAXALIGN()'d size) is determined once. Most of the functionsused by leaf page inserts used the insertstate.itemsz value already.This commit makes everything use insertstate.itemsz as standardpractice. The goal is to decouple tuple size from "effective" tuplesize. Making this distinction isn't truly necessary right now, but thatmight change in the future.Also explain why we consistently apply MAXALIGN() to get an effectiveindex tuple size. This was rather unclear, in part because it isn'tactually strictly necessary right now.
1 parentfc34b0d commit013c1f6

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static void _bt_insertonpg(Relation rel, BTScanInsert itup_key,
4444
Buffercbuf,
4545
BTStackstack,
4646
IndexTupleitup,
47+
Sizeitemsz,
4748
OffsetNumbernewitemoff,
4849
intpostingoff,
4950
boolsplit_only_page);
@@ -118,10 +119,18 @@ _bt_doinsert(Relation rel, IndexTuple itup,
118119

119120
/*
120121
* Fill in the BTInsertState working area, to track the current page and
121-
* position within the page to insert on
122+
* position within the page to insert on.
123+
*
124+
* Note that itemsz is passed down to lower level code that deals with
125+
* inserting the item. It must be MAXALIGN()'d. This ensures that space
126+
* accounting code consistently considers the alignment overhead that we
127+
* expect PageAddItem() will add later. (Actually, index_form_tuple() is
128+
* already conservative about alignment, but we don't rely on that from
129+
* this distance. Besides, preserving the "true" tuple size in index
130+
* tuple headers for the benefit of nbtsplitloc.c might happen someday.
131+
* Note that heapam does not MAXALIGN() each heap tuple's lp_len field.)
122132
*/
123133
insertstate.itup=itup;
124-
/* PageAddItem will MAXALIGN(), but be consistent */
125134
insertstate.itemsz=MAXALIGN(IndexTupleSize(itup));
126135
insertstate.itup_key=itup_key;
127136
insertstate.bounds_valid= false;
@@ -299,7 +308,8 @@ _bt_doinsert(Relation rel, IndexTuple itup,
299308
newitemoff=_bt_findinsertloc(rel,&insertstate,checkingunique,
300309
stack,heapRel);
301310
_bt_insertonpg(rel,itup_key,insertstate.buf,InvalidBuffer,stack,
302-
itup,newitemoff,insertstate.postingoff, false);
311+
itup,insertstate.itemsz,newitemoff,
312+
insertstate.postingoff, false);
303313
}
304314
else
305315
{
@@ -1058,13 +1068,13 @@ _bt_insertonpg(Relation rel,
10581068
Buffercbuf,
10591069
BTStackstack,
10601070
IndexTupleitup,
1071+
Sizeitemsz,
10611072
OffsetNumbernewitemoff,
10621073
intpostingoff,
10631074
boolsplit_only_page)
10641075
{
10651076
Pagepage;
10661077
BTPageOpaquelpageop;
1067-
Sizeitemsz;
10681078
IndexTupleoposting=NULL;
10691079
IndexTupleorigitup=NULL;
10701080
IndexTuplenposting=NULL;
@@ -1082,6 +1092,7 @@ _bt_insertonpg(Relation rel,
10821092
BTreeTupleGetNAtts(itup,rel) <=
10831093
IndexRelationGetNumberOfKeyAttributes(rel));
10841094
Assert(!BTreeTupleIsPosting(itup));
1095+
Assert(MAXALIGN(IndexTupleSize(itup))==itemsz);
10851096

10861097
/*
10871098
* Every internal page should have exactly one negative infinity item at
@@ -1096,10 +1107,6 @@ _bt_insertonpg(Relation rel,
10961107
elog(ERROR,"cannot insert to incompletely split page %u",
10971108
BufferGetBlockNumber(buf));
10981109

1099-
itemsz=IndexTupleSize(itup);
1100-
itemsz=MAXALIGN(itemsz);/* be safe, PageAddItem will do this but we
1101-
* need to be consistent */
1102-
11031110
/*
11041111
* Do we need to split an existing posting list item?
11051112
*/
@@ -2103,8 +2110,8 @@ _bt_insert_parent(Relation rel,
21032110

21042111
/* Recursively insert into the parent */
21052112
_bt_insertonpg(rel,NULL,pbuf,buf,stack->bts_parent,
2106-
new_item,stack->bts_offset+1,0,
2107-
is_only);
2113+
new_item,MAXALIGN(IndexTupleSize(new_item)),
2114+
stack->bts_offset+1,0,is_only);
21082115

21092116
/* be tidy */
21102117
pfree(new_item);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp