Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 34235a2

Browse files
committed
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.
1 parent 6456810 commit 34235a2

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/backend/access/index/genam.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/index/genam.c,v 1.23 2000/01/26 05:55:57 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/index/genam.c,v 1.24 2000/03/14 23:52:01 tgl Exp $
1212
*
1313
* NOTES
1414
* many of the old access method routines have been turned into
@@ -114,6 +114,9 @@ RelationGetIndexScan(Relation relation,
114114
ItemPointerSetInvalid(&scan->currentMarkData);
115115
ItemPointerSetInvalid(&scan->nextMarkData);
116116

117+
/* mark cached function lookup data invalid; it will be set on first use */
118+
scan->fn_getnext.fn_oid = InvalidOid;
119+
117120
if (numberOfKeys > 0)
118121
scan->keyData = (ScanKey) palloc(sizeof(ScanKeyData) * numberOfKeys);
119122
else

src/backend/access/index/indexam.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.40 2000/01/26 05:55:57 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.41 2000/03/14 23:52:01 tgl Exp $
1212
*
1313
* INTERFACE ROUTINES
1414
* index_open - open an index relation by relationId
@@ -329,17 +329,28 @@ RetrieveIndexResult
329329
index_getnext(IndexScanDesc scan,
330330
ScanDirection direction)
331331
{
332-
RegProcedure procedure;
333332
RetrieveIndexResult result;
334333

335334
SCAN_CHECKS;
336-
GET_SCAN_PROCEDURE(getnext, amgettuple);
335+
336+
/* ----------------
337+
* Look up the access procedure only once per scan.
338+
* ----------------
339+
*/
340+
if (scan->fn_getnext.fn_oid == InvalidOid)
341+
{
342+
RegProcedure procedure;
343+
344+
GET_SCAN_PROCEDURE(getnext, amgettuple);
345+
fmgr_info(procedure, &scan->fn_getnext);
346+
}
337347

338348
/* ----------------
339349
* have the am's gettuple proc do all the work.
340350
* ----------------
341351
*/
342-
result = (RetrieveIndexResult) fmgr(procedure, scan, direction);
352+
result = (RetrieveIndexResult)
353+
(*fmgr_faddr(&scan->fn_getnext)) (scan, direction);
343354

344355
return result;
345356
}

src/include/access/relscan.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: relscan.h,v 1.18 2000/01/26 05:57:51 momjian Exp $
10+
* $Id: relscan.h,v 1.19 2000/03/14 23:52:00 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -54,6 +54,7 @@ typedef struct IndexScanDescData
5454
bool scanFromEnd; /* restart scan at end? */
5555
uint16 numberOfKeys; /* number of key attributes */
5656
ScanKey keyData; /* key descriptor */
57+
FmgrInfo fn_getnext; /* cached lookup info for am's getnext fn */
5758
} IndexScanDescData;
5859

5960
typedef IndexScanDescData *IndexScanDesc;

0 commit comments

Comments
 (0)