[PATCH] Tiny optimization on nbtinsert.c
Started by Ranier Vilelaover 5 years ago1 messages
Hi,
Avoiding some calls and set vars, when it is not necessary.
best regards,
Ranier Vilela
Attachments:
nbtinsert_tiny_optimization.patchapplication/octet-stream; name=nbtinsert_tiny_optimization.patchDownload
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index a70b64d964..7bcce3460e 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -1599,11 +1599,14 @@ _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf, Buffer cbuf,
else
{
/* existing item at firstrightoff becomes firstright */
- itemid = PageGetItemId(origpage, firstrightoff);
- itemsz = ItemIdGetLength(itemid);
- firstright = (IndexTuple) PageGetItem(origpage, itemid);
+ itemid = PageGetItemId(origpage, firstrightoff);
+ itemsz = ItemIdGetLength(itemid);
if (firstrightoff == origpagepostingoff)
firstright = nposting;
+ else
+ {
+ firstright = (IndexTuple) PageGetItem(origpage, itemid);
+ }
}
if (isleaf)
@@ -1623,10 +1626,13 @@ _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf, Buffer cbuf,
/* existing item before firstrightoff becomes lastleft */
lastleftoff = OffsetNumberPrev(firstrightoff);
Assert(lastleftoff >= P_FIRSTDATAKEY(oopaque));
- itemid = PageGetItemId(origpage, lastleftoff);
- lastleft = (IndexTuple) PageGetItem(origpage, itemid);
if (lastleftoff == origpagepostingoff)
lastleft = nposting;
+ else
+ {
+ itemid = PageGetItemId(origpage, lastleftoff);
+ lastleft = (IndexTuple) PageGetItem(origpage, itemid);
+ }
}
lefthighkey = _bt_truncate(rel, lastleft, firstright, itup_key);