From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix cross-partition source values in MERGE after a concurrent up
Date: Mon, 23 Nov 2026 12:21:01 +0000
Message-ID: <E1xVT2b-000000001Fh-20Wy@gemulon.postgresql.org> (raw)
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 <tndrwang@gmail.com>
Author: Tender Wang <tndrwang@gmail.com>
Author: Dean Rasheed <dean.a.rasheed@gmail.com>
Discussion: https://postgr.es/m/CAHewXNkZb5rBnen7ALsXX3d5JgdpzUjsNY9pqbxub3N-%2BNb%3DyQ%40mail.gmail.com
Backpatch-through: 17
Branch
------
REL_17_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/a95dcec5dc0b54b20b606fce021c6e6cffd0adbc
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(-)
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 cross-partition source values in MERGE after a concurrent up
In-Reply-To: <E1xVT2b-000000001Fh-20Wy@gemulon.postgresql.org>
References: <E1xVT2b-000000001Fh-20Wy@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