diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-02-19 20:11:20 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-02-19 20:11:20 +0000 |
commit | 786340441706ac1957a031f11ad1c2e5b6e18314 (patch) | |
tree | 4e6b689b96778e42e6cc679169f71dc180049e04 /src/backend/executor/nodeSeqscan.c | |
parent | 8e2998d8a6aebc2a3b22e6048fab8abe1c95f1f0 (diff) | |
download | postgresql-786340441706ac1957a031f11ad1c2e5b6e18314.tar.gz postgresql-786340441706ac1957a031f11ad1c2e5b6e18314.zip |
A bunch of changes aimed at reducing backend startup time...
Improve 'pg_internal.init' relcache entry preload mechanism so that it is
safe to use for all system catalogs, and arrange to preload a realistic
set of system-catalog entries instead of only the three nailed-in-cache
indexes that were formerly loaded this way. Fix mechanism for deleting
out-of-date pg_internal.init files: this must be synchronized with transaction
commit, not just done at random times within transactions. Drive it off
relcache invalidation mechanism so that no special-case tests are needed.
Cache additional information in relcache entries for indexes (their pg_index
tuples and index-operator OIDs) to eliminate repeated lookups. Also cache
index opclass info at the per-opclass level to avoid repeated lookups during
relcache load.
Generalize 'systable scan' utilities originally developed by Hiroshi,
move them into genam.c, use in a number of places where there was formerly
ugly code for choosing either heap or index scan. In particular this allows
simplification of the logic that prevents infinite recursion between syscache
and relcache during startup: we can easily switch to heapscans in relcache.c
when and where needed to avoid recursion, so IndexScanOK becomes simpler and
does not need any expensive initialization.
Eliminate useless opening of a heapscan data structure while doing an indexscan
(this saves an mdnblocks call and thus at least one kernel call).
Diffstat (limited to 'src/backend/executor/nodeSeqscan.c')
-rw-r--r-- | src/backend/executor/nodeSeqscan.c | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/src/backend/executor/nodeSeqscan.c b/src/backend/executor/nodeSeqscan.c index d7ebec4985f..957a1bb2b72 100644 --- a/src/backend/executor/nodeSeqscan.c +++ b/src/backend/executor/nodeSeqscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/nodeSeqscan.c,v 1.33 2001/10/28 06:25:43 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/nodeSeqscan.c,v 1.34 2002/02/19 20:11:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -154,7 +154,9 @@ InitScanRelation(SeqScan *node, EState *estate, /* * get the relation object id from the relid'th entry in the range - * table, open that relation and initialize the scan state... + * table, open that relation and initialize the scan state. + * + * We acquire AccessShareLock for the duration of the scan. */ relid = node->scanrelid; rangeTable = estate->es_range_table; @@ -162,14 +164,13 @@ InitScanRelation(SeqScan *node, EState *estate, reloid = rtentry->relid; direction = estate->es_direction; - ExecOpenScanR(reloid, /* relation */ - 0, /* nkeys */ - NULL, /* scan key */ - false, /* is index */ - direction, /* scan direction */ - estate->es_snapshot, - ¤tRelation, /* return: rel desc */ - (Pointer *) ¤tScanDesc); /* return: scan desc */ + currentRelation = heap_open(reloid, AccessShareLock); + + currentScanDesc = heap_beginscan(currentRelation, + ScanDirectionIsBackward(direction), + estate->es_snapshot, + 0, + NULL); scanstate->css_currentRelation = currentRelation; scanstate->css_currentScanDesc = currentScanDesc; @@ -189,7 +190,6 @@ ExecInitSeqScan(SeqScan *node, EState *estate, Plan *parent) { CommonScanState *scanstate; Oid reloid; - HeapScanDesc scandesc; /* * Once upon a time it was possible to have an outerPlan of a SeqScan, @@ -229,7 +229,6 @@ ExecInitSeqScan(SeqScan *node, EState *estate, Plan *parent) */ reloid = InitScanRelation(node, estate, scanstate); - scandesc = scanstate->css_currentScanDesc; scanstate->cstate.cs_TupFromTlist = false; /* @@ -259,11 +258,15 @@ void ExecEndSeqScan(SeqScan *node) { CommonScanState *scanstate; + Relation relation; + HeapScanDesc scanDesc; /* * get information from node */ scanstate = node->scanstate; + relation = scanstate->css_currentRelation; + scanDesc = scanstate->css_currentScanDesc; /* * Free the projection info and the scan attribute info @@ -276,9 +279,18 @@ ExecEndSeqScan(SeqScan *node) ExecFreeExprContext(&scanstate->cstate); /* - * close scan relation + * close heap scan + */ + heap_endscan(scanDesc); + + /* + * close the heap relation. + * + * Currently, we do not release the AccessShareLock acquired by + * InitScanRelation. This lock should be held till end of transaction. + * (There is a faction that considers this too much locking, however.) */ - ExecCloseR((Plan *) node); + heap_close(relation, NoLock); /* * clean out the tuple table @@ -303,7 +315,6 @@ ExecSeqReScan(SeqScan *node, ExprContext *exprCtxt, Plan *parent) { CommonScanState *scanstate; EState *estate; - Relation rel; HeapScanDesc scan; ScanDirection direction; @@ -317,11 +328,13 @@ ExecSeqReScan(SeqScan *node, ExprContext *exprCtxt, Plan *parent) estate->es_evTupleNull[node->scanrelid - 1] = false; return; } - rel = scanstate->css_currentRelation; + scan = scanstate->css_currentScanDesc; direction = estate->es_direction; - scan = ExecReScanR(rel, scan, direction, 0, NULL); - scanstate->css_currentScanDesc = scan; + + heap_rescan(scan, /* scan desc */ + ScanDirectionIsBackward(direction), /* backward flag */ + NULL); /* new scan keys */ } /* ---------------------------------------------------------------- |