diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/catalog/pg_inherits.c | 12 | ||||
-rw-r--r-- | src/backend/rewrite/rewriteDefine.c | 25 |
2 files changed, 25 insertions, 12 deletions
diff --git a/src/backend/catalog/pg_inherits.c b/src/backend/catalog/pg_inherits.c index f3783961b7a..5ab79028274 100644 --- a/src/backend/catalog/pg_inherits.c +++ b/src/backend/catalog/pg_inherits.c @@ -3,8 +3,8 @@ * pg_inherits.c * routines to support manipulation of the pg_inherits relation * - * Note: currently, this module only contains inquiry functions; the actual - * creation and deletion of pg_inherits entries is done in tablecmds.c. + * Note: currently, this module mostly contains inquiry functions; actual + * creation and deletion of pg_inherits entries is mostly done in tablecmds.c. * Perhaps someday that code should be moved here, but it'd have to be * disentangled from other stuff such as pg_depend updates. * @@ -277,9 +277,11 @@ has_subclass(Oid relationId) } /* - * has_superclass - does this relation inherit from another? The caller - * should hold a lock on the given relation so that it can't be concurrently - * added to or removed from an inheritance hierarchy. + * has_superclass - does this relation inherit from another? + * + * Unlike has_subclass, this can be relied on to give an accurate answer. + * However, the caller must hold a lock on the given relation so that it + * can't be concurrently added to or removed from an inheritance hierarchy. */ bool has_superclass(Oid relationId) diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c index ee4ccbbd382..27e4ef911c8 100644 --- a/src/backend/rewrite/rewriteDefine.c +++ b/src/backend/rewrite/rewriteDefine.c @@ -25,6 +25,7 @@ #include "catalog/heap.h" #include "catalog/namespace.h" #include "catalog/objectaccess.h" +#include "catalog/pg_inherits.h" #include "catalog/pg_rewrite.h" #include "catalog/storage.h" #include "commands/policy.h" @@ -412,13 +413,14 @@ DefineQueryRewrite(const char *rulename, * Are we converting a relation to a view? * * If so, check that the relation is empty because the storage for the - * relation is going to be deleted. Also insist that the rel not have - * any triggers, indexes, child tables, policies, or RLS enabled. - * (Note: these tests are too strict, because they will reject - * relations that once had such but don't anymore. But we don't - * really care, because this whole business of converting relations to - * views is just a kluge to allow dump/reload of views that - * participate in circular dependencies.) + * relation is going to be deleted. Also insist that the rel not be + * involved in partitioning, nor have any triggers, indexes, child or + * parent tables, RLS policies, or RLS enabled. (Note: some of these + * tests are too strict, because they will reject relations that once + * had such but don't anymore. But we don't really care, because this + * whole business of converting relations to views is just an obsolete + * kluge to allow dump/reload of views that participate in circular + * dependencies.) */ if (event_relation->rd_rel->relkind != RELKIND_VIEW && event_relation->rd_rel->relkind != RELKIND_MATVIEW) @@ -433,6 +435,9 @@ DefineQueryRewrite(const char *rulename, errmsg("cannot convert partitioned table \"%s\" to a view", RelationGetRelationName(event_relation)))); + /* only case left: */ + Assert(event_relation->rd_rel->relkind == RELKIND_RELATION); + if (event_relation->rd_rel->relispartition) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), @@ -470,6 +475,12 @@ DefineQueryRewrite(const char *rulename, errmsg("could not convert table \"%s\" to a view because it has child tables", RelationGetRelationName(event_relation)))); + if (has_superclass(RelationGetRelid(event_relation))) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("could not convert table \"%s\" to a view because it has parent tables", + RelationGetRelationName(event_relation)))); + if (event_relation->rd_rel->relrowsecurity) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), |