From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: gowthamdoma18@gmail.com
Subject: BUG #19802: MERGE into a partitioned table fails with "SubPlan found with no parent plan"
Date: Wed, 28 Oct 2026 13:04:38 +0000
Message-ID: <19802-ef50a8f1a4b5deee@postgresql.org> (raw)
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:
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 = (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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, gowthamdoma18@gmail.com
Subject: Re: BUG #19802: MERGE into a partitioned table fails with "SubPlan found with no parent plan"
In-Reply-To: <19802-ef50a8f1a4b5deee@postgresql.org>
References: <19802-ef50a8f1a4b5deee@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox