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 1k3NFP-0003fY-07 for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Aug 2020 17:30:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k3NFN-0002xd-RO for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Aug 2020 17:30:37 +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 1k3NFN-0002xW-KO for pgsql-hackers@lists.postgresql.org; Wed, 05 Aug 2020 17:30:37 +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 1k3NFK-0005ns-UY for pgsql-hackers@postgresql.org; Wed, 05 Aug 2020 17:30:36 +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 075HUURS2528808; Wed, 5 Aug 2020 13:30:31 -0400 From: Tom Lane To: Amit Langote cc: Justin Pryzby , Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: FailedAssertion("pd_idx == pinfo->nparts", File: "execPartition.c", Line: 1689) In-reply-to: References: <20200802181131.GA27754@telsasoft.com> <20200803161133.GA21372@telsasoft.com> Comments: In-reply-to Amit Langote message dated "Tue, 04 Aug 2020 20:12:10 +0900" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2528694.1596648446.0@sss.pgh.pa.us> Date: Wed, 05 Aug 2020 13:30:30 -0400 Message-ID: <2528807.1596648630@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2528694.1596648446.1@sss.pgh.pa.us> Amit Langote writes: > The crash reported here is in the other case where the concurrently > added partitions cause the execution-time PartitionDesc to have more > partitions than the one that PartitionedRelPruneInfo is based on. > I was able to reproduce such a crash as follows: Yeah, I can repeat the case per these directions. I concur that the issue is that ExecCreatePartitionPruneState is failing to cope with zeroes in the relid_map. > The attached patch should fix that. I don't like this patch at all though; I do not think it is being nearly careful enough to ensure that it's matched the surviving relation OIDs correctly. In particular it blithely assumes that a zero in relid_map *must* match the immediately next entry in partdesc->oids, which is easy to break if the new partition is adjacent to the one the planner managed to prune. So I think we should do it more like the attached. I'm strongly tempted to convert the trailing Assert to an actual test-and-elog, too, but didn't do so here. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="fix-sloppy-partition-mapping-2.patch"; charset="us-ascii" Content-ID: <2528694.1596648446.2@sss.pgh.pa.us> Content-Description: fix-sloppy-partition-mapping-2.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/e= xecPartition.c index fb6ce49056..221a34e738 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -1673,7 +1673,19 @@ ExecCreatePartitionPruneState(PlanState *planstate, pprune->subpart_map =3D palloc(sizeof(int) * partdesc->nparts); for (pp_idx =3D 0; pp_idx < partdesc->nparts; ++pp_idx) { - if (pinfo->relid_map[pd_idx] !=3D partdesc->oids[pp_idx]) + /* + * pinfo->relid_map can contain InvalidOid entries for + * partitions pruned by the planner. We cannot tell + * exactly which of the partdesc entries these correspond + * to, but we don't have to; just skip over them. The + * non-pruned relid_map entries, however, had better be a + * subset of the partdesc entries and in the same order. + */ + while (pd_idx < pinfo->nparts && + !OidIsValid(pinfo->relid_map[pd_idx])) + pd_idx++; + if (pd_idx >=3D pinfo->nparts || + pinfo->relid_map[pd_idx] !=3D partdesc->oids[pp_idx]) { pprune->subplan_map[pp_idx] =3D -1; pprune->subpart_map[pp_idx] =3D -1; @@ -1686,6 +1698,14 @@ ExecCreatePartitionPruneState(PlanState *planstate, pinfo->subpart_map[pd_idx++]; } } + + /* + * It might seem that we need to skip any trailing InvalidOid + * entries in pinfo->relid_map before asserting that we + * scanned all of the relid_map. But we will have skipped + * them above, because they must correspond to some + * partdesc->oids entries; we just couldn't tell which. + */ Assert(pd_idx =3D=3D pinfo->nparts); } = ------- =_aaaaaaaaaa0--