Thread: pgsql: Disallow converting an inheritance child table to a view.

pgsql: Disallow converting an inheritance child table to a view.

From
Tom Lane
Date:
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

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ad85e5efa1bf6d534c1c519598c2beaaaa5eeb2f

Modified Files
--------------
src/backend/catalog/pg_inherits.c   |  8 +++++---
src/backend/rewrite/rewriteDefine.c | 25 ++++++++++++++++++-------
src/test/regress/expected/rules.out | 15 +++++++++++++--
src/test/regress/sql/rules.sql      | 16 ++++++++++++++--
4 files changed, 50 insertions(+), 14 deletions(-)