Fix cross-partition source values in MERGE after a concurrent update. Follow-up to commit b291954ea5a. When a concurrent update causes MERGE to switch from a WHEN MATCHED action to a WHEN NOT MATCHED BY SOURCE action, any source values returned should be NULL, not the source values from the originally matched tuple.
Commit b291954ea5a attempted to ensure this by building a new all-NULL slot for use in the RETURNING projection, when ExecMergeMatched() transitions from WHEN MATCHED to WHEN NOT MATCHED BY SOURCE after a concurrent update. However, this overlooked the code path taken for a cross-partition update, which executes ExecProcessReturning() from ExecInsert() rather than directly from ExecMergeMatched(). Fix by temporarily replacing the ModifyTableContext planSlot with the new all-NULL slot while the WHEN NOT MATCHED BY SOURCE action is executed, so that the correct NULL source values are seen by all code executed as part of the action. Backpatch to v17, where WHEN NOT MATCHED BY SOURCE support was added to MERGE. Reported-by: Tender Wang <[email protected]> Author: Tender Wang <[email protected]> Author: Dean Rasheed <[email protected]> Discussion: https://postgr.es/m/CAHewXNkZb5rBnen7ALsXX3d5JgdpzUjsNY9pqbxub3N-%2BNb%3DyQ%40mail.gmail.com Backpatch-through: 17 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/19db7e5b36e33c80a032e0e811176ad3b115b0ca Modified Files -------------- src/backend/executor/nodeModifyTable.c | 29 +++--- src/test/isolation/expected/merge-not-matched.out | 112 ++++++++++++++++++++++ src/test/isolation/specs/merge-not-matched.spec | 38 +++++++- 3 files changed, 163 insertions(+), 16 deletions(-)
