Re: Inconsistent update in the MERGE command

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
Cc: Dmitry <dsy(dot)075(at)yandex(dot)ru>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Inconsistent update in the MERGE command
Date: 2025-08-28 03:13:49
Message-ID: 9CBB705C-7AC9-4724-9CB3-E5C09AB69ECF@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Aug 25, 2025, at 01:34, Yugo Nagata <nagata(at)sraoss(dot)co(dot)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/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2025-08-28 03:34:52 Re: Fix ALTER TABLE DROP EXPRESSION with inheritance hierarchy
Previous Message Hayato Kuroda (Fujitsu) 2025-08-28 02:45:03 RE: POC: enable logical decoding when wal_level = 'replica' without a server restart