@@ -59,7 +59,7 @@ static Buffer _bt_split(Relation rel, Relation heaprel, BTScanInsert itup_key,
59
59
IndexTuple nposting , uint16 postingoff );
60
60
static void _bt_insert_parent (Relation rel , Relation heaprel , Buffer buf ,
61
61
Buffer rbuf , BTStack stack , bool isroot , bool isonly );
62
- static Buffer _bt_newroot (Relation rel , Relation heaprel , Buffer lbuf , Buffer rbuf );
62
+ static Buffer _bt_newlevel (Relation rel , Relation heaprel , Buffer lbuf , Buffer rbuf );
63
63
static inline bool _bt_pgaddtup (Page page , Size itemsize , IndexTuple itup ,
64
64
OffsetNumber itup_off , bool newfirstdataitem );
65
65
static void _bt_delete_or_dedup_one_page (Relation rel , Relation heapRel ,
@@ -110,7 +110,7 @@ _bt_doinsert(Relation rel, IndexTuple itup,
110
110
bool checkingunique = (checkUnique != UNIQUE_CHECK_NO );
111
111
112
112
/* we need an insertion scan key to do our search, so build one */
113
- itup_key = _bt_mkscankey (rel , heapRel , itup );
113
+ itup_key = _bt_mkscankey (rel , itup );
114
114
115
115
if (checkingunique )
116
116
{
@@ -1024,13 +1024,15 @@ _bt_findinsertloc(Relation rel,
1024
1024
* indexes.
1025
1025
*/
1026
1026
static void
1027
- _bt_stepright (Relation rel , Relation heaprel , BTInsertState insertstate , BTStack stack )
1027
+ _bt_stepright (Relation rel , Relation heaprel , BTInsertState insertstate ,
1028
+ BTStack stack )
1028
1029
{
1029
1030
Page page ;
1030
1031
BTPageOpaque opaque ;
1031
1032
Buffer rbuf ;
1032
1033
BlockNumber rblkno ;
1033
1034
1035
+ Assert (heaprel != NULL );
1034
1036
page = BufferGetPage (insertstate -> buf );
1035
1037
opaque = BTPageGetOpaque (page );
1036
1038
@@ -1145,7 +1147,7 @@ _bt_insertonpg(Relation rel,
1145
1147
1146
1148
/*
1147
1149
* Every internal page should have exactly one negative infinity item at
1148
- * all times. Only _bt_split() and _bt_newroot () should add items that
1150
+ * all times. Only _bt_split() and _bt_newlevel () should add items that
1149
1151
* become negative infinity items through truncation, since they're the
1150
1152
* only routines that allocate new internal pages.
1151
1153
*/
@@ -1250,14 +1252,14 @@ _bt_insertonpg(Relation rel,
1250
1252
* only one on its tree level, but was not the root, it may have been
1251
1253
* the "fast root". We need to ensure that the fast root link points
1252
1254
* at or above the current page. We can safely acquire a lock on the
1253
- * metapage here --- see comments for _bt_newroot ().
1255
+ * metapage here --- see comments for _bt_newlevel ().
1254
1256
*/
1255
1257
if (unlikely (split_only_page ))
1256
1258
{
1257
1259
Assert (!isleaf );
1258
1260
Assert (BufferIsValid (cbuf ));
1259
1261
1260
- metabuf = _bt_getbuf (rel , heaprel , BTREE_METAPAGE , BT_WRITE );
1262
+ metabuf = _bt_getbuf (rel , BTREE_METAPAGE , BT_WRITE );
1261
1263
metapg = BufferGetPage (metabuf );
1262
1264
metad = BTPageGetMeta (metapg );
1263
1265
@@ -1421,7 +1423,7 @@ _bt_insertonpg(Relation rel,
1421
1423
* call _bt_getrootheight while holding a buffer lock.
1422
1424
*/
1423
1425
if (BlockNumberIsValid (blockcache ) &&
1424
- _bt_getrootheight (rel , heaprel ) >= BTREE_FASTPATH_MIN_LEVEL )
1426
+ _bt_getrootheight (rel ) >= BTREE_FASTPATH_MIN_LEVEL )
1425
1427
RelationSetTargetBlock (rel , blockcache );
1426
1428
}
1427
1429
@@ -1715,7 +1717,7 @@ _bt_split(Relation rel, Relation heaprel, BTScanInsert itup_key, Buffer buf,
1715
1717
* way because it avoids an unnecessary PANIC when either origpage or its
1716
1718
* existing sibling page are corrupt.
1717
1719
*/
1718
- rbuf = _bt_getbuf (rel , heaprel , P_NEW , BT_WRITE );
1720
+ rbuf = _bt_allocbuf (rel , heaprel );
1719
1721
rightpage = BufferGetPage (rbuf );
1720
1722
rightpagenumber = BufferGetBlockNumber (rbuf );
1721
1723
/* rightpage was initialized by _bt_getbuf */
@@ -1888,7 +1890,7 @@ _bt_split(Relation rel, Relation heaprel, BTScanInsert itup_key, Buffer buf,
1888
1890
*/
1889
1891
if (!isrightmost )
1890
1892
{
1891
- sbuf = _bt_getbuf (rel , heaprel , oopaque -> btpo_next , BT_WRITE );
1893
+ sbuf = _bt_getbuf (rel , oopaque -> btpo_next , BT_WRITE );
1892
1894
spage = BufferGetPage (sbuf );
1893
1895
sopaque = BTPageGetOpaque (spage );
1894
1896
if (sopaque -> btpo_prev != origpagenumber )
@@ -2102,6 +2104,8 @@ _bt_insert_parent(Relation rel,
2102
2104
bool isroot ,
2103
2105
bool isonly )
2104
2106
{
2107
+ Assert (heaprel != NULL );
2108
+
2105
2109
/*
2106
2110
* Here we have to do something Lehman and Yao don't talk about: deal with
2107
2111
* a root split and construction of a new root. If our stack is empty
@@ -2121,8 +2125,8 @@ _bt_insert_parent(Relation rel,
2121
2125
2122
2126
Assert (stack == NULL );
2123
2127
Assert (isonly );
2124
- /* create a new root node and update the metapage */
2125
- rootbuf = _bt_newroot (rel , heaprel , buf , rbuf );
2128
+ /* create a new root node one level up and update the metapage */
2129
+ rootbuf = _bt_newlevel (rel , heaprel , buf , rbuf );
2126
2130
/* release the split buffers */
2127
2131
_bt_relbuf (rel , rootbuf );
2128
2132
_bt_relbuf (rel , rbuf );
@@ -2161,8 +2165,7 @@ _bt_insert_parent(Relation rel,
2161
2165
BlockNumberIsValid (RelationGetTargetBlock (rel ))));
2162
2166
2163
2167
/* Find the leftmost page at the next level up */
2164
- pbuf = _bt_get_endpoint (rel , heaprel , opaque -> btpo_level + 1 , false,
2165
- NULL );
2168
+ pbuf = _bt_get_endpoint (rel , opaque -> btpo_level + 1 , false, NULL );
2166
2169
/* Set up a phony stack entry pointing there */
2167
2170
stack = & fakestack ;
2168
2171
stack -> bts_blkno = BufferGetBlockNumber (pbuf );
@@ -2230,6 +2233,9 @@ _bt_insert_parent(Relation rel,
2230
2233
*
2231
2234
* On entry, 'lbuf' must be locked in write-mode. On exit, it is unlocked
2232
2235
* and unpinned.
2236
+ *
2237
+ * Caller must provide a valid heaprel, since finishing a page split requires
2238
+ * allocating a new page if and when the parent page splits in turn.
2233
2239
*/
2234
2240
void
2235
2241
_bt_finish_split (Relation rel , Relation heaprel , Buffer lbuf , BTStack stack )
@@ -2243,9 +2249,10 @@ _bt_finish_split(Relation rel, Relation heaprel, Buffer lbuf, BTStack stack)
2243
2249
bool wasonly ;
2244
2250
2245
2251
Assert (P_INCOMPLETE_SPLIT (lpageop ));
2252
+ Assert (heaprel != NULL );
2246
2253
2247
2254
/* Lock right sibling, the one missing the downlink */
2248
- rbuf = _bt_getbuf (rel , heaprel , lpageop -> btpo_next , BT_WRITE );
2255
+ rbuf = _bt_getbuf (rel , lpageop -> btpo_next , BT_WRITE );
2249
2256
rpage = BufferGetPage (rbuf );
2250
2257
rpageop = BTPageGetOpaque (rpage );
2251
2258
@@ -2257,7 +2264,7 @@ _bt_finish_split(Relation rel, Relation heaprel, Buffer lbuf, BTStack stack)
2257
2264
BTMetaPageData * metad ;
2258
2265
2259
2266
/* acquire lock on the metapage */
2260
- metabuf = _bt_getbuf (rel , heaprel , BTREE_METAPAGE , BT_WRITE );
2267
+ metabuf = _bt_getbuf (rel , BTREE_METAPAGE , BT_WRITE );
2261
2268
metapg = BufferGetPage (metabuf );
2262
2269
metad = BTPageGetMeta (metapg );
2263
2270
@@ -2323,10 +2330,11 @@ _bt_getstackbuf(Relation rel, Relation heaprel, BTStack stack, BlockNumber child
2323
2330
Page page ;
2324
2331
BTPageOpaque opaque ;
2325
2332
2326
- buf = _bt_getbuf (rel , heaprel , blkno , BT_WRITE );
2333
+ buf = _bt_getbuf (rel , blkno , BT_WRITE );
2327
2334
page = BufferGetPage (buf );
2328
2335
opaque = BTPageGetOpaque (page );
2329
2336
2337
+ Assert (heaprel != NULL );
2330
2338
if (P_INCOMPLETE_SPLIT (opaque ))
2331
2339
{
2332
2340
_bt_finish_split (rel , heaprel , buf , stack -> bts_parent );
@@ -2415,7 +2423,7 @@ _bt_getstackbuf(Relation rel, Relation heaprel, BTStack stack, BlockNumber child
2415
2423
}
2416
2424
2417
2425
/*
2418
- * _bt_newroot () -- Create a new root page for the index .
2426
+ * _bt_newlevel () -- Create a new level above root page .
2419
2427
*
2420
2428
* We've just split the old root page and need to create a new one.
2421
2429
* In order to do this, we add a new root page to the file, then lock
@@ -2433,7 +2441,7 @@ _bt_getstackbuf(Relation rel, Relation heaprel, BTStack stack, BlockNumber child
2433
2441
* lbuf, rbuf & rootbuf.
2434
2442
*/
2435
2443
static Buffer
2436
- _bt_newroot (Relation rel , Relation heaprel , Buffer lbuf , Buffer rbuf )
2444
+ _bt_newlevel (Relation rel , Relation heaprel , Buffer lbuf , Buffer rbuf )
2437
2445
{
2438
2446
Buffer rootbuf ;
2439
2447
Page lpage ,
@@ -2459,12 +2467,12 @@ _bt_newroot(Relation rel, Relation heaprel, Buffer lbuf, Buffer rbuf)
2459
2467
lopaque = BTPageGetOpaque (lpage );
2460
2468
2461
2469
/* get a new root page */
2462
- rootbuf = _bt_getbuf (rel , heaprel , P_NEW , BT_WRITE );
2470
+ rootbuf = _bt_allocbuf (rel , heaprel );
2463
2471
rootpage = BufferGetPage (rootbuf );
2464
2472
rootblknum = BufferGetBlockNumber (rootbuf );
2465
2473
2466
2474
/* acquire lock on the metapage */
2467
- metabuf = _bt_getbuf (rel , heaprel , BTREE_METAPAGE , BT_WRITE );
2475
+ metabuf = _bt_getbuf (rel , BTREE_METAPAGE , BT_WRITE );
2468
2476
metapg = BufferGetPage (metabuf );
2469
2477
metad = BTPageGetMeta (metapg );
2470
2478
0 commit comments