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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Disallow converting an inheritance child table to a view.
Дата
Msg-id E1l8U1J-0001du-1w@gemulon.postgresql.org
обсуждение исходный текст
Список 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_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/4353bc878135da7b9b5b416a6986e23a70a3d9b6

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 по дате отправления:

Предыдущее
От: Michael Paquier
Дата:
Сообщение: pgsql: Clarify some comments around SharedRecoveryState in xlog.c
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Propagate CTE property flags when copying a CTE list into a rule