aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_func.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-02-19 20:11:20 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-02-19 20:11:20 +0000
commit786340441706ac1957a031f11ad1c2e5b6e18314 (patch)
tree4e6b689b96778e42e6cc679169f71dc180049e04 /src/backend/parser/parse_func.c
parent8e2998d8a6aebc2a3b22e6048fab8abe1c95f1f0 (diff)
downloadpostgresql-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_func.c')
-rw-r--r--src/backend/parser/parse_func.c94
1 files changed, 38 insertions, 56 deletions
diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c
index 77391851338..766a5daad55 100644
--- a/src/backend/parser/parse_func.c
+++ b/src/backend/parser/parse_func.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.115 2001/12/12 03:28:49 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.116 2002/02/19 20:11:15 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -547,11 +547,9 @@ agg_get_candidates(char *aggname,
Oid typeId,
CandidateList *candidates)
{
- CandidateList current_candidate;
Relation pg_aggregate_desc;
- HeapScanDesc pg_aggregate_scan;
+ SysScanDesc pg_aggregate_scan;
HeapTuple tup;
- Form_pg_aggregate agg;
int ncandidates = 0;
ScanKeyData aggKey[1];
@@ -563,15 +561,15 @@ agg_get_candidates(char *aggname,
NameGetDatum(aggname));
pg_aggregate_desc = heap_openr(AggregateRelationName, AccessShareLock);
- pg_aggregate_scan = heap_beginscan(pg_aggregate_desc,
- 0,
- SnapshotSelf, /* ??? */
- 1,
- aggKey);
+ pg_aggregate_scan = systable_beginscan(pg_aggregate_desc,
+ AggregateNameTypeIndex, true,
+ SnapshotNow,
+ 1, aggKey);
- while (HeapTupleIsValid(tup = heap_getnext(pg_aggregate_scan, 0)))
+ while (HeapTupleIsValid(tup = systable_getnext(pg_aggregate_scan)))
{
- agg = (Form_pg_aggregate) GETSTRUCT(tup);
+ Form_pg_aggregate agg = (Form_pg_aggregate) GETSTRUCT(tup);
+ CandidateList current_candidate;
current_candidate = (CandidateList) palloc(sizeof(struct _CandidateList));
current_candidate->args = (Oid *) palloc(sizeof(Oid));
@@ -582,7 +580,7 @@ agg_get_candidates(char *aggname,
ncandidates++;
}
- heap_endscan(pg_aggregate_scan);
+ systable_endscan(pg_aggregate_scan);
heap_close(pg_aggregate_desc, AccessShareLock);
return ncandidates;
@@ -680,62 +678,46 @@ static CandidateList
func_get_candidates(char *funcname, int nargs)
{
Relation heapRelation;
- Relation idesc;
- ScanKeyData skey;
- HeapTupleData tuple;
- IndexScanDesc sd;
- RetrieveIndexResult indexRes;
- Form_pg_proc pgProcP;
+ ScanKeyData skey[2];
+ HeapTuple tuple;
+ SysScanDesc funcscan;
CandidateList candidates = NULL;
- CandidateList current_candidate;
int i;
heapRelation = heap_openr(ProcedureRelationName, AccessShareLock);
- ScanKeyEntryInitialize(&skey,
+
+ ScanKeyEntryInitialize(&skey[0],
(bits16) 0x0,
(AttrNumber) Anum_pg_proc_proname,
(RegProcedure) F_NAMEEQ,
PointerGetDatum(funcname));
+ ScanKeyEntryInitialize(&skey[1],
+ (bits16) 0x0,
+ (AttrNumber) Anum_pg_proc_pronargs,
+ (RegProcedure) F_INT2EQ,
+ Int16GetDatum(nargs));
- idesc = index_openr(ProcedureNameIndex);
-
- sd = index_beginscan(idesc, false, 1, &skey);
+ funcscan = systable_beginscan(heapRelation, ProcedureNameIndex, true,
+ SnapshotNow, 2, skey);
- do
+ while (HeapTupleIsValid(tuple = systable_getnext(funcscan)))
{
- indexRes = index_getnext(sd, ForwardScanDirection);
- if (indexRes)
- {
- Buffer buffer;
-
- tuple.t_datamcxt = NULL;
- tuple.t_data = NULL;
- tuple.t_self = indexRes->heap_iptr;
- heap_fetch(heapRelation, SnapshotNow, &tuple, &buffer, sd);
- pfree(indexRes);
- if (tuple.t_data != NULL)
- {
- pgProcP = (Form_pg_proc) GETSTRUCT(&tuple);
- if (pgProcP->pronargs == nargs)
- {
- current_candidate = (CandidateList)
- palloc(sizeof(struct _CandidateList));
- current_candidate->args = (Oid *)
- palloc(FUNC_MAX_ARGS * sizeof(Oid));
- MemSet(current_candidate->args, 0, FUNC_MAX_ARGS * sizeof(Oid));
- for (i = 0; i < nargs; i++)
- current_candidate->args[i] = pgProcP->proargtypes[i];
-
- current_candidate->next = candidates;
- candidates = current_candidate;
- }
- ReleaseBuffer(buffer);
- }
- }
- } while (indexRes);
+ Form_pg_proc pgProcP = (Form_pg_proc) GETSTRUCT(tuple);
+ CandidateList current_candidate;
+
+ current_candidate = (CandidateList)
+ palloc(sizeof(struct _CandidateList));
+ current_candidate->args = (Oid *)
+ palloc(FUNC_MAX_ARGS * sizeof(Oid));
+ MemSet(current_candidate->args, 0, FUNC_MAX_ARGS * sizeof(Oid));
+ for (i = 0; i < nargs; i++)
+ current_candidate->args[i] = pgProcP->proargtypes[i];
+
+ current_candidate->next = candidates;
+ candidates = current_candidate;
+ }
- index_endscan(sd);
- index_close(idesc);
+ systable_endscan(funcscan);
heap_close(heapRelation, AccessShareLock);
return candidates;