Re: BUG #16856: Crash when add "_RETURN" rule on child table

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: todoubaba(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16856: Crash when add "_RETURN" rule on child table
Date: 2021-02-06 17:20:25
Message-ID: 191747.1612632025@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Michael Paquier <michael(at)paquier(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2021-02-06 17:31:01 Re: BUG #16856: Crash when add "_RETURN" rule on child table
Previous Message Michael Paquier 2021-02-06 12:50:24 Re: BUG #16856: Crash when add "_RETURN" rule on child table