@@ -54,7 +54,7 @@ static Buffer _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf,
54
54
IndexTuple newitem , IndexTuple orignewitem ,
55
55
IndexTuple nposting , uint16 postingoff );
56
56
static void _bt_insert_parent (Relation rel , Buffer buf , Buffer rbuf ,
57
- BTStack stack , bool is_root , bool is_only );
57
+ BTStack stack , bool isroot , bool isonly );
58
58
static Buffer _bt_newroot (Relation rel , Buffer lbuf , Buffer rbuf );
59
59
static inline bool _bt_pgaddtup (Page page , Size itemsize , IndexTuple itup ,
60
60
OffsetNumber itup_off , bool newfirstdataitem );
@@ -306,11 +306,11 @@ _bt_search_insert(Relation rel, BTInsertState insertstate)
306
306
if (_bt_conditionallockbuf (rel , insertstate -> buf ))
307
307
{
308
308
Page page ;
309
- BTPageOpaque lpageop ;
309
+ BTPageOpaque opaque ;
310
310
311
311
_bt_checkpage (rel , insertstate -> buf );
312
312
page = BufferGetPage (insertstate -> buf );
313
- lpageop = (BTPageOpaque ) PageGetSpecialPointer (page );
313
+ opaque = (BTPageOpaque ) PageGetSpecialPointer (page );
314
314
315
315
/*
316
316
* Check if the page is still the rightmost leaf page and has
@@ -320,9 +320,9 @@ _bt_search_insert(Relation rel, BTInsertState insertstate)
320
320
* scantid to be unset when our caller is a checkingunique
321
321
* inserter.)
322
322
*/
323
- if (P_RIGHTMOST (lpageop ) &&
324
- P_ISLEAF (lpageop ) &&
325
- !P_IGNORE (lpageop ) &&
323
+ if (P_RIGHTMOST (opaque ) &&
324
+ P_ISLEAF (opaque ) &&
325
+ !P_IGNORE (opaque ) &&
326
326
PageGetFreeSpace (page ) > insertstate -> itemsz &&
327
327
PageGetMaxOffsetNumber (page ) >= P_HIKEY &&
328
328
_bt_compare (rel , insertstate -> itup_key , page , P_HIKEY ) > 0 )
@@ -795,17 +795,17 @@ _bt_findinsertloc(Relation rel,
795
795
{
796
796
BTScanInsert itup_key = insertstate -> itup_key ;
797
797
Page page = BufferGetPage (insertstate -> buf );
798
- BTPageOpaque lpageop ;
798
+ BTPageOpaque opaque ;
799
799
OffsetNumber newitemoff ;
800
800
801
- lpageop = (BTPageOpaque ) PageGetSpecialPointer (page );
801
+ opaque = (BTPageOpaque ) PageGetSpecialPointer (page );
802
802
803
803
/* Check 1/3 of a page restriction */
804
804
if (unlikely (insertstate -> itemsz > BTMaxItemSize (page )))
805
805
_bt_check_third_page (rel , heapRel , itup_key -> heapkeyspace , page ,
806
806
insertstate -> itup );
807
807
808
- Assert (P_ISLEAF (lpageop ) && !P_INCOMPLETE_SPLIT (lpageop ));
808
+ Assert (P_ISLEAF (opaque ) && !P_INCOMPLETE_SPLIT (opaque ));
809
809
Assert (!insertstate -> bounds_valid || checkingunique );
810
810
Assert (!itup_key -> heapkeyspace || itup_key -> scantid != NULL );
811
811
Assert (itup_key -> heapkeyspace || itup_key -> scantid == NULL );
@@ -857,14 +857,14 @@ _bt_findinsertloc(Relation rel,
857
857
break ;
858
858
859
859
/* Test '<=', not '!=', since scantid is set now */
860
- if (P_RIGHTMOST (lpageop ) ||
860
+ if (P_RIGHTMOST (opaque ) ||
861
861
_bt_compare (rel , itup_key , page , P_HIKEY ) <= 0 )
862
862
break ;
863
863
864
864
_bt_stepright (rel , insertstate , stack );
865
865
/* Update local state after stepping right */
866
866
page = BufferGetPage (insertstate -> buf );
867
- lpageop = (BTPageOpaque ) PageGetSpecialPointer (page );
867
+ opaque = (BTPageOpaque ) PageGetSpecialPointer (page );
868
868
/* Assume duplicates (if checkingunique) */
869
869
uniquedup = true;
870
870
}
@@ -884,7 +884,7 @@ _bt_findinsertloc(Relation rel,
884
884
*/
885
885
if (PageGetFreeSpace (page ) < insertstate -> itemsz )
886
886
{
887
- if (P_HAS_GARBAGE (lpageop ))
887
+ if (P_HAS_GARBAGE (opaque ))
888
888
{
889
889
_bt_vacuum_one_page (rel , insertstate -> buf , heapRel );
890
890
insertstate -> bounds_valid = false;
@@ -940,7 +940,7 @@ _bt_findinsertloc(Relation rel,
940
940
* Before considering moving right, see if we can obtain enough
941
941
* space by erasing LP_DEAD items
942
942
*/
943
- if (P_HAS_GARBAGE (lpageop ))
943
+ if (P_HAS_GARBAGE (opaque ))
944
944
{
945
945
_bt_vacuum_one_page (rel , insertstate -> buf , heapRel );
946
946
insertstate -> bounds_valid = false;
@@ -964,23 +964,23 @@ _bt_findinsertloc(Relation rel,
964
964
insertstate -> stricthigh <= PageGetMaxOffsetNumber (page ))
965
965
break ;
966
966
967
- if (P_RIGHTMOST (lpageop ) ||
967
+ if (P_RIGHTMOST (opaque ) ||
968
968
_bt_compare (rel , itup_key , page , P_HIKEY ) != 0 ||
969
969
random () <= (MAX_RANDOM_VALUE / 100 ))
970
970
break ;
971
971
972
972
_bt_stepright (rel , insertstate , stack );
973
973
/* Update local state after stepping right */
974
974
page = BufferGetPage (insertstate -> buf );
975
- lpageop = (BTPageOpaque ) PageGetSpecialPointer (page );
975
+ opaque = (BTPageOpaque ) PageGetSpecialPointer (page );
976
976
}
977
977
}
978
978
979
979
/*
980
980
* We should now be on the correct page. Find the offset within the page
981
981
* for the new tuple. (Possibly reusing earlier search bounds.)
982
982
*/
983
- Assert (P_RIGHTMOST (lpageop ) ||
983
+ Assert (P_RIGHTMOST (opaque ) ||
984
984
_bt_compare (rel , itup_key , page , P_HIKEY ) <= 0 );
985
985
986
986
newitemoff = _bt_binsrch_insert (rel , insertstate );
@@ -1025,41 +1025,41 @@ static void
1025
1025
_bt_stepright (Relation rel , BTInsertState insertstate , BTStack stack )
1026
1026
{
1027
1027
Page page ;
1028
- BTPageOpaque lpageop ;
1028
+ BTPageOpaque opaque ;
1029
1029
Buffer rbuf ;
1030
1030
BlockNumber rblkno ;
1031
1031
1032
1032
page = BufferGetPage (insertstate -> buf );
1033
- lpageop = (BTPageOpaque ) PageGetSpecialPointer (page );
1033
+ opaque = (BTPageOpaque ) PageGetSpecialPointer (page );
1034
1034
1035
1035
rbuf = InvalidBuffer ;
1036
- rblkno = lpageop -> btpo_next ;
1036
+ rblkno = opaque -> btpo_next ;
1037
1037
for (;;)
1038
1038
{
1039
1039
rbuf = _bt_relandgetbuf (rel , rbuf , rblkno , BT_WRITE );
1040
1040
page = BufferGetPage (rbuf );
1041
- lpageop = (BTPageOpaque ) PageGetSpecialPointer (page );
1041
+ opaque = (BTPageOpaque ) PageGetSpecialPointer (page );
1042
1042
1043
1043
/*
1044
1044
* If this page was incompletely split, finish the split now. We do
1045
1045
* this while holding a lock on the left sibling, which is not good
1046
1046
* because finishing the split could be a fairly lengthy operation.
1047
1047
* But this should happen very seldom.
1048
1048
*/
1049
- if (P_INCOMPLETE_SPLIT (lpageop ))
1049
+ if (P_INCOMPLETE_SPLIT (opaque ))
1050
1050
{
1051
1051
_bt_finish_split (rel , rbuf , stack );
1052
1052
rbuf = InvalidBuffer ;
1053
1053
continue ;
1054
1054
}
1055
1055
1056
- if (!P_IGNORE (lpageop ))
1056
+ if (!P_IGNORE (opaque ))
1057
1057
break ;
1058
- if (P_RIGHTMOST (lpageop ))
1058
+ if (P_RIGHTMOST (opaque ))
1059
1059
elog (ERROR , "fell off the end of index \"%s\"" ,
1060
1060
RelationGetRelationName (rel ));
1061
1061
1062
- rblkno = lpageop -> btpo_next ;
1062
+ rblkno = opaque -> btpo_next ;
1063
1063
}
1064
1064
/* rbuf locked; unlock buf, update state for caller */
1065
1065
_bt_relbuf (rel , insertstate -> buf );
@@ -1110,35 +1110,43 @@ _bt_insertonpg(Relation rel,
1110
1110
bool split_only_page )
1111
1111
{
1112
1112
Page page ;
1113
- BTPageOpaque lpageop ;
1113
+ BTPageOpaque opaque ;
1114
+ bool isleaf ,
1115
+ isroot ,
1116
+ isrightmost ,
1117
+ isonly ;
1114
1118
IndexTuple oposting = NULL ;
1115
1119
IndexTuple origitup = NULL ;
1116
1120
IndexTuple nposting = NULL ;
1117
1121
1118
1122
page = BufferGetPage (buf );
1119
- lpageop = (BTPageOpaque ) PageGetSpecialPointer (page );
1123
+ opaque = (BTPageOpaque ) PageGetSpecialPointer (page );
1124
+ isleaf = P_ISLEAF (opaque );
1125
+ isroot = P_ISROOT (opaque );
1126
+ isrightmost = P_RIGHTMOST (opaque );
1127
+ isonly = P_LEFTMOST (opaque ) && P_RIGHTMOST (opaque );
1120
1128
1121
1129
/* child buffer must be given iff inserting on an internal page */
1122
- Assert (P_ISLEAF ( lpageop ) == !BufferIsValid (cbuf ));
1130
+ Assert (isleaf == !BufferIsValid (cbuf ));
1123
1131
/* tuple must have appropriate number of attributes */
1124
- Assert (!P_ISLEAF ( lpageop ) ||
1132
+ Assert (!isleaf ||
1125
1133
BTreeTupleGetNAtts (itup , rel ) ==
1126
1134
IndexRelationGetNumberOfAttributes (rel ));
1127
- Assert (P_ISLEAF ( lpageop ) ||
1135
+ Assert (isleaf ||
1128
1136
BTreeTupleGetNAtts (itup , rel ) <=
1129
1137
IndexRelationGetNumberOfKeyAttributes (rel ));
1130
1138
Assert (!BTreeTupleIsPosting (itup ));
1131
1139
Assert (MAXALIGN (IndexTupleSize (itup )) == itemsz );
1132
1140
/* Caller must always finish incomplete split for us */
1133
- Assert (!P_INCOMPLETE_SPLIT (lpageop ));
1141
+ Assert (!P_INCOMPLETE_SPLIT (opaque ));
1134
1142
1135
1143
/*
1136
1144
* Every internal page should have exactly one negative infinity item at
1137
1145
* all times. Only _bt_split() and _bt_newroot() should add items that
1138
1146
* become negative infinity items through truncation, since they're the
1139
1147
* only routines that allocate new internal pages.
1140
1148
*/
1141
- Assert (P_ISLEAF ( lpageop ) || newitemoff > P_FIRSTDATAKEY (lpageop ));
1149
+ Assert (isleaf || newitemoff > P_FIRSTDATAKEY (opaque ));
1142
1150
1143
1151
/*
1144
1152
* Do we need to split an existing posting list item?
@@ -1154,7 +1162,7 @@ _bt_insertonpg(Relation rel,
1154
1162
* its post-split version is treated as an extra step in either the
1155
1163
* insert or page split critical section.
1156
1164
*/
1157
- Assert (P_ISLEAF ( lpageop ) && !ItemIdIsDead (itemid ));
1165
+ Assert (isleaf && !ItemIdIsDead (itemid ));
1158
1166
Assert (itup_key -> heapkeyspace && itup_key -> allequalimage );
1159
1167
oposting = (IndexTuple ) PageGetItem (page , itemid );
1160
1168
@@ -1177,8 +1185,6 @@ _bt_insertonpg(Relation rel,
1177
1185
*/
1178
1186
if (PageGetFreeSpace (page ) < itemsz )
1179
1187
{
1180
- bool is_root = P_ISROOT (lpageop );
1181
- bool is_only = P_LEFTMOST (lpageop ) && P_RIGHTMOST (lpageop );
1182
1188
Buffer rbuf ;
1183
1189
1184
1190
Assert (!split_only_page );
@@ -1208,12 +1214,10 @@ _bt_insertonpg(Relation rel,
1208
1214
* page.
1209
1215
*----------
1210
1216
*/
1211
- _bt_insert_parent (rel , buf , rbuf , stack , is_root , is_only );
1217
+ _bt_insert_parent (rel , buf , rbuf , stack , isroot , isonly );
1212
1218
}
1213
1219
else
1214
1220
{
1215
- bool isleaf = P_ISLEAF (lpageop );
1216
- bool isrightmost = P_RIGHTMOST (lpageop );
1217
1221
Buffer metabuf = InvalidBuffer ;
1218
1222
Page metapg = NULL ;
1219
1223
BTMetaPageData * metad = NULL ;
@@ -1226,7 +1230,7 @@ _bt_insertonpg(Relation rel,
1226
1230
* at or above the current page. We can safely acquire a lock on the
1227
1231
* metapage here --- see comments for _bt_newroot().
1228
1232
*/
1229
- if (split_only_page )
1233
+ if (unlikely ( split_only_page ) )
1230
1234
{
1231
1235
Assert (!isleaf );
1232
1236
Assert (BufferIsValid (cbuf ));
@@ -1235,7 +1239,7 @@ _bt_insertonpg(Relation rel,
1235
1239
metapg = BufferGetPage (metabuf );
1236
1240
metad = BTPageGetMeta (metapg );
1237
1241
1238
- if (metad -> btm_fastlevel >= lpageop -> btpo .level )
1242
+ if (metad -> btm_fastlevel >= opaque -> btpo .level )
1239
1243
{
1240
1244
/* no update wanted */
1241
1245
_bt_relbuf (rel , metabuf );
@@ -1262,7 +1266,7 @@ _bt_insertonpg(Relation rel,
1262
1266
if (metad -> btm_version < BTREE_NOVAC_VERSION )
1263
1267
_bt_upgrademetapage (metapg );
1264
1268
metad -> btm_fastroot = BufferGetBlockNumber (buf );
1265
- metad -> btm_fastlevel = lpageop -> btpo .level ;
1269
+ metad -> btm_fastlevel = opaque -> btpo .level ;
1266
1270
MarkBufferDirty (metabuf );
1267
1271
}
1268
1272
@@ -1383,7 +1387,7 @@ _bt_insertonpg(Relation rel,
1383
1387
* may be used by a future inserter within _bt_search_insert().
1384
1388
*/
1385
1389
blockcache = InvalidBlockNumber ;
1386
- if (isrightmost && isleaf && !P_ISROOT ( lpageop ) )
1390
+ if (isrightmost && isleaf && !isroot )
1387
1391
blockcache = BufferGetBlockNumber (buf );
1388
1392
1389
1393
/* Release buffer for insertion target block */
@@ -2066,16 +2070,16 @@ _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf, Buffer cbuf,
2066
2070
*
2067
2071
* stack - stack showing how we got here. Will be NULL when splitting true
2068
2072
* root, or during concurrent root split, where we can be inefficient
2069
- * is_root - we split the true root
2070
- * is_only - we split a page alone on its level (might have been fast root)
2073
+ * isroot - we split the true root
2074
+ * isonly - we split a page alone on its level (might have been fast root)
2071
2075
*/
2072
2076
static void
2073
2077
_bt_insert_parent (Relation rel ,
2074
2078
Buffer buf ,
2075
2079
Buffer rbuf ,
2076
2080
BTStack stack ,
2077
- bool is_root ,
2078
- bool is_only )
2081
+ bool isroot ,
2082
+ bool isonly )
2079
2083
{
2080
2084
/*
2081
2085
* Here we have to do something Lehman and Yao don't talk about: deal with
@@ -2090,12 +2094,12 @@ _bt_insert_parent(Relation rel,
2090
2094
* from the root. This is not super-efficient, but it's rare enough not
2091
2095
* to matter.
2092
2096
*/
2093
- if (is_root )
2097
+ if (isroot )
2094
2098
{
2095
2099
Buffer rootbuf ;
2096
2100
2097
2101
Assert (stack == NULL );
2098
- Assert (is_only );
2102
+ Assert (isonly );
2099
2103
/* create a new root node and update the metapage */
2100
2104
rootbuf = _bt_newroot (rel , buf , rbuf );
2101
2105
/* release the split buffers */
@@ -2115,10 +2119,10 @@ _bt_insert_parent(Relation rel,
2115
2119
2116
2120
if (stack == NULL )
2117
2121
{
2118
- BTPageOpaque lpageop ;
2122
+ BTPageOpaque opaque ;
2119
2123
2120
2124
elog (DEBUG2 , "concurrent ROOT page split" );
2121
- lpageop = (BTPageOpaque ) PageGetSpecialPointer (page );
2125
+ opaque = (BTPageOpaque ) PageGetSpecialPointer (page );
2122
2126
2123
2127
/*
2124
2128
* We should never reach here when a leaf page split takes place
@@ -2132,12 +2136,11 @@ _bt_insert_parent(Relation rel,
2132
2136
* page will split, since it's faster to go through _bt_search()
2133
2137
* and get a stack in the usual way.
2134
2138
*/
2135
- Assert (!(P_ISLEAF (lpageop ) &&
2139
+ Assert (!(P_ISLEAF (opaque ) &&
2136
2140
BlockNumberIsValid (RelationGetTargetBlock (rel ))));
2137
2141
2138
2142
/* Find the leftmost page at the next level up */
2139
- pbuf = _bt_get_endpoint (rel , lpageop -> btpo .level + 1 , false,
2140
- NULL );
2143
+ pbuf = _bt_get_endpoint (rel , opaque -> btpo .level + 1 , false, NULL );
2141
2144
/* Set up a phony stack entry pointing there */
2142
2145
stack = & fakestack ;
2143
2146
stack -> bts_blkno = BufferGetBlockNumber (pbuf );
@@ -2189,7 +2192,7 @@ _bt_insert_parent(Relation rel,
2189
2192
/* Recursively insert into the parent */
2190
2193
_bt_insertonpg (rel , NULL , pbuf , buf , stack -> bts_parent ,
2191
2194
new_item , MAXALIGN (IndexTupleSize (new_item )),
2192
- stack -> bts_offset + 1 , 0 , is_only );
2195
+ stack -> bts_offset + 1 , 0 , isonly );
2193
2196
2194
2197
/* be tidy */
2195
2198
pfree (new_item );
@@ -2214,8 +2217,8 @@ _bt_finish_split(Relation rel, Buffer lbuf, BTStack stack)
2214
2217
Buffer rbuf ;
2215
2218
Page rpage ;
2216
2219
BTPageOpaque rpageop ;
2217
- bool was_root ;
2218
- bool was_only ;
2220
+ bool wasroot ;
2221
+ bool wasonly ;
2219
2222
2220
2223
Assert (P_INCOMPLETE_SPLIT (lpageop ));
2221
2224
@@ -2236,20 +2239,20 @@ _bt_finish_split(Relation rel, Buffer lbuf, BTStack stack)
2236
2239
metapg = BufferGetPage (metabuf );
2237
2240
metad = BTPageGetMeta (metapg );
2238
2241
2239
- was_root = (metad -> btm_root == BufferGetBlockNumber (lbuf ));
2242
+ wasroot = (metad -> btm_root == BufferGetBlockNumber (lbuf ));
2240
2243
2241
2244
_bt_relbuf (rel , metabuf );
2242
2245
}
2243
2246
else
2244
- was_root = false;
2247
+ wasroot = false;
2245
2248
2246
2249
/* Was this the only page on the level before split? */
2247
- was_only = (P_LEFTMOST (lpageop ) && P_RIGHTMOST (rpageop ));
2250
+ wasonly = (P_LEFTMOST (lpageop ) && P_RIGHTMOST (rpageop ));
2248
2251
2249
2252
elog (DEBUG1 , "finishing incomplete split of %u/%u" ,
2250
2253
BufferGetBlockNumber (lbuf ), BufferGetBlockNumber (rbuf ));
2251
2254
2252
- _bt_insert_parent (rel , lbuf , rbuf , stack , was_root , was_only );
2255
+ _bt_insert_parent (rel , lbuf , rbuf , stack , wasroot , wasonly );
2253
2256
}
2254
2257
2255
2258
/*
0 commit comments