nbtree: Rename _bt_search() variables.
authorPeter Geoghegan <pg@bowt.ie>
Thu, 2 Jul 2020 21:54:55 +0000 (14:54 -0700)
committerPeter Geoghegan <pg@bowt.ie>
Thu, 2 Jul 2020 21:54:55 +0000 (14:54 -0700)
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.

src/backend/access/nbtree/nbtsearch.c

index 45342248128f16ee1ed574dfebcc258fff223379..f228c87a2b779f1f2fff77d55610fed429539794 100644 (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),
  * 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
- * address of the leaf-page buffer, which is locked and pinned.  No locks
- * are held on the parent pages, however!
+ * Return value is a stack of parent-page pointers (i.e. there is no entry for
+ * the leaf level/page).  *bufP is set to the address of the leaf-page buffer,
+ * 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
  * 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;
        ItemId      itemid;
        IndexTuple  itup;
-       BlockNumber blkno;
-       BlockNumber par_blkno;
+       BlockNumber child;
        BTStack     new_stack;
 
        /*
         * 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
-        * move right to its new sibling.  Do that.
+        * downlink in its parent page (or the metapage).  If it has, we may
+        * need to move right to its new sibling.  Do that.
         *
         * In write-mode, allow _bt_moveright to finish any incomplete splits
         * 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
-        * any of the upper levels (they are taken care of in _bt_getstackbuf,
-        * if the leaf page is split and we insert to the parent page).  But
-        * this is a good opportunity to finish splits of internal pages too.
+        * any of the upper levels (internal pages with incomplete splits are
+        * also taken care of in _bt_getstackbuf).  But this is a good
+        * opportunity to finish splits of internal pages too.
         */
        *bufP = _bt_moveright(rel, key, *bufP, (access == BT_WRITE), stack_in,
                              page_access, snapshot);
@@ -144,25 +144,23 @@ _bt_search(Relation rel, BTScanInsert key, Buffer *bufP, int access,
            break;
 
        /*
-        * Find the appropriate item on the internal page, and get the child
-        * page that it points to.
+        * Find the appropriate pivot tuple on this page.  Its downlink points
+        * to the child page that we're about to descend to.
         */
        offnum = _bt_binsrch(rel, key, *bufP);
        itemid = PageGetItemId(page, offnum);
        itup = (IndexTuple) PageGetItem(page, itemid);
        Assert(BTreeTupleIsPivot(itup) || !key->heapkeyspace);
-       blkno = BTreeTupleGetDownLink(itup);
-       par_blkno = BufferGetBlockNumber(*bufP);
+       child = BTreeTupleGetDownLink(itup);
 
        /*
-        * We need to save the location of the pivot tuple we chose in the
-        * parent page on a stack.  If we need to split a page, we'll use the
-        * stack to work back up to its parent page.  If caller ends up
-        * splitting a page one level down, it usually ends up inserting a new
-        * pivot tuple/downlink immediately after the location recorded here.
+        * We need to save the location of the pivot tuple we chose in a new
+        * stack entry for this page/level.  If caller ends up splitting a
+        * page one level down, it usually ends up inserting a new pivot
+        * tuple/downlink immediately after the location recorded here.
         */
        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_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)
            page_access = BT_WRITE;
 
-       /* drop the read lock on the parent page, acquire one on the child */
-       *bufP = _bt_relandgetbuf(rel, *bufP, blkno, page_access);
+       /* drop the read lock on the page, then acquire one on its child */
+       *bufP = _bt_relandgetbuf(rel, *bufP, child, page_access);
 
        /* okay, all set to move down a level */
        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
         * 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
-        * need to move right in the tree.  See Lehman and Yao for an
-        * excruciatingly precise description.
+        * need to move right in the tree.
         */
        *bufP = _bt_moveright(rel, key, *bufP, true, stack_in, BT_WRITE,
                              snapshot);