Re: BUG #16856: Crash when add "_RETURN" rule on child table - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #16856: Crash when add "_RETURN" rule on child table
Date
Msg-id 191747.1612632025@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #16856: Crash when add "_RETURN" rule on child table  (Michael Paquier <michael@paquier.xyz>)
Responses Re: BUG #16856: Crash when add "_RETURN" rule on child table  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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



pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: BUG #16856: Crash when add "_RETURN" rule on child table
Next
From: Tom Lane
Date:
Subject: Re: BUG #16856: Crash when add "_RETURN" rule on child table