pgsql: Fix stale source values in MERGE after a concurrent update.

Started by Dean Rasheed1 day ago1 messagescommitters
Jump to latest
#1Dean Rasheed
dean.a.rasheed@gmail.com

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
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9cd821c6532e900cae1b2d2675a3d3c774c38216

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(-)