diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-02-06 15:17:02 -0500 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-02-06 15:17:02 -0500 |
| commit | 5ad03374bfe74ebdea937461170c1567671e11e0 (patch) | |
| tree | 8fb654257ba05395e382dd2dd2308cb534eda973 /src/test | |
| parent | aaf266157d21935d8106bd68c18eadea5dfdf1eb (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/test')
| -rw-r--r-- | src/test/regress/expected/rules.out | 11 | ||||
| -rw-r--r-- | src/test/regress/sql/rules.sql | 11 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 615e14fbe48..1d094b995ae 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -2457,6 +2457,17 @@ select reltoastrelid, relkind, relfrozenxid (1 row) drop view fooview; +-- cannot convert an inheritance parent or child to a view, though +create table fooview (x int, y text); +create table fooview_child () inherits (fooview); +create rule "_RETURN" as on select to fooview do instead + select 1 as x, 'aaa'::text as y; +ERROR: could not convert table "fooview" to a view because it has child tables +create rule "_RETURN" as on select to fooview_child do instead + select 1 as x, 'aaa'::text as y; +ERROR: could not convert table "fooview_child" to a view because it has parent tables +drop table fooview cascade; +NOTICE: drop cascades to table fooview_child -- -- check for planner problems with complex inherited UPDATES -- diff --git a/src/test/regress/sql/rules.sql b/src/test/regress/sql/rules.sql index 12cd4a012bc..347545063f0 100644 --- a/src/test/regress/sql/rules.sql +++ b/src/test/regress/sql/rules.sql @@ -898,6 +898,17 @@ select reltoastrelid, relkind, relfrozenxid drop view fooview; +-- cannot convert an inheritance parent or child to a view, though +create table fooview (x int, y text); +create table fooview_child () inherits (fooview); + +create rule "_RETURN" as on select to fooview do instead + select 1 as x, 'aaa'::text as y; +create rule "_RETURN" as on select to fooview_child do instead + select 1 as x, 'aaa'::text as y; + +drop table fooview cascade; + -- -- check for planner problems with complex inherited UPDATES -- |
