pgsql: Fix stale source values in MERGE after a concurrent update.
Fix stale source values in MERGE after a concurrent update.
When a MERGE has WHEN NOT MATCHED BY SOURCE actions and an initially
matched target row is concurrently updated so that it no longer
satisfies the join condition, causing a WHEN NOT MATCHED BY SOURCE
action to be executed, the RETURNING list was incorrectly evaluated
using the original non-NULL source values. All source values returned
by a WHEN NOT MATCHED BY SOURCE action should be NULL.
Fix in ExecMergeMatched(), when we transition from MATCHED to NOT
MATCHED BY SOURCE after a concurrent update, by building a new
all-NULL slot for use in the RETURNING projection.
Backpatch to v17, where WHEN NOT MATCHED BY SOURCE support was added
to MERGE.
Bug: #19912
Reported-by: Chunling Qin <303677365@qq.com>
Author: Tender Wang <tndrwang@gmail.com>
Author: Dean Rasheed <dean.a.rasheed@gmail.com>
Discussion: /messages/by-id/19912-ceea4a1c0a7dd41c@postgresql.org
Backpatch-through: 17
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/b291954ea5a4855ded56c334859d7de9fea372eb
Modified Files
--------------
src/backend/executor/nodeModifyTable.c | 37 ++++++-
src/test/isolation/expected/merge-not-matched.out | 113 ++++++++++++++++++++++
src/test/isolation/isolation_schedule | 1 +
src/test/isolation/specs/merge-not-matched.spec | 49 ++++++++++
4 files changed, 197 insertions(+), 3 deletions(-)