1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-01 01:04:50 +03:00

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.
This commit is contained in:
Tom Lane 2000-03-14 23:52:01 +00:00
parent 6456810078
commit 34235a295b
3 changed files with 21 additions and 6 deletions

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* many of the old access method routines have been turned into * many of the old access method routines have been turned into
@ -114,6 +114,9 @@ RelationGetIndexScan(Relation relation,
ItemPointerSetInvalid(&scan->currentMarkData); ItemPointerSetInvalid(&scan->currentMarkData);
ItemPointerSetInvalid(&scan->nextMarkData); 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) if (numberOfKeys > 0)
scan->keyData = (ScanKey) palloc(sizeof(ScanKeyData) * numberOfKeys); scan->keyData = (ScanKey) palloc(sizeof(ScanKeyData) * numberOfKeys);
else else

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 * INTERFACE ROUTINES
* index_open - open an index relation by relationId * index_open - open an index relation by relationId
@ -329,17 +329,28 @@ RetrieveIndexResult
index_getnext(IndexScanDesc scan, index_getnext(IndexScanDesc scan,
ScanDirection direction) ScanDirection direction)
{ {
RegProcedure procedure;
RetrieveIndexResult result; RetrieveIndexResult result;
SCAN_CHECKS; 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. * 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; return result;
} }

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * 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? */ bool scanFromEnd; /* restart scan at end? */
uint16 numberOfKeys; /* number of key attributes */ uint16 numberOfKeys; /* number of key attributes */
ScanKey keyData; /* key descriptor */ ScanKey keyData; /* key descriptor */
FmgrInfo fn_getnext; /* cached lookup info for am's getnext fn */
} IndexScanDescData; } IndexScanDescData;
typedef IndexScanDescData *IndexScanDesc; typedef IndexScanDescData *IndexScanDesc;