Commit 34235a29 authored by Tom Lane's avatar Tom Lane

Cache fmgr lookup data for index's getnext() function in IndexScanDesc,

so that the fmgr lookup only has to happen once per index scan and not
once per tuple.  Seems to save 5% or so of CPU time for an indexscan.
parent 64568100
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/index/genam.c,v 1.23 2000/01/26 05:55:57 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/index/genam.c,v 1.24 2000/03/14 23:52:01 tgl Exp $
*
* NOTES
* many of the old access method routines have been turned into
......@@ -114,6 +114,9 @@ RelationGetIndexScan(Relation relation,
ItemPointerSetInvalid(&scan->currentMarkData);
ItemPointerSetInvalid(&scan->nextMarkData);
/* mark cached function lookup data invalid; it will be set on first use */
scan->fn_getnext.fn_oid = InvalidOid;
if (numberOfKeys > 0)
scan->keyData = (ScanKey) palloc(sizeof(ScanKeyData) * numberOfKeys);
else
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.40 2000/01/26 05:55:57 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.41 2000/03/14 23:52:01 tgl Exp $
*
* INTERFACE ROUTINES
* index_open - open an index relation by relationId
......@@ -329,17 +329,28 @@ RetrieveIndexResult
index_getnext(IndexScanDesc scan,
ScanDirection direction)
{
RegProcedure procedure;
RetrieveIndexResult result;
SCAN_CHECKS;
GET_SCAN_PROCEDURE(getnext, amgettuple);
/* ----------------
* Look up the access procedure only once per scan.
* ----------------
*/
if (scan->fn_getnext.fn_oid == InvalidOid)
{
RegProcedure procedure;
GET_SCAN_PROCEDURE(getnext, amgettuple);
fmgr_info(procedure, &scan->fn_getnext);
}
/* ----------------
* have the am's gettuple proc do all the work.
* ----------------
*/
result = (RetrieveIndexResult) fmgr(procedure, scan, direction);
result = (RetrieveIndexResult)
(*fmgr_faddr(&scan->fn_getnext)) (scan, direction);
return result;
}
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: relscan.h,v 1.18 2000/01/26 05:57:51 momjian Exp $
* $Id: relscan.h,v 1.19 2000/03/14 23:52:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -54,6 +54,7 @@ typedef struct IndexScanDescData
bool scanFromEnd; /* restart scan at end? */
uint16 numberOfKeys; /* number of key attributes */
ScanKey keyData; /* key descriptor */
FmgrInfo fn_getnext; /* cached lookup info for am's getnext fn */
} IndexScanDescData;
typedef IndexScanDescData *IndexScanDesc;
......
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