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.98.2) (envelope-from ) id 1xHkf7-00000003HOx-05fC for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Oct 2026 16:20:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xHkf4-0000000FLJN-47dY for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Oct 2026 16:20:02 +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.98.2) (envelope-from ) id 1xHjnu-0000000F2c4-49t1 for pgsql-bugs@lists.postgresql.org; Fri, 16 Oct 2026 15:25:06 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xHjnt-00000002M4F-0wSv for pgsql-bugs@lists.postgresql.org; Fri, 16 Oct 2026 15:25:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=GTN1uzxXneTz8ShqlfQwQispKComDKFpDEXN8z6gGIA=; b=WK6AGhS0U/PA7NrcVUGpC0DODN 1lay3ooDYJwSiJQU6s7AxC06Jo7IakGf2L3RO5YgzSOWG7aX8waYU4lWSCarLJojRI10QeHwgm6B4 08OygpFYLA0T9hcELFztK1X0RcSRazPlDKuysz1YfRAJ4Vg0oXk43WDHYKqXu204mFHuRWAMqbGNL r2JKt93VXeL84JQsZMq5+r/1EYhucPQ7q27gsmBRTRCUUJtqd3zRkYGxzs8915bW97MD59c5W3LS1 vAjIS1M5rHQu43V3JFPSZr3S1Dk+0oBGpUgbDuXraLK0IFaw7HnaUlhxArWrszz3Q3wLwhv6ga2Pl j/oP8yFg==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xHjnt-00000006naA-00bM for pgsql-bugs@lists.postgresql.org; Fri, 16 Oct 2026 15:25:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xHjnr-00000003Ikl-2WXe for pgsql-bugs@lists.postgresql.org; Fri, 16 Oct 2026 15:25:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19766: Assert in shm_toc_insert: EXPLAIN ANALYZE of a SubPlan shared by Parallel Append children To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: alpkeles99@gmail.com Reply-To: alpkeles99@gmail.com, pgsql-bugs@lists.postgresql.org Date: Fri, 16 Oct 2026 15:24:16 +0000 Message-ID: <19766-c3d105a4e0ec5487@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19766 Logged by: Alperen Keles Email address: alpkeles99@gmail.com PostgreSQL version: 19rc1 Operating system: Ubuntu 24.04 x86_64 (also macOS 26 arm64) Description: =20 Hello, On an assert-enabled master, this crashes the backend with default settings and empty tables: CREATE TABLE p (a int) PARTITION BY LIST (a); CREATE TABLE p1 PARTITION OF p FOR VALUES IN (1); CREATE TABLE p2 PARTITION OF p FOR VALUES IN (2); CREATE TABLE s (b int); EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT * FROM p WHERE a NOT IN (SELECT 1 FROM s, s s2); TRAP: failed Assert("toc->toc_entry[i].key !=3D key"), File: "shm_toc.c", Line: 190 shm_toc_insert ExecMaterialInitializeDSM nodeMaterial.c:440 ExecParallelInitializeDSM execParallel.c:596 planstate_walk_subplans nodeFuncs.c:4838 planstate_walk_members planstate_tree_walker_impl (the Parallel Append) ExecParallelInitializeDSM execParallel.c:602 ExecInitParallelPlan ExecGather The query without ANALYZE runs normally. The plan is Gather -> Parallel Append -> two Parallel Seq Scans, each with the filter "NOT (ANY (a =3D (SubPlan any_1).col1))"; the SubPlan is Materialize -> Nested Loop -> (Seq Scan, Materialize -> Seq Scan). The SubPlan referenced by both partitions' quals has a single PlanState, but planstate_tree_walker() visits the subPlan list of each child, so ExecParallelInitializeDSM() reaches the SubPlan's nodes once per partition and inserts the same plan_node_id into the TOC twice. Since a241bc4fede ("Show Material node Maximum Storage for parallel workers") Material is one of the nodes that put an entry there, which makes this reachable with default settings. The double visit itself is older. On REL_19_STABLE (19rc1), and on a241bc4fede's parent, the same assertion fails when the shared SubPlan contains another node with parallel instrumentation, with the same tables: EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT * FROM p WHERE a > ALL (SELECT b FROM s ORDER BY b, b + 1); -> TRAP ... in ExecSortInitializeDSM EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT * FROM p WHERE a > ALL (SELECT b FROM s GROUP BY b); -> TRAP ... in ExecAggInitializeDSM (On REL_19_STABLE the failing assertion reads Assert("vtoc->toc_entry[i].key !=3D key"), shm_toc.c:193.) I got it from ExecHashInitializeDSM, ExecMemoizeInitializeDSM and ExecIncrementalSortInitializeDSM in the same way. The duplicate-key assertion is 43222b8e53f, so REL_18_STABLE and older don't trap. Versions tested (Ubuntu 24.04, x86_64, gcc 13.3, --enable-cassert --enable-debug, CFLAGS=3D-O2, dynamic_shared_memory_type =3D mmap; builds from 2026-10-16): - master a261fc2b722: all three queries crash (the first one also on macOS 26 arm64, master 158b6d5109f) - a241bc4fede: the first query crashes; its parent c6b8af429b3 runs it but crashes on the other two - REL_19_STABLE 1212d5d33b1 (19rc1): the first query runs, the other two crash - REL_18_STABLE dfbc1507cdb (18.6), REL_14_STABLE 14904052e65 (14.24): no crash Found with a query fuzzer. Regards, Alperen Keles