nbtree: Rename _bt_search() variables.

Make some of the variable names in _bt_search() consistent with
corresponding variables within _bt_getstackbuf().  This naming scheme is
clearer because the variable names always express a relationship between
the currently locked buffer/page and some other page.
This commit is contained in:
Peter Geoghegan 2020-07-02 14:54:55 -07:00
parent 641dd167a3
commit e25d462a38
1 changed files with 21 additions and 24 deletions

View File

@ -82,9 +82,10 @@ _bt_drop_lock_and_maybe_pin(IndexScanDesc scan, BTScanPos sp)
* The passed scankey is an insertion-type scankey (see nbtree/README), * The passed scankey is an insertion-type scankey (see nbtree/README),
* but it can omit the rightmost column(s) of the index. * but it can omit the rightmost column(s) of the index.
* *
* Return value is a stack of parent-page pointers. *bufP is set to the * Return value is a stack of parent-page pointers (i.e. there is no entry for
* address of the leaf-page buffer, which is locked and pinned. No locks * the leaf level/page). *bufP is set to the address of the leaf-page buffer,
* are held on the parent pages, however! * which is locked and pinned. No locks are held on the parent pages,
* however!
* *
* If the snapshot parameter is not NULL, "old snapshot" checking will take * If the snapshot parameter is not NULL, "old snapshot" checking will take
* place during the descent through the tree. This is not needed when * place during the descent through the tree. This is not needed when
@ -118,21 +119,20 @@ _bt_search(Relation rel, BTScanInsert key, Buffer *bufP, int access,
OffsetNumber offnum; OffsetNumber offnum;
ItemId itemid; ItemId itemid;
IndexTuple itup; IndexTuple itup;
BlockNumber blkno; BlockNumber child;
BlockNumber par_blkno;
BTStack new_stack; BTStack new_stack;
/* /*
* Race -- the page we just grabbed may have split since we read its * Race -- the page we just grabbed may have split since we read its
* pointer in the parent (or metapage). If it has, we may need to * downlink in its parent page (or the metapage). If it has, we may
* move right to its new sibling. Do that. * need to move right to its new sibling. Do that.
* *
* In write-mode, allow _bt_moveright to finish any incomplete splits * In write-mode, allow _bt_moveright to finish any incomplete splits
* along the way. Strictly speaking, we'd only need to finish an * along the way. Strictly speaking, we'd only need to finish an
* incomplete split on the leaf page we're about to insert to, not on * incomplete split on the leaf page we're about to insert to, not on
* any of the upper levels (they are taken care of in _bt_getstackbuf, * any of the upper levels (internal pages with incomplete splits are
* if the leaf page is split and we insert to the parent page). But * also taken care of in _bt_getstackbuf). But this is a good
* this is a good opportunity to finish splits of internal pages too. * opportunity to finish splits of internal pages too.
*/ */
*bufP = _bt_moveright(rel, key, *bufP, (access == BT_WRITE), stack_in, *bufP = _bt_moveright(rel, key, *bufP, (access == BT_WRITE), stack_in,
page_access, snapshot); page_access, snapshot);
@ -144,25 +144,23 @@ _bt_search(Relation rel, BTScanInsert key, Buffer *bufP, int access,
break; break;
/* /*
* Find the appropriate item on the internal page, and get the child * Find the appropriate pivot tuple on this page. Its downlink points
* page that it points to. * to the child page that we're about to descend to.
*/ */
offnum = _bt_binsrch(rel, key, *bufP); offnum = _bt_binsrch(rel, key, *bufP);
itemid = PageGetItemId(page, offnum); itemid = PageGetItemId(page, offnum);
itup = (IndexTuple) PageGetItem(page, itemid); itup = (IndexTuple) PageGetItem(page, itemid);
Assert(BTreeTupleIsPivot(itup) || !key->heapkeyspace); Assert(BTreeTupleIsPivot(itup) || !key->heapkeyspace);
blkno = BTreeTupleGetDownLink(itup); child = BTreeTupleGetDownLink(itup);
par_blkno = BufferGetBlockNumber(*bufP);
/* /*
* We need to save the location of the pivot tuple we chose in the * We need to save the location of the pivot tuple we chose in a new
* parent page on a stack. If we need to split a page, we'll use the * stack entry for this page/level. If caller ends up splitting a
* stack to work back up to its parent page. If caller ends up * page one level down, it usually ends up inserting a new pivot
* splitting a page one level down, it usually ends up inserting a new * tuple/downlink immediately after the location recorded here.
* pivot tuple/downlink immediately after the location recorded here.
*/ */
new_stack = (BTStack) palloc(sizeof(BTStackData)); new_stack = (BTStack) palloc(sizeof(BTStackData));
new_stack->bts_blkno = par_blkno; new_stack->bts_blkno = BufferGetBlockNumber(*bufP);
new_stack->bts_offset = offnum; new_stack->bts_offset = offnum;
new_stack->bts_parent = stack_in; new_stack->bts_parent = stack_in;
@ -174,8 +172,8 @@ _bt_search(Relation rel, BTScanInsert key, Buffer *bufP, int access,
if (opaque->btpo.level == 1 && access == BT_WRITE) if (opaque->btpo.level == 1 && access == BT_WRITE)
page_access = BT_WRITE; page_access = BT_WRITE;
/* drop the read lock on the parent page, acquire one on the child */ /* drop the read lock on the page, then acquire one on its child */
*bufP = _bt_relandgetbuf(rel, *bufP, blkno, page_access); *bufP = _bt_relandgetbuf(rel, *bufP, child, page_access);
/* okay, all set to move down a level */ /* okay, all set to move down a level */
stack_in = new_stack; stack_in = new_stack;
@ -196,8 +194,7 @@ _bt_search(Relation rel, BTScanInsert key, Buffer *bufP, int access,
* If the page was split between the time that we surrendered our read * If the page was split between the time that we surrendered our read
* lock and acquired our write lock, then this page may no longer be * lock and acquired our write lock, then this page may no longer be
* the right place for the key we want to insert. In this case, we * the right place for the key we want to insert. In this case, we
* need to move right in the tree. See Lehman and Yao for an * need to move right in the tree.
* excruciatingly precise description.
*/ */
*bufP = _bt_moveright(rel, key, *bufP, true, stack_in, BT_WRITE, *bufP = _bt_moveright(rel, key, *bufP, true, stack_in, BT_WRITE,
snapshot); snapshot);