From 786340441706ac1957a031f11ad1c2e5b6e18314 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 19 Feb 2002 20:11:20 +0000 Subject: 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). --- src/backend/commands/command.c | 99 +++++------------------------------------- 1 file changed, 11 insertions(+), 88 deletions(-) (limited to 'src/backend/commands/command.c') diff --git a/src/backend/commands/command.c b/src/backend/commands/command.c index 9b1a33673c7..f01cf4498fd 100644 --- a/src/backend/commands/command.c +++ b/src/backend/commands/command.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.153 2002/02/14 15:24:06 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.154 2002/02/19 20:11:12 tgl Exp $ * * NOTES * The PerformAddAttribute() code, like most of the relation @@ -29,6 +29,7 @@ #include "catalog/pg_attrdef.h" #include "catalog/pg_index.h" #include "catalog/pg_opclass.h" +#include "catalog/pg_relcheck.h" #include "catalog/pg_type.h" #include "commands/command.h" #include "commands/trigger.h" @@ -820,92 +821,8 @@ AlterTableAlterColumnStatistics(const char *relationName, #ifdef _DROP_COLUMN_HACK__ /* * ALTER TABLE DROP COLUMN trial implementation - * */ -/* - * system table scan(index scan/sequential scan) - */ -typedef struct SysScanDescData -{ - Relation heap_rel; - Relation irel; - HeapScanDesc scan; - IndexScanDesc iscan; - HeapTupleData tuple; - Buffer buffer; -} SysScanDescData, *SysScanDesc; - -static void * -systable_beginscan(Relation rel, const char *indexRelname, int nkeys, ScanKey entry) -{ - bool hasindex = (rel->rd_rel->relhasindex && !IsIgnoringSystemIndexes()); - SysScanDesc sysscan; - - sysscan = (SysScanDesc) palloc(sizeof(SysScanDescData)); - sysscan->heap_rel = rel; - sysscan->irel = (Relation) NULL; - sysscan->tuple.t_datamcxt = NULL; - sysscan->tuple.t_data = NULL; - sysscan->buffer = InvalidBuffer; - if (hasindex) - { - sysscan->irel = index_openr((char *) indexRelname); - sysscan->iscan = index_beginscan(sysscan->irel, false, nkeys, entry); - } - else - sysscan->scan = heap_beginscan(rel, false, SnapshotNow, nkeys, entry); - return (void *) sysscan; -} - -static void -systable_endscan(void *scan) -{ - SysScanDesc sysscan = (SysScanDesc) scan; - - if (sysscan->irel) - { - if (BufferIsValid(sysscan->buffer)) - ReleaseBuffer(sysscan->buffer); - index_endscan(sysscan->iscan); - index_close(sysscan->irel); - } - else - heap_endscan(sysscan->scan); - pfree(scan); -} - -static HeapTuple -systable_getnext(void *scan) -{ - SysScanDesc sysscan = (SysScanDesc) scan; - HeapTuple htup = (HeapTuple) NULL; - RetrieveIndexResult indexRes; - - if (sysscan->irel) - { - if (BufferIsValid(sysscan->buffer)) - { - ReleaseBuffer(sysscan->buffer); - sysscan->buffer = InvalidBuffer; - } - while (indexRes = index_getnext(sysscan->iscan, ForwardScanDirection), indexRes != NULL) - { - sysscan->tuple.t_self = indexRes->heap_iptr; - heap_fetch(sysscan->heap_rel, SnapshotNow, &sysscan->tuple, &(sysscan->buffer)); - pfree(indexRes); - if (sysscan->tuple.t_data != NULL) - { - htup = &sysscan->tuple; - break; - } - } - } - else - htup = heap_getnext(sysscan->scan, 0); - return htup; -} - /* * find a specified attribute in a node entry */ @@ -957,10 +874,15 @@ RemoveColumnReferences(Oid reloid, int attnum, bool checkonly, HeapTuple reltup) /* * Remove/check constraints here */ - ScanKeyEntryInitialize(&entry, (bits16) 0x0, Anum_pg_relcheck_rcrelid, - (RegProcedure) F_OIDEQ, ObjectIdGetDatum(reloid)); + ScanKeyEntryInitialize(&entry, (bits16) 0x0, + Anum_pg_relcheck_rcrelid, + (RegProcedure) F_OIDEQ, + ObjectIdGetDatum(reloid)); + rcrel = heap_openr(RelCheckRelationName, RowExclusiveLock); - sysscan = systable_beginscan(rcrel, RelCheckIndex, 1, &entry); + sysscan = systable_beginscan(rcrel, RelCheckIndex, true, + SnapshotNow, + 1, &entry); while (HeapTupleIsValid(htup = systable_getnext(sysscan))) { @@ -987,6 +909,7 @@ RemoveColumnReferences(Oid reloid, int attnum, bool checkonly, HeapTuple reltup) } } } + systable_endscan(sysscan); heap_close(rcrel, NoLock); -- cgit v1.2.3