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 1xM6Sw-00000001rHw-07tY for pgsql-bugs@arkaria.postgresql.org; Wed, 28 Oct 2026 16:25:30 +0000 Received: from localhost ([127.0.0.1]:37210 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xM6St-0000000HSGM-2fWF for pgsql-bugs@arkaria.postgresql.org; Wed, 28 Oct 2026 16:25:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:56080) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xM3L2-0000000GeG5-0ZHY for pgsql-bugs@lists.postgresql.org; Wed, 28 Oct 2026 13:05:08 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xM3Kz-00000001Q7W-45W4 for pgsql-bugs@lists.postgresql.org; Wed, 28 Oct 2026 13:05:07 +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=FljVF8QLQozKiXGWhi0na3DLF1n6prQq6cUvuZonPYw=; b=3DVF3C0K5yqw3LSySeKH7F3q1f bSNMPJaPNf/wPEsLIitWLfgQjTkjDQrHPbmb82g2d+k/k8EBp7JkVNlghwOiPo5n94HkQyzE3LfH8 ORifDzBXlaAGghu1CP84snlVbl87HUMfobnSKwZ8BMcdj1U8p1I7DUyHNy9+aIj5VtdKZ1ktisjWN lEN86P94CA7Zw4NxQkVWUoUO+mhLmcY7j6GcRpwtEaAA3/CTMzTnBfTXFg8jnH4u+TLwTN4dzREnq dSBNEDc2jVORsiIgMnMKiQd8RZj6obNQmJ2XS2q8+7rF3J02M31AigfQcmGNAnGATFtB4q1QVca1L qxE85Zmg==; 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 1xM3Ky-00000003w8w-3SYn for pgsql-bugs@lists.postgresql.org; Wed, 28 Oct 2026 13:05:04 +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 1xM3Kw-00000004LKE-2Q5W for pgsql-bugs@lists.postgresql.org; Wed, 28 Oct 2026 13:05:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19802: MERGE into a partitioned table fails with "SubPlan found with no parent plan" To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: gowthamdoma18@gmail.com Reply-To: gowthamdoma18@gmail.com, pgsql-bugs@lists.postgresql.org Date: Wed, 28 Oct 2026 13:04:38 +0000 Message-ID: <19802-ef50a8f1a4b5deee@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: 19802 Logged by: Gowtham Reddy Email address: gowthamdoma18@gmail.com PostgreSQL version: 18.6 Operating system: Ubuntu 22.04 (WSL2), x86_64 Description: =20 MERGE into a partitioned table fails with an internal error when the source is a subquery that is not pulled up, an UPDATE SET clause contains a scalar subquery that references the source, and the statement has both WHEN MATCHED UPDATE and WHEN NOT MATCHED INSERT: CREATE TABLE mp (a int, b text) PARTITION BY RANGE (a); CREATE TABLE mp1 PARTITION OF mp FOR VALUES FROM (0) TO (10); MERGE INTO mp t USING (SELECT true AS c OFFSET 0) s ON t.a IS NULL WHEN MATCHED THEN UPDATE SET b =3D (SELECT NULL WHERE s.c) WHEN NOT MATCHED THEN INSERT VALUES (1, 'x'); ERROR: SubPlan found with no parent plan Reproduced on 17.11, 18.6 and master (4848fd675, 2026-10-28). Each of these makes it succeed: a non-partitioned target table; dropping either the WHEN MATCHED UPDATE or the WHEN NOT MATCHED INSERT action (or using DO NOTHING instead of the INSERT); a join condition that references the source (ON true also works); a source that is pulled up (no OFFSET/LIMIT); the equivalent UPDATE ... FROM. The same message was fixed for a SELECT case on a partitioned table in eacee6b61 ("Don't use SubPlan-containing expressions for startup-time pruning"); that commit is in the tested master, so this MERGE case seems to take a different path. Found by a grammar-based SQL fuzzer (university course project); the script above is the hand-reduced test case.