summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane2005-12-07 18:03:48 +0000
committerTom Lane2005-12-07 18:03:48 +0000
commitf1b059af12673abf93ba13594799732bac83ed01 (patch)
tree822946b5d6f997eb31c5de4fd4a8adf11cd7ff72 /src
parent10a2df28c0dc51ac579ba2239d5f4c55e56c37d1 (diff)
A couple of tiny performance hacks in _bt_step(). Remove PageIsEmpty
checks, which were once needed because PageGetMaxOffsetNumber would fail on empty pages, but are now just redundant. Also, don't set up local variables that aren't needed in the fast path --- most of the time, we only need to advance offnum and not step across a page boundary. Motivated by noticing _bt_step at the top of OProfile profile for a pgbench run.
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/nbtree/nbtsearch.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c
index 9c42797b95c..dd4f500842b 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.97 2005/11/22 18:17:06 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.98 2005/12/07 18:03:48 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -889,9 +889,9 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
bool
_bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
{
- Relation rel = scan->indexRelation;
ItemPointer current = &(scan->currentItemData);
BTScanOpaque so = (BTScanOpaque) scan->opaque;
+ Relation rel;
Page page;
BTPageOpaque opaque;
OffsetNumber offnum,
@@ -905,16 +905,17 @@ _bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
offnum = current->ip_posid;
page = BufferGetPage(*bufP);
- opaque = (BTPageOpaque) PageGetSpecialPointer(page);
maxoff = PageGetMaxOffsetNumber(page);
if (ScanDirectionIsForward(dir))
{
- if (!PageIsEmpty(page) && offnum < maxoff)
+ if (offnum < maxoff)
offnum = OffsetNumberNext(offnum);
else
{
/* Walk right to the next page with data */
+ rel = scan->indexRelation;
+ opaque = (BTPageOpaque) PageGetSpecialPointer(page);
for (;;)
{
/* if we're at end of scan, release the buffer and return */
@@ -932,10 +933,10 @@ _bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
if (!P_IGNORE(opaque))
{
- maxoff = PageGetMaxOffsetNumber(page);
/* done if it's not empty */
+ maxoff = PageGetMaxOffsetNumber(page);
offnum = P_FIRSTDATAKEY(opaque);
- if (!PageIsEmpty(page) && offnum <= maxoff)
+ if (offnum <= maxoff)
break;
}
}
@@ -944,6 +945,7 @@ _bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
else
{
/* backwards scan */
+ opaque = (BTPageOpaque) PageGetSpecialPointer(page);
if (offnum > P_FIRSTDATAKEY(opaque))
offnum = OffsetNumberPrev(offnum);
else
@@ -955,6 +957,7 @@ _bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
* plus the possibility that the page we were on gets deleted
* after we leave it. See nbtree/README for details.
*/
+ rel = scan->indexRelation;
for (;;)
{
*bufP = _bt_walk_left(rel, *bufP);
@@ -978,8 +981,7 @@ _bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
{
maxoff = PageGetMaxOffsetNumber(page);
offnum = maxoff;
- if (!PageIsEmpty(page) &&
- maxoff >= P_FIRSTDATAKEY(opaque))
+ if (maxoff >= P_FIRSTDATAKEY(opaque))
break;
}
}