From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix stale source values in MERGE after a concurrent update.
Date: Sat, 21 Nov 2026 12:17:58 +0000
Message-ID: <E1xUk2X-00000000dKR-3e2g@gemulon.postgresql.org> (raw)
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: https://postgr.es/m/19912-ceea4a1c0a7dd41c%40postgresql.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(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: dean.a.rasheed@gmail.com
Subject: Re: pgsql: Fix stale source values in MERGE after a concurrent update.
In-Reply-To: <E1xUk2X-00000000dKR-3e2g@gemulon.postgresql.org>
References: <E1xUk2X-00000000dKR-3e2g@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox