From 26bf0d5a1aa1017139f04386278f40d7a98cc145 Mon Sep 17 00:00:00 2001 From: Tender Wang Date: Thu, 29 Oct 2026 08:31:04 +0800 Subject: [PATCH] Fix MERGE into partitioned tables with SubPlans in UPDATE actions When tuple routing creates a ResultRelInfo for a partition during MERGE, ExecInitPartitionInfo() builds partition-specific state for each MERGE action. Unlike the corresponding code in ExecInitMerge(), it passed a NULL parent PlanState when building an UPDATE projection. This fails if the UPDATE target list contains a SubPlan, because ExecInitSubPlanExpr() needs the parent PlanState to initialize the SubPlan and attach its state to the parent's subPlan list, resulting in the error "SubPlan found with no parent plan". Pass the ModifyTableState's PlanState to ExecBuildUpdateProjection(), as ExecInitMerge() already does. --- src/backend/executor/execPartition.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c index 4ec69f2bf99..a7ec585763e 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -1069,7 +1069,7 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, EState *estate, RelationGetDescr(leaf_part_rri->ri_RelationDesc), econtext, leaf_part_rri->ri_newTupleSlot, - NULL); + &mtstate->ps); break; case CMD_DELETE: case CMD_NOTHING: -- 2.43.0