Fix MERGE into partitioned table with subquery in UPDATE targetlist.

Under some circumstances, a MERGE into a partitioned table with an
UPDATE action with a subquery in its targetlist would fail with a
"SubPlan found with no parent plan" error.

This was due to ExecInitPartitionInfo() passing a NULL parent
PlanState to ExecBuildUpdateProjection() for the MERGE UPDATE action's
targetlist. Fix by passing &mtstate->ps, like ExecInitMerge().

Backpatch to v15, where MERGE was introduced.

Bug: #19802
Reported-by: Gowtham Reddy <[email protected]>
Author: Tender Wang <[email protected]>
Reviewed-by: Dilip Kumar <[email protected]>
Discussion: https://postgr.es/m/19802-ef50a8f1a4b5deee%40postgresql.org
Backpatch-through: 15

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/291a641ab77ea41fe83c141d1cbb865f2b32d5de

Modified Files
--------------
src/backend/executor/execPartition.c |  2 +-
src/test/regress/expected/merge.out  | 15 +++++++++++++++
src/test/regress/sql/merge.sql       | 11 +++++++++++
3 files changed, 27 insertions(+), 1 deletion(-)

Reply via email to