pgsql: Disallow converting an inheritance child table to a view. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Disallow converting an inheritance child table to a view.
Date
Msg-id E1l8U1J-0001dz-2f@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/580069037cec005ed3b61d233ae87462be91c6d0

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


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: Clarify some comments around SharedRecoveryState in xlog.c
Next
From: Tom Lane
Date:
Subject: pgsql: Propagate CTE property flags when copying a CTE list into a rule