Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qvIiL-004OCr-2Q for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Oct 2023 14:49:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qvIiJ-008Vvg-21 for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Oct 2023 14:48:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qvIiI-008Vuw-Pm for pgsql-bugs@lists.postgresql.org; Tue, 24 Oct 2023 14:48:59 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qvIiG-0025Je-Rj for pgsql-bugs@lists.postgresql.org; Tue, 24 Oct 2023 14:48:58 +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 39OEmqfW556853; Tue, 24 Oct 2023 10:48:52 -0400 From: Tom Lane To: Amit Langote cc: Hans Buschmann , Peter Geoghegan , "David G. Johnston" , "pgsql-bugs@lists.postgresql.org" Subject: Re: AW: AW: BUG #18147: ERROR: invalid perminfoindex 0 in RTE with relid xxxxx In-reply-to: References: <18147-6fc796538913ee88@postgresql.org> <2796464.1696525626@sss.pgh.pa.us> <9fdfed847859435e8641e613198be9e3@nidsa.net> <3319880.1696778678@sss.pgh.pa.us> <3c9fe737f6aa4ae9b0dc19bffd97e106@nidsa.net> <408285.1698085850@sss.pgh.pa.us> <428393.1698094765@sss.pgh.pa.us> Comments: In-reply-to Amit Langote message dated "Tue, 24 Oct 2023 18:48:06 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <556851.1698158932.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Tue, 24 Oct 2023 10:48:52 -0400 Message-ID: <556852.1698158932@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Amit Langote writes: > On Tue, Oct 24, 2023 at 5:59 AM Tom Lane wrote: >> Maybe we could fix this by setting ModifyTable.rootRelation to >> the parent relation in the plain-inheritance case not only the >> partitioned case; but I've not investigated what else might be >> expecting it to be set only for partitions. > That appears to be the easiest fix to me (attached PoC makes the error > go away for me and passes check-world). > By setting rootRelation for plan-inheritance roots, there would be two > ResultRelInfos for the root relation (that is, if it's also present in > resultRelations, unlike in this case) -- one in > ModifyTableState.rootResultRelInfo and another in the 1st element of > ModifyTableState.resultRelInfo[]. That might be fine, because, > AFAICS, the partitioning-related code sites that look at the former > have checks to ensure that they don't accidentally try to access a > plain-inheritance relation as a partitioned one. I might need to take > a closer look. I suggest that it might be cleaner if we make rootRelation point to the original appendrel (that is, the RTE entry with inh = true). That would be exactly parallel to the partitioning situation, in that that RTE is not scanned in the plan. But it's for the same table as what's normally the first result table, so it should have the same permissions info. BTW, I noted while looking at this example that there are two RTEPermissionInfo structs with identical contents, one for the appendrel RTE and one for the first child. That seems kind of unnecessary. > I decided to look at fire{BS|AS}Triggers() first, because we changed > them in f49b85d783f to look at ModifyTableState.rootResultRelInfo to > get the table whose triggers to fire. They seem broken for this case: Yuck. But either proposal above would fix that, right? regards, tom lane