postgrespro.git / summary / log / commit / refs
commit b897b3aae6b525922fe3d074d4bdf5f2674954dd
Author: Peter Geoghegan <pg@bowt.ie>
Date: Wed Mar 18 01:39:26 2020 +0000
nbtree: Remove useless local variables.
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 | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index f503be6422..966c0bb532 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -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);
[parent: 9b8aa0929390]