nbtree: Remove useless local variables.
authorPeter Geoghegan <pg@bowt.ie>
Wed, 18 Mar 2020 01:39:26 +0000 (18:39 -0700)
committerPeter Geoghegan <pg@bowt.ie>
Wed, 18 Mar 2020 01:39:26 +0000 (18:39 -0700)
Copying block and offset numbers to local variables in _bt_insertonpg()
made the code less readable.  Remove the variables.  There is already
code that conditionally calls BufferGetBlockNumber() in the same block,
so consistently do it that way instead.

Calling BufferGetBlockNumber() is very cheap, but we might as well avoid
it when it isn't truly necessary.  It isn't truly necessary for
_bt_insertonpg() to call BufferGetBlockNumber() in almost all cases.

Spotted while working on a patch that refactors the fastpath rightmost
leaf page cache optimization, which was added by commit 2b272734.

src/backend/access/nbtree/nbtinsert.c

index f503be6422414fdad7bf17a2dc3988a3272adec4..966c0bb532fe65558209f357c09b3fc2c673ebb1 100644 (file)
@@ -1180,13 +1180,8 @@ _bt_insertonpg(Relation rel,
                Buffer          metabuf = InvalidBuffer;
                Page            metapg = NULL;
                BTMetaPageData *metad = NULL;
-               OffsetNumber itup_off;
-               BlockNumber itup_blkno;
                BlockNumber cachedBlock = InvalidBlockNumber;
 
-               itup_off = newitemoff;
-               itup_blkno = BufferGetBlockNumber(buf);
-
                /*
                 * If we are doing this insert because we split a page that was the
                 * only one on its tree level, but was not the root, it may have been
@@ -1218,7 +1213,7 @@ _bt_insertonpg(Relation rel,
 
                if (!_bt_pgaddtup(page, itemsz, itup, newitemoff))
                        elog(PANIC, "failed to add new item to block %u in index \"%s\"",
-                                itup_blkno, RelationGetRelationName(rel));
+                                BufferGetBlockNumber(buf), RelationGetRelationName(rel));
 
                MarkBufferDirty(buf);
 
@@ -1227,7 +1222,7 @@ _bt_insertonpg(Relation rel,
                        /* upgrade meta-page if needed */
                        if (metad->btm_version < BTREE_NOVAC_VERSION)
                                _bt_upgrademetapage(metapg);
-                       metad->btm_fastroot = itup_blkno;
+                       metad->btm_fastroot = BufferGetBlockNumber(buf);
                        metad->btm_fastlevel = lpageop->btpo.level;
                        MarkBufferDirty(metabuf);
                }
@@ -1260,7 +1255,7 @@ _bt_insertonpg(Relation rel,
                        uint8           xlinfo;
                        XLogRecPtr      recptr;
 
-                       xlrec.offnum = itup_off;
+                       xlrec.offnum = newitemoff;
 
                        XLogBeginInsert();
                        XLogRegisterData((char *) &xlrec, SizeOfBtreeInsert);