diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-07-12 18:43:19 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-07-12 18:43:19 +0000 |
commit | 7c6df91dda27accab3097390ef0d21d93028c7a1 (patch) | |
tree | 5705b975e8de4edf82252e6df28e0bd57c83cb95 /src/backend/rewrite/rewriteSupport.c | |
parent | 791a40f943e2a9353c5823fb4f2bd446ec623d38 (diff) | |
download | postgresql-7c6df91dda27accab3097390ef0d21d93028c7a1.tar.gz postgresql-7c6df91dda27accab3097390ef0d21d93028c7a1.zip |
Second phase of committing Rod Taylor's pg_depend/pg_constraint patch.
pg_relcheck is gone; CHECK, UNIQUE, PRIMARY KEY, and FOREIGN KEY
constraints all have real live entries in pg_constraint. pg_depend
exists, and RESTRICT/CASCADE options work on most kinds of DROP;
however, pg_depend is not yet very well populated with dependencies.
(Most of the ones that are present at this point just replace formerly
hardwired associations, such as the implicit drop of a relation's pg_type
entry when the relation is dropped.) Need to add more logic to create
dependency entries, improve pg_dump to dump constraints in place of
indexes and triggers, and add some regression tests.
Diffstat (limited to 'src/backend/rewrite/rewriteSupport.c')
-rw-r--r-- | src/backend/rewrite/rewriteSupport.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/backend/rewrite/rewriteSupport.c b/src/backend/rewrite/rewriteSupport.c index ba590b8cc66..3f4c7f23871 100644 --- a/src/backend/rewrite/rewriteSupport.c +++ b/src/backend/rewrite/rewriteSupport.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.52 2002/06/20 20:29:34 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.53 2002/07/12 18:43:17 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -18,6 +18,7 @@ #include "catalog/catname.h" #include "catalog/indexing.h" #include "rewrite/rewriteSupport.h" +#include "utils/inval.h" #include "utils/syscache.h" @@ -44,9 +45,8 @@ IsDefinedRewriteRule(Oid owningRel, const char *ruleName) * 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. - * Therefore, we execute the update even if relhasrules has the right value - * already. Possible future improvement: skip the disk update and just send - * an SI message in that case. + * This must happen even if we find that no change is needed in the pg_class + * row. */ void SetRelationRuleStatus(Oid relationId, bool relHasRules, @@ -54,6 +54,7 @@ SetRelationRuleStatus(Oid relationId, bool relHasRules, { Relation relationRelation; HeapTuple tuple; + Form_pg_class classForm; Relation idescs[Num_pg_class_indices]; /* @@ -66,18 +67,28 @@ SetRelationRuleStatus(Oid relationId, bool relHasRules, 0, 0, 0); if (!HeapTupleIsValid(tuple)) elog(ERROR, "SetRelationRuleStatus: cache lookup failed for relation %u", relationId); + classForm = (Form_pg_class) GETSTRUCT(tuple); - /* Do the update */ - ((Form_pg_class) GETSTRUCT(tuple))->relhasrules = relHasRules; - if (relIsBecomingView) - ((Form_pg_class) GETSTRUCT(tuple))->relkind = RELKIND_VIEW; + 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); + simple_heap_update(relationRelation, &tuple->t_self, tuple); - /* Keep the catalog indices up to date */ - CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs); - CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple); - CatalogCloseIndices(Num_pg_class_indices, idescs); + /* Keep the catalog indices up to date */ + CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs); + CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple); + CatalogCloseIndices(Num_pg_class_indices, idescs); + } + else + { + /* no need to change tuple, but force relcache rebuild anyway */ + CacheInvalidateRelcache(relationId); + } heap_freetuple(tuple); heap_close(relationRelation, RowExclusiveLock); |