summaryrefslogtreecommitdiff
path: root/src/backend/catalog/pg_inherits.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-02-06 15:17:01 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2021-02-06 15:17:01 -0500
commitdd705a039f6cd41921529fa4e971d70b224be052 (patch)
treeddccef3ffc4fe579f763ea968193ee53eb37d98d /src/backend/catalog/pg_inherits.c
parentf7400823c3bd6ce03c2fe1bec5b7066bad146809 (diff)
Disallow converting an inheritance child table to a view.
Generally, members of inheritance trees must be plain tables (or, in more recent versions, foreign tables). ALTER TABLE INHERIT rejects creating an inheritance relationship that has a view at either end. When DefineQueryRewrite attempts to convert a relation to a view, it already had checks prohibiting doing so for partitioning parents or children as well as traditional-inheritance parents ... but it neglected to check that a traditional-inheritance child wasn't being converted. Since the planner assumes that any inheritance child is a table, this led to making plans that tried to do a physical scan on a view, causing failures (or even crashes, in recent versions). One could imagine trying to support such a case by expanding the view normally, but since the rewriter runs before the planner does inheritance expansion, it would take some very fundamental refactoring to make that possible. There are probably a lot of other parts of the system that don't cope well with such a situation, too. For now, just forbid it. Per bug #16856 from Yang Lin. Back-patch to all supported branches. (In versions before v10, this includes back-patching the portion of commit 501ed02cf that added has_superclass(). Perhaps the lack of that infrastructure partially explains the missing check.) Discussion: https://postgr.es/m/16856-0363e05c6e1612fd@postgresql.org
Diffstat (limited to 'src/backend/catalog/pg_inherits.c')
-rw-r--r--src/backend/catalog/pg_inherits.c12
1 files changed, 7 insertions, 5 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)