summaryrefslogtreecommitdiff
path: root/src/backend/access/nbtree/nbtsearch.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-08-24 01:18:34 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-08-24 01:18:34 +0000
commit08ae5edc5c883352018ef754562fc8edbd4177fd (patch)
treeef87fc45a4e1dc895b98c64fdb1d1d55295af24f /src/backend/access/nbtree/nbtsearch.c
parent7ad642d0b51fdb3a2fb4372f4b298d3f363b05ec (diff)
Optimize the case where a btree indexscan has current and mark positions
on the same index page; we can avoid data copying as well as buffer refcount manipulations in this common case. Makes for a small but noticeable improvement in mergejoin speed. Heikki Linnakangas
Diffstat (limited to 'src/backend/access/nbtree/nbtsearch.c')
-rw-r--r--src/backend/access/nbtree/nbtsearch.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c
index 2c1dfc3eb47..07bc076e49b 100644
--- a/src/backend/access/nbtree/nbtsearch.c
+++ b/src/backend/access/nbtree/nbtsearch.c
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.105 2006/05/07 01:21:30 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.106 2006/08/24 01:18:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -815,6 +815,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
so->currPos.moreRight = false;
}
so->numKilled = 0; /* just paranoia */
+ so->markItemIndex = -1; /* ditto */
/* position to the precise item on the page */
offnum = _bt_binsrch(rel, buf, keysCount, scankeys, nextkey);
@@ -1053,6 +1054,21 @@ _bt_steppage(IndexScanDesc scan, ScanDirection dir)
if (so->numKilled > 0)
_bt_killitems(scan, true);
+ /*
+ * Before we modify currPos, make a copy of the page data if there
+ * was a mark position that needs it.
+ */
+ if (so->markItemIndex >= 0)
+ {
+ /* bump pin on current buffer for assignment to mark buffer */
+ IncrBufferRefCount(so->currPos.buf);
+ memcpy(&so->markPos, &so->currPos,
+ offsetof(BTScanPosData, items[1]) +
+ so->currPos.lastItem * sizeof(BTScanPosItem));
+ so->markPos.itemIndex = so->markItemIndex;
+ so->markItemIndex = -1;
+ }
+
rel = scan->indexRelation;
if (ScanDirectionIsForward(dir))
@@ -1408,6 +1424,7 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
so->currPos.moreRight = false;
}
so->numKilled = 0; /* just paranoia */
+ so->markItemIndex = -1; /* ditto */
/*
* Now load data from the first page of the scan.