Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l8RH5-0000j3-5I for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Feb 2021 17:21:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l8RH4-0002aG-3e for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Feb 2021 17:21:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l8RH3-0002a9-TD for pgsql-bugs@lists.postgresql.org; Sat, 06 Feb 2021 17:21:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l8RGy-0000l8-Cy for pgsql-bugs@lists.postgresql.org; Sat, 06 Feb 2021 17:21:33 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 116HKPVa191748; Sat, 6 Feb 2021 12:20:25 -0500 From: Tom Lane To: Michael Paquier cc: todoubaba@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16856: Crash when add "_RETURN" rule on child table In-reply-to: References: <16856-0363e05c6e1612fd@postgresql.org> Comments: In-reply-to Michael Paquier message dated "Sat, 06 Feb 2021 21:50:24 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <191746.1612632025.1@sss.pgh.pa.us> Date: Sat, 06 Feb 2021 12:20:25 -0500 Message-ID: <191747.1612632025@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michael Paquier 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