1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-23 14:01:44 +03:00

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).
This commit is contained in:
Tom Lane
2002-02-19 20:11:20 +00:00
parent 8e2998d8a6
commit 7863404417
33 changed files with 1997 additions and 2220 deletions

View File

@ -48,6 +48,12 @@
* (XXX is it worth testing likewise for duplicate catcache flush entries?
* Probably not.)
*
* If a relcache flush is issued for a system relation that we preload
* from the relcache init file, we must also delete the init file so that
* it will be rebuilt during the next backend restart. The actual work of
* manipulating the init file is in relcache.c, but we keep track of the
* need for it here.
*
* All the request lists are kept in TopTransactionContext memory, since
* they need not live beyond the end of the current transaction.
*
@ -56,7 +62,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.47 2001/11/16 23:30:35 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.48 2002/02/19 20:11:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -107,6 +113,8 @@ typedef struct InvalidationListHeader
*/
static InvalidationListHeader GlobalInvalidMsgs;
static bool RelcacheInitFileInval; /* init file must be invalidated? */
/*
* head of invalidation message list for the current command
* eaten by AtCommit_LocalCache() in CommandCounterIncrement()
@ -339,6 +347,13 @@ RegisterRelcacheInvalidation(Oid dbId, Oid relId)
dbId, relId);
AddRelcacheInvalidationMessage(&LocalInvalidMsgs,
dbId, relId);
/*
* If the relation being invalidated is one of those cached in the
* relcache init file, mark that we need to zap that file at commit.
*/
if (RelationIdIsInInitFile(relId))
RelcacheInitFileInval = true;
}
/*
@ -418,8 +433,8 @@ InvalidateSystemCaches(void)
/*
* PrepareForTupleInvalidation
* Invoke functions for the tuple which register invalidation
* of catalog/relation cache.
* Detect whether invalidation of this tuple implies invalidation
* of catalog/relation cache entries; if so, register inval events.
*/
static void
PrepareForTupleInvalidation(Relation relation, HeapTuple tuple,
@ -525,8 +540,19 @@ AtEOXactInvalidationMessages(bool isCommit)
{
if (isCommit)
{
/*
* Relcache init file invalidation requires processing both
* before and after we send the SI messages. However, we need
* not do anything unless we committed.
*/
if (RelcacheInitFileInval)
RelationCacheInitFileInvalidate(true);
ProcessInvalidationMessages(&GlobalInvalidMsgs,
SendSharedInvalidMessage);
if (RelcacheInitFileInval)
RelationCacheInitFileInvalidate(false);
}
else
{
@ -534,6 +560,8 @@ AtEOXactInvalidationMessages(bool isCommit)
LocalExecuteInvalidationMessage);
}
RelcacheInitFileInval = false;
DiscardInvalidationMessages(&GlobalInvalidMsgs, false);
DiscardInvalidationMessages(&LocalInvalidMsgs, false);
DiscardInvalidationMessages(&RollbackMsgs, false);