Re: Avoid using raw xmin of frozen tuples in logicalrep conflict detection

From: Zhijie Hou <houzhijie22(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Subject: Re: Avoid using raw xmin of frozen tuples in logicalrep conflict detection
Date: 2026-11-09 11:34:41
Message-ID: bee65802-a349-4e7b-8403-45adc98a1ca2@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Fri, Nov 6, 2026 at 12:13 PM Zhijie Hou wrote:
> Hi Andres,
>
> On Wed, Nov 4, 2026 at 09:33 PM Andres Freund wrote:
> > That surely is not the right fix, it breaks any sense of abstraction
> > across table AMs. There's afaict no guarantee that the target table
> > is heapam. And even if there currently is, we shouldn't bake that in
> > further.
>
> Thanks for pointing it out. I agree that conflict.c shouldn't be
> reaching into BufferHeapTupleTableSlot or HeapTupleHeaderGetXmin()
> directly.
>
> To avoid that, on master, it seems cleanest to handle this at the
> TupleTableSlotOps level (alongside getsysattr and
> is_current_xact_tuple in execTuples.c), for example, via an optional
> callback that returns the effective xmin (HeapTupleHeaderGetXmin() for
> heap/buffer-heap slots, and InvalidTransactionId when NULL for
> virtual/minimal slots or AMs that don't store tuple xmin).
>
> TransactionId (*get_effective_xmin) (TupleTableSlot *slot);

Following this, I am attaching two patches implementing the approaches
discussed above for reference:

v2-0001-Fix-logical-xx.patch adds an optional get_effective_xmin
callback to TupleTableSlotOps (alongside getsysattr and
is_current_xact_tuple). Heap and buffer-heap slots implement it via
HeapTupleHeaderGetXmin(), while slots that do not provide this
information leave the callback unset so slot_get_effective_xmin()
returns InvalidTransactionId.

nocfbot-v2-0001-Fix-logical-xx.patch avoids adding a new
TupleTableSlotOps callback (which is also needed for back-patching to
18) by checking TTS_IS_BUFFERTUPLE(localslot) ||
TTS_IS_HEAPTUPLE(localslot) in GetTupleTransactionInfo() to use
HeapTupleHeaderGetXmin(), and falling back to slot_getsysattr() for
other slot types.

What do you think ?

--
Best Regards,
Zhijie Hou

Attachment Content-Type Size
nocfbot-v2-0001-Fix-logical-replication-conflict-detection-on-fro-without-callback.patch text/plain 7.2 KB
v2-0001-Fix-logical-replication-conflict-detection-on-fro.patch text/plain 11.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Osama Abdul Qader 2026-11-09 11:42:40 Re: Avoid using raw xmin of frozen tuples in logicalrep conflict detection
Previous Message Kirill Reshke 2026-11-09 11:33:27 Re: Honor inherited ownership when finishing prepared transactions