diff options
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); |