Commit 5d1dd2bc authored by Neil Conway's avatar Neil Conway

Micro-optimization of markpos() and restrpos() in btree and hash indexes.

Rather than using ReadBuffer() to increment the reference count on an
already-pinned buffer, we should use IncrBufferRefCount() as it is
faster and does not require acquiring the BufMgrLock.
parent a51e54cf
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.74 2004/11/11 00:32:40 neilc Exp $ * $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.75 2004/11/17 03:13:37 neilc Exp $
* *
* NOTES * NOTES
* This file contains only the public interface routines. * This file contains only the public interface routines.
...@@ -397,9 +397,8 @@ hashmarkpos(PG_FUNCTION_ARGS) ...@@ -397,9 +397,8 @@ hashmarkpos(PG_FUNCTION_ARGS)
/* bump pin count on currentItemData and copy to currentMarkData */ /* bump pin count on currentItemData and copy to currentMarkData */
if (ItemPointerIsValid(&(scan->currentItemData))) if (ItemPointerIsValid(&(scan->currentItemData)))
{ {
so->hashso_mrkbuf = _hash_getbuf(rel, IncrBufferRefCount(so->hashso_curbuf);
BufferGetBlockNumber(so->hashso_curbuf), so->hashso_mrkbuf = so->hashso_curbuf;
HASH_NOLOCK);
scan->currentMarkData = scan->currentItemData; scan->currentMarkData = scan->currentItemData;
} }
...@@ -425,9 +424,8 @@ hashrestrpos(PG_FUNCTION_ARGS) ...@@ -425,9 +424,8 @@ hashrestrpos(PG_FUNCTION_ARGS)
/* bump pin count on currentMarkData and copy to currentItemData */ /* bump pin count on currentMarkData and copy to currentItemData */
if (ItemPointerIsValid(&(scan->currentMarkData))) if (ItemPointerIsValid(&(scan->currentMarkData)))
{ {
so->hashso_curbuf = _hash_getbuf(rel, IncrBufferRefCount(so->hashso_mrkbuf);
BufferGetBlockNumber(so->hashso_mrkbuf), so->hashso_curbuf = so->hashso_mrkbuf;
HASH_NOLOCK);
scan->currentItemData = scan->currentMarkData; scan->currentItemData = scan->currentMarkData;
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.121 2004/11/11 00:32:50 neilc Exp $ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.122 2004/11/17 03:13:38 neilc Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -477,8 +477,8 @@ btmarkpos(PG_FUNCTION_ARGS) ...@@ -477,8 +477,8 @@ btmarkpos(PG_FUNCTION_ARGS)
/* bump pin on current buffer for assignment to mark buffer */ /* bump pin on current buffer for assignment to mark buffer */
if (ItemPointerIsValid(&(scan->currentItemData))) if (ItemPointerIsValid(&(scan->currentItemData)))
{ {
so->btso_mrkbuf = ReadBuffer(scan->indexRelation, IncrBufferRefCount(so->btso_curbuf);
BufferGetBlockNumber(so->btso_curbuf)); so->btso_mrkbuf = so->btso_curbuf;
scan->currentMarkData = scan->currentItemData; scan->currentMarkData = scan->currentItemData;
so->mrkHeapIptr = so->curHeapIptr; so->mrkHeapIptr = so->curHeapIptr;
} }
...@@ -509,8 +509,8 @@ btrestrpos(PG_FUNCTION_ARGS) ...@@ -509,8 +509,8 @@ btrestrpos(PG_FUNCTION_ARGS)
/* bump pin on marked buffer */ /* bump pin on marked buffer */
if (ItemPointerIsValid(&(scan->currentMarkData))) if (ItemPointerIsValid(&(scan->currentMarkData)))
{ {
so->btso_curbuf = ReadBuffer(scan->indexRelation, IncrBufferRefCount(so->btso_mrkbuf);
BufferGetBlockNumber(so->btso_mrkbuf)); so->btso_curbuf = so->btso_mrkbuf;
scan->currentItemData = scan->currentMarkData; scan->currentItemData = scan->currentMarkData;
so->curHeapIptr = so->mrkHeapIptr; so->curHeapIptr = so->mrkHeapIptr;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment