Re: BUG #16856: Crash when add "_RETURN" rule on child table
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Paquier <michael@paquier.xyz>
Cc: todoubaba@gmail.com, pgsql-bugs@lists.postgresql.org
Date: 2021-02-06T17:20:25Z
Lists: pgsql-bugs
Michael Paquier <michael@paquier.xyz> writes:
> On Sat, Feb 06, 2021 at 07:46:14AM +0000, PG Bug reporting form wrote:
>> create table parent(a text);
>> create table child() inherits (parent);
>> create or replace rule "_RETURN" as
>> on select
>> to child
>> do instead
>> select *
>> from (values('x')) as t(a);
>>
>> select * from parent;
> Yes, reproduced here. This crashes as the relcache entry of the child
> relation is not getting its rd_tableam initialized.
I don't think it's unreasonable for the code to assume that child
relations are tables and not views. If you did the equivalent
regression=# create table parent(a text);
CREATE TABLE
regression=# create view child as select *
regression-# from (values('x')) as t(a);
CREATE VIEW
regression=# alter table child inherit parent;
ERROR: "child" is not a table or foreign table
or for that matter
regression=# alter table parent inherit child;
ERROR: "child" is not a table or foreign table
So my take is that this is an oversight in the CREATE RULE logic
that allows converting a table to a view: if it has inheritance
parents or children we must disallow doing that.
I'd be inclined to back-patch further than 12, too. Even if
there's not an obvious instant crash in those branches, it's
unlikely that their behavior is entirely sane.
regards, tom lane
Commits
-
Disallow converting an inheritance child table to a view.
- ad85e5efa1bf 10.16 landed
- 7736ab05fe83 9.6.21 landed
- 5ad03374bfe7 9.5.25 landed
- 580069037cec 11.11 landed
- f7332195708d 12.6 landed
- dd705a039f6c 14.0 landed
- 4353bc878135 13.2 landed