pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Takeshi Ideriha <iderihatakeshi@gmail.com>
Cc: shihao zhong <zhong950419@gmail.com>
Cc: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Cc: alpkeles99@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19760: CLUSTER loses a row the transaction inserted and then updated in a rolled-back subtransaction
Date: Tue, 20 Oct 2026 16:41:49 +0900
Message-ID: <atcbPTfcO9rihmbD@paquier.xyz> (raw)
In-Reply-To: <949ad7b3-2b0e-40dc-b6ac-e84da432149b@gmail.com>
References: <19760-8f9a0eba17bc8c92@postgresql.org>
	<41175da6-293f-4b8f-ad18-3636f3d8a2f6@gmail.com>
	<CAJTYsWXQgkqEpecZK9MCFVV+504oOdueuenRf+xTfNf9BcKE-g@mail.gmail.com>
	<CAGRkXqRMvz-ZzC88_eXsyJZRpPXhE4_Fo6ueYdm5tpH+CHc6EQ@mail.gmail.com>
	<5fff280b-96c4-497f-bbfc-0af95b9844b3@gmail.com>
	<CAGRkXqSo9vZ=7mw_X0tjH1-Wwdz8nWu9xpdX1x8hVM8tCazKAA@mail.gmail.com>
	<949ad7b3-2b0e-40dc-b6ac-e84da432149b@gmail.com>

On Tue, Oct 20, 2026 at 11:32:44AM +0900, Takeshi Ideriha wrote:
> Regarding logical_rewrite_heap_tuple() part, you are completely right. I
> tested by myself yesterday and hit the same error while decoding the
> vacuum full scenario. Thank you for pointing out. I was not aware of DDL
> case with logical replication.

@@ -574,6 +576,14 @@ rewrite_heap_dead_tuple(RewriteState state, HeapTuple old_tuple)
 
 	if (unresolved != NULL)
 	{
+		/*
+		 * If the inserter of this tuple aborted, the update never happened
+		 * and the earlier tuple is not dead.  It will be written at the end.
+		 */
+		if (!HeapTupleHeaderXminCommitted(old_tuple->t_data) &&
+			!TransactionIdDidCommit(HeapTupleHeaderGetXmin(old_tuple->t_data)))
+			return false;

Having a recheck of the old tuple's state within
rewrite_heap_dead_tuple() feels very incorrect to me, based on the
bunch of comments at the top of rewriteheap.c.  It sounds to me that
rewrite_heap_dead_tuple() should be called when we know that the tuple
is dead, no?  Isn't heapam_relation_copy_for_cluster() the bit actually
incorrect here, marking the tuple with "isdead" to start with?  Your
solution of a recheck to make sure that an old tuple is actually dead
in a code path where an old tuple is assumed to be absolutely and
definitely dead looks like an API contract violation regarding
rewriteheap.c.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (30+ messages)  latest in thread

Message-ID: <atcbPTfcO9rihmbD@paquier.xyz>
Permalink:  ../atcbPTfcO9rihmbD@paquier.xyz/
Also on:    postgresql.org/message-id/atcbPTfcO9rihmbD@paquier.xyz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: michael@paquier.xyz, iderihatakeshi@gmail.com, zhong950419@gmail.com, ayushtiwari.slg01@gmail.com, alpkeles99@gmail.com
  Subject: Re: BUG #19760: CLUSTER loses a row the transaction inserted and then updated in a rolled-back subtransaction
  In-Reply-To: <atcbPTfcO9rihmbD@paquier.xyz>
  References: <19760-8f9a0eba17bc8c92@postgresql.org> <41175da6-293f-4b8f-ad18-3636f3d8a2f6@gmail.com> <CAJTYsWXQgkqEpecZK9MCFVV+504oOdueuenRf+xTfNf9BcKE-g@mail.gmail.com> <CAGRkXqRMvz-ZzC88_eXsyJZRpPXhE4_Fo6ueYdm5tpH+CHc6EQ@mail.gmail.com> <5fff280b-96c4-497f-bbfc-0af95b9844b3@gmail.com> <CAGRkXqSo9vZ=7mw_X0tjH1-Wwdz8nWu9xpdX1x8hVM8tCazKAA@mail.gmail.com> <949ad7b3-2b0e-40dc-b6ac-e84da432149b@gmail.com> <atcbPTfcO9rihmbD@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox