| From: | Zhijie Hou <houzhijie22(at)gmail(dot)com> |
|---|---|
| To: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: update_deleted lookup assumes heap tuple slots |
| Date: | 2026-12-01 05:41:15 |
| Message-ID: | b2ef1d61-d94d-46ba-ac2a-291b18a15f0a@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Mon, Nov30, 2026 at 01:04 PM Amit Kapila wrote:
> On Sat, Nov 28, 2026 at 10:02 PM Andrew Dunstan <andrew(at)dunslane(dot)net> 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)?
+1
Also, it might be better to do this check early in
FindDeletedTupleInLocalRel() (with an Assert in execReplication.c if
needed) so that we can avoid unnecessary preparation before scanning for
dead tuples.
--
Best Regards,
Zhijie Hou
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Smith | 2026-12-01 05:47:06 | Re: [PATCH] Report changes discarded for relations not in the subscription |
| Previous Message | Shlok Kyal | 2026-12-01 05:32:36 | Re: Preserve conflict log table during upgrade |