Re: Inconsistent update in the MERGE command - Mailing list pgsql-hackers

From Chao Li
Subject Re: Inconsistent update in the MERGE command
Date
Msg-id 9CBB705C-7AC9-4724-9CB3-E5C09AB69ECF@gmail.com
Whole thread Raw
In response to Re: Inconsistent update in the MERGE command  (Yugo Nagata <nagata@sraoss.co.jp>)
List 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/




pgsql-hackers by date:

Previous
From: "Hayato Kuroda (Fujitsu)"
Date:
Subject: RE: POC: enable logical decoding when wal_level = 'replica' without a server restart
Next
From: jian he
Date:
Subject: Re: Fix ALTER TABLE DROP EXPRESSION with inheritance hierarchy