@@ -59,7 +59,7 @@ static Buffer _bt_split(Relation rel, Relation heaprel, BTScanInsert itup_key,
5959 IndexTuple nposting , uint16 postingoff );
6060static void _bt_insert_parent (Relation rel , Relation heaprel , Buffer buf ,
6161 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 );
6363static inline bool _bt_pgaddtup (Page page , Size itemsize , IndexTuple itup ,
6464 OffsetNumber itup_off , bool newfirstdataitem );
6565static void _bt_delete_or_dedup_one_page (Relation rel , Relation heapRel ,
@@ -110,7 +110,7 @@ _bt_doinsert(Relation rel, IndexTuple itup,
110110 bool checkingunique = (checkUnique != UNIQUE_CHECK_NO );
111111
112112 /* 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 );
114114
115115 if (checkingunique )
116116 {
@@ -1024,13 +1024,15 @@ _bt_findinsertloc(Relation rel,
10241024 * indexes.
10251025 */
10261026static void
1027- _bt_stepright (Relation rel , Relation heaprel , BTInsertState insertstate , BTStack stack )
1027+ _bt_stepright (Relation rel , Relation heaprel , BTInsertState insertstate ,
1028+ BTStack stack )
10281029{
10291030 Page page ;
10301031 BTPageOpaque opaque ;
10311032 Buffer rbuf ;
10321033 BlockNumber rblkno ;
10331034
1035+ Assert (heaprel != NULL );
10341036 page = BufferGetPage (insertstate -> buf );
10351037 opaque = BTPageGetOpaque (page );
10361038
@@ -1145,7 +1147,7 @@ _bt_insertonpg(Relation rel,
11451147
11461148 /*
11471149 * 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
11491151 * become negative infinity items through truncation, since they're the
11501152 * only routines that allocate new internal pages.
11511153 */
@@ -1250,14 +1252,14 @@ _bt_insertonpg(Relation rel,
12501252 * only one on its tree level, but was not the root, it may have been
12511253 * the "fast root". We need to ensure that the fast root link points
12521254 * 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 ().
12541256 */
12551257 if (unlikely (split_only_page ))
12561258 {
12571259 Assert (!isleaf );
12581260 Assert (BufferIsValid (cbuf ));
12591261
1260- metabuf = _bt_getbuf (rel , heaprel , BTREE_METAPAGE , BT_WRITE );
1262+ metabuf = _bt_getbuf (rel , BTREE_METAPAGE , BT_WRITE );
12611263 metapg = BufferGetPage (metabuf );
12621264 metad = BTPageGetMeta (metapg );
12631265
@@ -1421,7 +1423,7 @@ _bt_insertonpg(Relation rel,
14211423 * call _bt_getrootheight while holding a buffer lock.
14221424 */
14231425 if (BlockNumberIsValid (blockcache ) &&
1424- _bt_getrootheight (rel , heaprel ) >= BTREE_FASTPATH_MIN_LEVEL )
1426+ _bt_getrootheight (rel ) >= BTREE_FASTPATH_MIN_LEVEL )
14251427 RelationSetTargetBlock (rel , blockcache );
14261428 }
14271429
@@ -1715,7 +1717,7 @@ _bt_split(Relation rel, Relation heaprel, BTScanInsert itup_key, Buffer buf,
17151717 * way because it avoids an unnecessary PANIC when either origpage or its
17161718 * existing sibling page are corrupt.
17171719 */
1718- rbuf = _bt_getbuf (rel , heaprel , P_NEW , BT_WRITE );
1720+ rbuf = _bt_allocbuf (rel , heaprel );
17191721 rightpage = BufferGetPage (rbuf );
17201722 rightpagenumber = BufferGetBlockNumber (rbuf );
17211723 /* rightpage was initialized by _bt_getbuf */
@@ -1888,7 +1890,7 @@ _bt_split(Relation rel, Relation heaprel, BTScanInsert itup_key, Buffer buf,
18881890 */
18891891 if (!isrightmost )
18901892 {
1891- sbuf = _bt_getbuf (rel , heaprel , oopaque -> btpo_next , BT_WRITE );
1893+ sbuf = _bt_getbuf (rel , oopaque -> btpo_next , BT_WRITE );
18921894 spage = BufferGetPage (sbuf );
18931895 sopaque = BTPageGetOpaque (spage );
18941896 if (sopaque -> btpo_prev != origpagenumber )
@@ -2102,6 +2104,8 @@ _bt_insert_parent(Relation rel,
21022104 bool isroot ,
21032105 bool isonly )
21042106{
2107+ Assert (heaprel != NULL );
2108+
21052109 /*
21062110 * Here we have to do something Lehman and Yao don't talk about: deal with
21072111 * a root split and construction of a new root. If our stack is empty
@@ -2121,8 +2125,8 @@ _bt_insert_parent(Relation rel,
21212125
21222126 Assert (stack == NULL );
21232127 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 );
21262130 /* release the split buffers */
21272131 _bt_relbuf (rel , rootbuf );
21282132 _bt_relbuf (rel , rbuf );
@@ -2161,8 +2165,7 @@ _bt_insert_parent(Relation rel,
21612165 BlockNumberIsValid (RelationGetTargetBlock (rel ))));
21622166
21632167 /* 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 );
21662169 /* Set up a phony stack entry pointing there */
21672170 stack = & fakestack ;
21682171 stack -> bts_blkno = BufferGetBlockNumber (pbuf );
@@ -2230,6 +2233,9 @@ _bt_insert_parent(Relation rel,
22302233 *
22312234 * On entry, 'lbuf' must be locked in write-mode. On exit, it is unlocked
22322235 * 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.
22332239 */
22342240void
22352241_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)
22432249 bool wasonly ;
22442250
22452251 Assert (P_INCOMPLETE_SPLIT (lpageop ));
2252+ Assert (heaprel != NULL );
22462253
22472254 /* 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 );
22492256 rpage = BufferGetPage (rbuf );
22502257 rpageop = BTPageGetOpaque (rpage );
22512258
@@ -2257,7 +2264,7 @@ _bt_finish_split(Relation rel, Relation heaprel, Buffer lbuf, BTStack stack)
22572264 BTMetaPageData * metad ;
22582265
22592266 /* acquire lock on the metapage */
2260- metabuf = _bt_getbuf (rel , heaprel , BTREE_METAPAGE , BT_WRITE );
2267+ metabuf = _bt_getbuf (rel , BTREE_METAPAGE , BT_WRITE );
22612268 metapg = BufferGetPage (metabuf );
22622269 metad = BTPageGetMeta (metapg );
22632270
@@ -2323,10 +2330,11 @@ _bt_getstackbuf(Relation rel, Relation heaprel, BTStack stack, BlockNumber child
23232330 Page page ;
23242331 BTPageOpaque opaque ;
23252332
2326- buf = _bt_getbuf (rel , heaprel , blkno , BT_WRITE );
2333+ buf = _bt_getbuf (rel , blkno , BT_WRITE );
23272334 page = BufferGetPage (buf );
23282335 opaque = BTPageGetOpaque (page );
23292336
2337+ Assert (heaprel != NULL );
23302338 if (P_INCOMPLETE_SPLIT (opaque ))
23312339 {
23322340 _bt_finish_split (rel , heaprel , buf , stack -> bts_parent );
@@ -2415,7 +2423,7 @@ _bt_getstackbuf(Relation rel, Relation heaprel, BTStack stack, BlockNumber child
24152423}
24162424
24172425/*
2418- * _bt_newroot () -- Create a new root page for the index .
2426+ * _bt_newlevel () -- Create a new level above root page .
24192427 *
24202428 * We've just split the old root page and need to create a new one.
24212429 * 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
24332441 * lbuf, rbuf & rootbuf.
24342442 */
24352443static Buffer
2436- _bt_newroot (Relation rel , Relation heaprel , Buffer lbuf , Buffer rbuf )
2444+ _bt_newlevel (Relation rel , Relation heaprel , Buffer lbuf , Buffer rbuf )
24372445{
24382446 Buffer rootbuf ;
24392447 Page lpage ,
@@ -2459,12 +2467,12 @@ _bt_newroot(Relation rel, Relation heaprel, Buffer lbuf, Buffer rbuf)
24592467 lopaque = BTPageGetOpaque (lpage );
24602468
24612469 /* get a new root page */
2462- rootbuf = _bt_getbuf (rel , heaprel , P_NEW , BT_WRITE );
2470+ rootbuf = _bt_allocbuf (rel , heaprel );
24632471 rootpage = BufferGetPage (rootbuf );
24642472 rootblknum = BufferGetBlockNumber (rootbuf );
24652473
24662474 /* acquire lock on the metapage */
2467- metabuf = _bt_getbuf (rel , heaprel , BTREE_METAPAGE , BT_WRITE );
2475+ metabuf = _bt_getbuf (rel , BTREE_METAPAGE , BT_WRITE );
24682476 metapg = BufferGetPage (metabuf );
24692477 metad = BTPageGetMeta (metapg );
24702478
0 commit comments