pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Disallow converting an inheritance child table to a view.
Date: Sat, 06 Feb 2021 20:17:29 +0000
Message-ID: <E1l8U1J-0001dz-2f@gemulon.postgresql.org> (raw)

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(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1l8U1J-0001dz-2f@gemulon.postgresql.org>
Permalink:  ../E1l8U1J-0001dz-2f@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1l8U1J-0001dz-2f@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Disallow converting an inheritance child table to a view.
  In-Reply-To: <E1l8U1J-0001dz-2f@gemulon.postgresql.org>
  References: <E1l8U1J-0001dz-2f@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox