Re: Inconsistent update in the MERGE command
Chao Li <li.evan.chao@gmail.com>
From: Chao Li <li.evan.chao@gmail.com>
To: Yugo Nagata <nagata@sraoss.co.jp>
Cc: Dmitry <dsy.075@yandex.ru>,
pgsql-hackers@lists.postgresql.org
Date: 2025-08-28T03:13:49Z
Lists: pgsql-hackers
> On Aug 25, 2025, at 01:34, Yugo Nagata <nagata@sraoss.co.jp> wrote:
>
> Currently, TM_FailureData.ctid is used as a reference to the
> latest version of oldtuple, but this is not always correct.
> Instead, the tupleid passed to table_tuple_lock should be used.
Based on my understanding:
At line 3386:
result = table_tuple_lock(resultRelationDesc, tupleid,
estate->es_snapshot,
inputslot, estate->es_output_cid,
lockmode, LockWaitBlock,
TUPLE_LOCK_FLAG_FIND_LAST_VERSION,
&context->tmfd);
When calling table_tuple_lock(), “tupleid” is used to lock the tuple, and “&context->tmfd” is used to carry out lasted version of tuple info if table_tuple_lock() fails.
In this case, at line 3394, it drops into:
switch (result)
{
case TM_Ok:
Result is TM_Ok, meaning table_tuple_lock() didn’t fail, then we should not use info from “context->tmfd”.
So I think this fix makes sense.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Commits
-
Fix concurrent update issue with MERGE.
- f871fbae9d00 15.15 landed
- 21a61b87f47b 16.11 landed
- 6195afbe536a 17.7 landed
- c70b6db34ffe 18.0 landed
- 6ede13d1b5f5 19 (unreleased) landed