mirror of
https://github.com/zebrajr/postgres.git
synced 2025-12-07 12:20:31 +01:00
hardwired lists of index names for each catalog, use the relcache's mechanism for caching lists of OIDs of indexes of any table. This reduces the common case of updating system catalog indexes to a single line, makes it much easier to add a new system index (in fact, you can now do so on-the-fly if you want to), and as a nice side benefit improves performance a little. Per recent pghackers discussion.
93 lines
2.6 KiB
C
93 lines
2.6 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* rewriteSupport.c
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
*
|
|
* IDENTIFICATION
|
|
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.54 2002/08/05 03:29:17 tgl Exp $
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#include "postgres.h"
|
|
|
|
#include "access/heapam.h"
|
|
#include "catalog/catname.h"
|
|
#include "catalog/indexing.h"
|
|
#include "rewrite/rewriteSupport.h"
|
|
#include "utils/inval.h"
|
|
#include "utils/syscache.h"
|
|
|
|
|
|
/*
|
|
* Is there a rule by the given name?
|
|
*/
|
|
bool
|
|
IsDefinedRewriteRule(Oid owningRel, const char *ruleName)
|
|
{
|
|
return SearchSysCacheExists(RULERELNAME,
|
|
ObjectIdGetDatum(owningRel),
|
|
PointerGetDatum(ruleName),
|
|
0, 0);
|
|
}
|
|
|
|
|
|
/*
|
|
* SetRelationRuleStatus
|
|
* Set the value of the relation's relhasrules field in pg_class;
|
|
* if the relation is becoming a view, also adjust its relkind.
|
|
*
|
|
* NOTE: caller must be holding an appropriate lock on the relation.
|
|
*
|
|
* NOTE: an important side-effect of this operation is that an SI invalidation
|
|
* message is sent out to all backends --- including me --- causing relcache
|
|
* entries to be flushed or updated with the new set of rules for the table.
|
|
* This must happen even if we find that no change is needed in the pg_class
|
|
* row.
|
|
*/
|
|
void
|
|
SetRelationRuleStatus(Oid relationId, bool relHasRules,
|
|
bool relIsBecomingView)
|
|
{
|
|
Relation relationRelation;
|
|
HeapTuple tuple;
|
|
Form_pg_class classForm;
|
|
|
|
/*
|
|
* Find the tuple to update in pg_class, using syscache for the
|
|
* lookup.
|
|
*/
|
|
relationRelation = heap_openr(RelationRelationName, RowExclusiveLock);
|
|
tuple = SearchSysCacheCopy(RELOID,
|
|
ObjectIdGetDatum(relationId),
|
|
0, 0, 0);
|
|
if (!HeapTupleIsValid(tuple))
|
|
elog(ERROR, "SetRelationRuleStatus: cache lookup failed for relation %u", relationId);
|
|
classForm = (Form_pg_class) GETSTRUCT(tuple);
|
|
|
|
if (classForm->relhasrules != relHasRules ||
|
|
(relIsBecomingView && classForm->relkind != RELKIND_VIEW))
|
|
{
|
|
/* Do the update */
|
|
classForm->relhasrules = relHasRules;
|
|
if (relIsBecomingView)
|
|
classForm->relkind = RELKIND_VIEW;
|
|
|
|
simple_heap_update(relationRelation, &tuple->t_self, tuple);
|
|
|
|
/* Keep the catalog indexes up to date */
|
|
CatalogUpdateIndexes(relationRelation, tuple);
|
|
}
|
|
else
|
|
{
|
|
/* no need to change tuple, but force relcache rebuild anyway */
|
|
CacheInvalidateRelcache(relationId);
|
|
}
|
|
|
|
heap_freetuple(tuple);
|
|
heap_close(relationRelation, RowExclusiveLock);
|
|
}
|