On Sat, Nov 28, 2026 at 10:02 PM Andrew Dunstan <[email protected]> wrote:
>
> The update_deleted detection in [1] makes an apply worker that can't find
> the row a remote UPDATE changes go looking for a recently deleted one, if
> the subscription has retain_dead_tuples. The lookup scans with SnapshotAny
> and hands each tuple to update_most_recent_deletion_info(), which casts the
> slot to a BufferHeapTupleTableSlot, locks its buffer and calls
> HeapTupleSatisfiesVacuum() on the heap header. That only makes sense for
> heap. Everything before it goes through table_slot_create(), so a table
> using another AM gets that far with a buffer number and a header that
> aren't there.
>
> I ran into this with a table AM I'm working on. With a subscriber table in
> that AM, retain_dead_tuples on, and a row deleted on the subscriber that
> the publisher then updates, an assert build of the apply worker dies once
> the conflict slot has an xmin:
>
> TRAP: failed Assert("bufnum <= NBuffers"), File: "bufmgr.h"
> LockBuffer
> update_most_recent_deletion_info
> RelationFindDeletedTupleInfoByIndex
> ...
>
> Without assertions it locks some arbitrary buffer instead. Core only has
> heap, so I can't offer a reproducer and there's no test for the new
> behaviour. 035_conflicts covers the heap path.
>
> I can see two ways to fix it, and I'd like to know which people prefer.
> They're posted as a series, but the second replaces the first rather than
> building on it.
>
> 0001 makes both lookup functions return "no deleted tuple" unless the
> relation's slots are buffer heap tuple slots. A remote UPDATE of a row
> that can't be found is then update_missing, as it was before update_deleted
> existed. It's small, and I think it should go back to 19, where
> retain_dead_tuples is already in. The weakness is that it asks about a
> slot type rather than the AM, and no other AM can ever get update_deleted.
>
+deleted_tuple_info_available(Relation rel)
+{
+ return table_slot_callbacks(rel) == &TTSOpsBufferHeapTuple;
+}
Is it better to use an AM check here like rel->rd_tableam ==
GetHeapamTableAmRoutine() (or rel->rd_rel->relam ==
HEAP_TABLE_AM_OID)?
> 0002 swaps that check for an optional TableAmRoutine callback,
> tuple_recently_deleted. Given a tuple fetched with SnapshotAny, it says
> whether the tuple was deleted by a transaction that isn't yet older than
> oldestxmin, and which one. heap implements it with the code that used to
> be in update_most_recent_deletion_info(), which is left with just picking
> the deletion with the latest commit timestamp.
>
If we want to go this route then is it better to get even the
localtimestamp and origin information as well? However, it is not
clear to me as to how non-heap AM's would detect such a conflict
because they may be retaining old versions in undo LOG instead of heap
or in some other way such that SnapshotAny won't be able to find
recently-deleted rows. I feel it is probably better to
extend/introduce this API later once we have some examples showing how
one wants to use it.
--
With Regards,
Amit Kapila.