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 1l5aNg-0004Bq-7e for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Jan 2021 20:28:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l5aNe-0004yr-L1 for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Jan 2021 20:28: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 1l5aNe-0004yk-E5 for pgsql-hackers@lists.postgresql.org; Fri, 29 Jan 2021 20:28:34 +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 1l5aNc-00006T-J0 for pgsql-hackers@lists.postgresql.org; Fri, 29 Jan 2021 20:28:34 +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 10TKSQrJ2823554; Fri, 29 Jan 2021 15:28:26 -0500 From: Tom Lane To: David Rowley cc: Andreas Seltenreich , pgsql-hackers@lists.postgresql.org Subject: Re: [sqlsmith] Failed assertion during partition pruning In-reply-to: <1501458.1606854684@sss.pgh.pa.us> References: <87sg8tqhsl.fsf@aurora.ydns.eu> <919903.1606603948@sss.pgh.pa.us> <1501458.1606854684@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 01 Dec 2020 15:31:24 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2823552.1611952106.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 29 Jan 2021 15:28:26 -0500 Message-ID: <2823553.1611952106@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: >> What it looks like to me is that the code for setting up run-time >> partition pruning has failed to consider the possibility of nested >> partitioning: it's expecting that every partitioned table will have >> at least one direct child that is a leaf. I'm not sure though >> whether just the Assert is wrong, or there's more fundamental >> issues here. > After looking into the git history I realized that this assertion is > quite new, stemming from David's a929e17e5a8 of 2020-11-02. So there's > something not right about that. I took some more time to poke at this today, and I now think that the assertion in make_partitionedrel_pruneinfo is probably OK, and what it's pointing out is a bug upstream in path creation. Specifically, I noted that in select a from trigger_parted where pg_trigger_depth() <> a order by a; we arrive at make_partitionedrel_pruneinfo with partrelids equal to (b 1 2), which seems to be correct. The RTE list is RTE 1: trigger_parted RTE 2: trigger_parted_p1 RTE 3: trigger_parted_p1_1 Like so much else of the partitioning code, AppendPath.partitioned_rels is abysmally underdocumented, but what I think it means is the set of non-leaf partitioned tables that are notionally scanned by the AppendPath. The only table directly mentioned by the AppendPath's subpath is RTE 3, so that all seems fine. However, upon adding a LIMIT: select a from trigger_parted where pg_trigger_depth() <> a order by a limi= t 40; server closed the connection unexpectedly we arrive at make_partitionedrel_pruneinfo with partrelids equal to just (b 1); trigger_parted_p1 has been left out. The Path in this case has been made by generate_orderedappend_paths, which is what's responsible for computing AppendPath.partitioned_rels that eventually winds up as the argument to make_partitionedrel_pruneinfo. So I think that that code is somehow failing to account for nested partitioning, while the non-ordered-append code is doing it right. But I didn't spot exactly where the discrepancy is. regards, tom lane