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