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/parser/parse_oper.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/parser/parse_oper.c')
-rw-r--r-- | src/backend/parser/parse_oper.c | 166 |
1 files changed, 81 insertions, 85 deletions
diff --git a/src/backend/parser/parse_oper.c b/src/backend/parser/parse_oper.c index 15a39dc84bc..318f1b9eb7e 100644 --- a/src/backend/parser/parse_oper.c +++ b/src/backend/parser/parse_oper.c @@ -8,15 +8,17 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.51 2001/10/25 05:49:40 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.52 2002/02/19 20:11:15 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" +#include "access/genam.h" #include "access/heapam.h" #include "catalog/catname.h" +#include "catalog/indexing.h" #include "catalog/pg_operator.h" #include "parser/parse_coerce.h" #include "parser/parse_func.h" @@ -80,13 +82,11 @@ static int binary_oper_get_candidates(char *opname, CandidateList *candidates) { - CandidateList current_candidate; Relation pg_operator_desc; - HeapScanDesc pg_operator_scan; + SysScanDesc pg_operator_scan; HeapTuple tup; - Form_pg_operator oper; int ncandidates = 0; - ScanKeyData opKey[2]; + ScanKeyData opKey[1]; *candidates = NULL; @@ -95,38 +95,94 @@ binary_oper_get_candidates(char *opname, F_NAMEEQ, NameGetDatum(opname)); - ScanKeyEntryInitialize(&opKey[1], 0, - Anum_pg_operator_oprkind, - F_CHAREQ, - CharGetDatum('b')); - pg_operator_desc = heap_openr(OperatorRelationName, AccessShareLock); - pg_operator_scan = heap_beginscan(pg_operator_desc, - 0, - SnapshotSelf, /* ??? */ - 2, - opKey); + pg_operator_scan = systable_beginscan(pg_operator_desc, + OperatorNameIndex, true, + SnapshotNow, + 1, opKey); - while (HeapTupleIsValid(tup = heap_getnext(pg_operator_scan, 0))) + while (HeapTupleIsValid(tup = systable_getnext(pg_operator_scan))) { - oper = (Form_pg_operator) GETSTRUCT(tup); + Form_pg_operator oper = (Form_pg_operator) GETSTRUCT(tup); + + if (oper->oprkind == 'b') + { + CandidateList current_candidate; - current_candidate = (CandidateList) palloc(sizeof(struct _CandidateList)); - current_candidate->args = (Oid *) palloc(2 * sizeof(Oid)); + current_candidate = (CandidateList) palloc(sizeof(struct _CandidateList)); + current_candidate->args = (Oid *) palloc(2 * sizeof(Oid)); - current_candidate->args[0] = oper->oprleft; - current_candidate->args[1] = oper->oprright; - current_candidate->next = *candidates; - *candidates = current_candidate; - ncandidates++; + current_candidate->args[0] = oper->oprleft; + current_candidate->args[1] = oper->oprright; + current_candidate->next = *candidates; + *candidates = current_candidate; + ncandidates++; + } } - heap_endscan(pg_operator_scan); + systable_endscan(pg_operator_scan); heap_close(pg_operator_desc, AccessShareLock); return ncandidates; } /* binary_oper_get_candidates() */ +/* unary_oper_get_candidates() + * given opname, find all possible types for which + * a right/left unary operator named opname exists. + * Build a list of the candidate input types. + * Returns number of candidates found. + */ +static int +unary_oper_get_candidates(char *opname, + CandidateList *candidates, + char rightleft) +{ + Relation pg_operator_desc; + SysScanDesc pg_operator_scan; + HeapTuple tup; + int ncandidates = 0; + ScanKeyData opKey[1]; + + *candidates = NULL; + + ScanKeyEntryInitialize(&opKey[0], 0, + Anum_pg_operator_oprname, + F_NAMEEQ, + NameGetDatum(opname)); + + pg_operator_desc = heap_openr(OperatorRelationName, AccessShareLock); + pg_operator_scan = systable_beginscan(pg_operator_desc, + OperatorNameIndex, true, + SnapshotNow, + 1, opKey); + + while (HeapTupleIsValid(tup = systable_getnext(pg_operator_scan))) + { + Form_pg_operator oper = (Form_pg_operator) GETSTRUCT(tup); + + if (oper->oprkind == rightleft) + { + CandidateList current_candidate; + + current_candidate = (CandidateList) palloc(sizeof(struct _CandidateList)); + current_candidate->args = (Oid *) palloc(sizeof(Oid)); + + if (rightleft == 'r') + current_candidate->args[0] = oper->oprleft; + else + current_candidate->args[0] = oper->oprright; + current_candidate->next = *candidates; + *candidates = current_candidate; + ncandidates++; + } + } + + systable_endscan(pg_operator_scan); + heap_close(pg_operator_desc, AccessShareLock); + + return ncandidates; +} /* unary_oper_get_candidates() */ + /* oper_select_candidate() * Given the input argtype array and one or more candidates @@ -739,66 +795,6 @@ compatible_oper_funcid(char *op, Oid arg1, Oid arg2, bool noError) return InvalidOid; } -/* unary_oper_get_candidates() - * given opname, find all possible types for which - * a right/left unary operator named opname exists. - * Build a list of the candidate input types. - * Returns number of candidates found. - */ -static int -unary_oper_get_candidates(char *opname, - CandidateList *candidates, - char rightleft) -{ - CandidateList current_candidate; - Relation pg_operator_desc; - HeapScanDesc pg_operator_scan; - HeapTuple tup; - Form_pg_operator oper; - int ncandidates = 0; - ScanKeyData opKey[2]; - - *candidates = NULL; - - ScanKeyEntryInitialize(&opKey[0], 0, - Anum_pg_operator_oprname, - F_NAMEEQ, - NameGetDatum(opname)); - - ScanKeyEntryInitialize(&opKey[1], 0, - Anum_pg_operator_oprkind, - F_CHAREQ, - CharGetDatum(rightleft)); - - pg_operator_desc = heap_openr(OperatorRelationName, AccessShareLock); - pg_operator_scan = heap_beginscan(pg_operator_desc, - 0, - SnapshotSelf, /* ??? */ - 2, - opKey); - - while (HeapTupleIsValid(tup = heap_getnext(pg_operator_scan, 0))) - { - oper = (Form_pg_operator) GETSTRUCT(tup); - - current_candidate = (CandidateList) palloc(sizeof(struct _CandidateList)); - current_candidate->args = (Oid *) palloc(sizeof(Oid)); - - if (rightleft == 'r') - current_candidate->args[0] = oper->oprleft; - else - current_candidate->args[0] = oper->oprright; - current_candidate->next = *candidates; - *candidates = current_candidate; - ncandidates++; - } - - heap_endscan(pg_operator_scan); - heap_close(pg_operator_desc, AccessShareLock); - - return ncandidates; -} /* unary_oper_get_candidates() */ - /* Given unary right operator (operator on right), return oper struct * |