From: Manu <manuelreyesbravo@gmail.com>
To: Zhijie Hou <houzhijie22@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: shihao zhong <zhong950419@gmail.com>
Cc: Takeshi Ideriha <iderihatakeshi@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: Sun, 25 Oct 2026 19:58:16 -0300
Message-ID: <179296909690.2912611.12132607274884942288@gmail.com> (raw)
In-Reply-To: <CAFvd2n-pPQvqTfbGKArgEKUfi3fAHq56EVpy6xXByx-SUKHn_g@mail.gmail.com>
References: <CAFvd2n-pPQvqTfbGKArgEKUfi3fAHq56EVpy6xXByx-SUKHn_g@mail.gmail.com>
Hi Zhijie,
On Sun, Oct 25, 2026 at 4:31 PM Zhijie Hou <houzhijie22@gmail.com>
wrote:
> This doesn't look safe to me. Even if TransactionIdDidAbort() returns true, the
> xmax may not have been removed from PGPROC yet. So this change would create the
> risky case where the old tuple has been marked as XMAX_INVAL while the new
> tuple's xmin is still considered in progress.
You're right. On master dfd7ede529f with v2 and nocfbot-0001, your
test fails in 3 of 3 runs once nocfbot-0002 is added ("failed to find
parent tuple for heap-only tuple at (0,3)"), and passes in 4 of 4
without it.
I took the order in RecordTransactionAbort() (clog first, proc array
later) as the reason the clog alone was enough, but that order is
what opens the window: until ProcArrayEndTransaction() runs, the new
version of the tuple, whose xmin is that xmax, is still in progress,
which is the race the note at the top of heapam_visibility.c is
about.
So the clog can only be a filter there. The attached diff replaces
nocfbot-0002: it keeps TransactionIdDidAbort(xmax) first and then
confirms with !TransactionIdIsInProgress(xmax) before setting the
hint. It passes your test in 4 of 4 runs, shihao's spec, cases 1-3,
5 and 7-11 from measurements.txt, and make check, the isolation suite,
injection_points and test_decoding.
It keeps what made nocfbot-0002 cheap in subxact_updates.sql. There
xmax is a released subtransaction that is still running, so it is
not aborted in the clog and the proc array is never asked. One
VACUUM makes the same SLRU accesses as with the old nocfbot-0002:
999937 clog and 999872 subtrans, against 999873 and 1999744 with
nocfbot-0001 alone. When xmax did abort, it pays both lookups until
the hint is set. I have not re-timed it.
nocfbot-0001 alone (your xmin != xmax idea plus the MULTI skip) is
unchanged and passes your test in 4 of 4 runs.
Thanks for the repro.
Regards,
Manu
Attachments:nocfbot-0002-fixed-abort-check-on-v2.diff.txt (text/plain, 1.3K) download
Applies on top of v2 and nocfbot-0001. Not for the CF bot.
Replaces nocfbot-0002 from 2026-10-22: the clog is only a filter, the
proc array still confirms the abort before the hint is set.
diff --git a/src/backend/access/heap/heapam_visibility.c b/src/backend/access/heap/heapam_visibility.c--- a/src/backend/access/heap/heapam_visibility.c+++ b/src/backend/access/heap/heapam_visibility.c@@ -1197,10 +1197,18 @@ HeapTupleSatisfiesVacuumHorizon(HeapTupl
{
TransactionId xmax = HeapTupleHeaderGetUpdateXid(tuple);
- /* xmax == xmin: xmax is in progress too, nothing to do */+ /*+ * xmax == xmin: xmax is in progress too, nothing to do.+ * The clog is only a cheap filter here: a running xmax is not+ * aborted there. An abort reaches the clog before the xid+ * leaves the proc array, and the new version of the tuple,+ * whose xmin is this xmax, is in progress until then. So the+ * proc array must confirm it, as the note at the top of this+ * file asks.+ */
if (!TransactionIdEquals(xmax, HeapTupleHeaderGetRawXmin(tuple)) &&
- !TransactionIdIsInProgress(xmax) &&- !TransactionIdDidCommit(xmax))+ TransactionIdDidAbort(xmax) &&+ !TransactionIdIsInProgress(xmax))
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
InvalidTransactionId);
}
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: manuelreyesbravo@gmail.com, houzhijie22@gmail.com, michael@paquier.xyz, zhong950419@gmail.com, iderihatakeshi@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: <179296909690.2912611.12132607274884942288@gmail.com>
References: <CAFvd2n-pPQvqTfbGKArgEKUfi3fAHq56EVpy6xXByx-SUKHn_g@mail.gmail.com> <179296909690.2912611.12132607274884942288@gmail.com>
* 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