BUG #19802: MERGE into a partitioned table fails with "SubPlan found with no parent plan"

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: gowthamdoma18(at)gmail(dot)com
Subject: BUG #19802: MERGE into a partitioned table fails with "SubPlan found with no parent plan"
Date: 2026-10-28 13:04:38
Message-ID: 19802-ef50a8f1a4b5deee@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19802
Logged by: Gowtham Reddy
Email address: gowthamdoma18(at)gmail(dot)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.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2026-10-28 13:06:17 BUG #19803: Assertion "!parallel_aware || pathnode->path.parallel_safe" in create_append_path
Previous Message Matheus Alcantara 2026-10-28 12:26:38 Re: BUG #19752: GROUP BY on a constant and a cast to a length-limited array type crashes the server while planning