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/nodeIndexscan.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/nodeIndexscan.c')
-rw-r--r-- | src/backend/executor/nodeIndexscan.c | 83 |
1 files changed, 56 insertions, 27 deletions
diff --git a/src/backend/executor/nodeIndexscan.c b/src/backend/executor/nodeIndexscan.c index bde5bce334d..3ab73f62f9a 100644 --- a/src/backend/executor/nodeIndexscan.c +++ b/src/backend/executor/nodeIndexscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.66 2002/02/11 20:10:48 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.67 2002/02/19 20:11:13 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -359,14 +359,20 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent) int n_keys; ScanKey scan_keys; int *run_keys; + List *listscan; indxqual = lnext(indxqual); n_keys = numScanKeys[i]; scan_keys = scanKeys[i]; run_keys = runtimeKeyInfo[i]; + listscan = qual; for (j = 0; j < n_keys; j++) { + Expr *clause = lfirst(listscan); + + listscan = lnext(listscan); + /* * If we have a run-time key, then extract the run-time * expression and evaluate it with respect to the current @@ -382,7 +388,6 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent) */ if (run_keys[j] != NO_OP) { - Expr *clause = nth(j, qual); Node *scanexpr; Datum scanvalue; bool isNull; @@ -448,6 +453,9 @@ ExecEndIndexScan(IndexScan *node) List *indxqual; int *numScanKeys; int numIndices; + Relation relation; + RelationPtr indexRelationDescs; + IndexScanDescPtr indexScanDescs; int i; scanstate = node->scan.scanstate; @@ -461,6 +469,9 @@ ExecEndIndexScan(IndexScan *node) numIndices = indexstate->iss_NumIndices; scanKeys = indexstate->iss_ScanKeys; numScanKeys = indexstate->iss_NumScanKeys; + indexRelationDescs = indexstate->iss_RelationDescs; + indexScanDescs = indexstate->iss_ScanDescs; + relation = scanstate->css_currentRelation; /* * Free the projection info and the scan attribute info @@ -475,9 +486,25 @@ ExecEndIndexScan(IndexScan *node) FreeExprContext(indexstate->iss_RuntimeContext); /* - * close the heap and index relations + * close the index relations + */ + for (i = 0; i < numIndices; i++) + { + if (indexScanDescs[i] != NULL) + index_endscan(indexScanDescs[i]); + + if (indexRelationDescs[i] != NULL) + index_close(indexRelationDescs[i]); + } + + /* + * close the heap relation. + * + * Currently, we do not release the AccessShareLock acquired by + * ExecInitIndexScan. 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); /* * free the scan keys used in scanning the indices @@ -589,6 +616,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent) CommonScanState *scanstate; List *indxqual; List *indxid; + List *listscan; int i; int numIndices; int indexPtr; @@ -603,7 +631,6 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent) Index relid; Oid reloid; Relation currentRelation; - HeapScanDesc currentScanDesc; ScanDirection direction; /* @@ -709,6 +736,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent) * for each opclause in the given qual, convert each qual's * opclause into a single scan key */ + listscan = qual; for (j = 0; j < n_keys; j++) { Expr *clause; /* one clause of index qual */ @@ -725,7 +753,8 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent) /* * extract clause information from the qualification */ - clause = nth(j, qual); + clause = lfirst(listscan); + listscan = lnext(listscan); op = (Oper *) clause->oper; if (!IsA(clause, Expr) ||!IsA(op, Oper)) @@ -989,25 +1018,19 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent) direction = estate->es_direction; /* - * open the base relation + * open the base relation and acquire AccessShareLock on it. */ relid = node->scan.scanrelid; rtentry = rt_fetch(relid, rangeTable); reloid = rtentry->relid; - ExecOpenScanR(reloid, /* relation */ - 0, /* nkeys */ - (ScanKey) 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); if (!RelationGetForm(currentRelation)->relhasindex) elog(ERROR, "indexes of the relation %u was inactivated", reloid); + scanstate->css_currentRelation = currentRelation; - scanstate->css_currentScanDesc = currentScanDesc; + scanstate->css_currentScanDesc = NULL; /* no heap scan here */ /* * get the scan type from the relation descriptor. @@ -1017,24 +1040,30 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent) /* * open the index relations and initialize relation and scan - * descriptors. + * descriptors. Note we acquire no locks here; the index machinery + * does its own locks and unlocks. (We rely on having AccessShareLock + * on the parent table to ensure the index won't go away!) */ + listscan = indxid; for (i = 0; i < numIndices; i++) { - Oid indexOid = (Oid) nthi(i, indxid); + Oid indexOid = (Oid) lfirsti(listscan); if (indexOid != 0) { - ExecOpenScanR(indexOid, /* relation */ - numScanKeys[i], /* nkeys */ - scanKeys[i], /* scan key */ - true, /* is index */ - direction, /* scan direction */ - estate->es_snapshot, - &(relationDescs[i]), /* return: rel desc */ - (Pointer *) &(scanDescs[i])); - /* return: scan desc */ + relationDescs[i] = index_open(indexOid); + + /* + * Note: index_beginscan()'s second arg is a boolean indicating + * that the scan should be done in reverse. That is, if you pass + * it true, then the scan is backward. + */ + scanDescs[i] = index_beginscan(relationDescs[i], + false, /* see above comment */ + numScanKeys[i], + scanKeys[i]); } + listscan = lnext(listscan); } indexstate->iss_RelationDescs = relationDescs; |