From: alvherre@kurilemu.de <alvherre@kurilemu.de>
To: Bingshuai Li <lucian1412@outlook.com>
Cc: Zhijie Hou <houzhijie22@gmail.com>
Cc: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alexander Lakhin <exclusion@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
Cc: mark.dilger@enterprisedb.com <mark.dilger@enterprisedb.com>
Cc: Amit Kapila <amit.kapila16@gmail.com>
Cc: Masahiko Sawada <sawada.mshk@gmail.com>
Cc: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Cc: a.kozhemyakin@postgrespro.ru <a.kozhemyakin@postgrespro.ru>
Subject: Re: Bug in logical decoding with DDL and subtransactions
Date: Wed, 14 Oct 2026 20:04:27 +0200
Message-ID: <as_BgS7Mcqe7mZdy@alvherre.pgsql> (raw)
In-Reply-To: <ME0P300MB0953ED3D18EC0A67B765540FC69D2@ME0P300MB0953.AUSP300.PROD.OUTLOOK.COM>
Hello,
Many thanks for the reviews. I have pushed this to all branches.
On 2026-Oct-14, Bingshuai Li wrote:
> Agreed on the guard (+1); for the record, I reproduced the cfbot
> failure locally on master 36a56229765c plus v8 with the same sanitizer
> flags -- the stream test loses its backend and the one-line return
> makes the test_decoding and isolation cases pass.
Right.
> One correction on the comment, though, in the "not known to be a
> subxact" paragraph: I don't think "there cannot possibly be TUPLECIDs
> to clean up" holds. The NEW_CID gate is on the snapshot state, but
> the association needed by this abort cleanup is established when the
> subxact's first WAL record carrying its toplevel XID is replayed
> (LogicalDecodingProcessRecord -> ReorderBufferAssignChild). After a
> restart, a saved CONSISTENT snapshot can be restored at a checkpoint
> past that record; later NEW_CID records still pass the FULL_SNAPSHOT
> gate. The subxact then gets an entry via ReorderBufferProcessXid with
> no association, while its TUPLECIDs are queued on the toplevel. That
> is the state I reported upthread (entry present, not a known subxact,
> tuplecids on the toplevel; the toplevel commit skipped).
>
> For this unassociated-subxact case, the early return need not mean an
> empty list. If the toplevel commits, that commit was already consumed
> before start_decoding_at; SnapBuildXactNeedsSkip() skips it and
> ReorderBufferForget() frees the list, never reaching the tuplecid hash
> -- as Zhijie's v7 comment had it. If the toplevel aborts,
> ReorderBufferAbort() frees the list.
> The existing parenthetical already covers the top-level abort case.
> Minimal suggestion for that paragraph:
>
> * We return without cleanup if the aborting subxact is not known to
> * this reorderbuffer. It may still have TUPLECIDs queued on the
> * toplevel if this snapbuild missed its first WAL record carrying
> * the toplevel XID. A commit that could use them was already
> * consumed: SnapBuildXactNeedsSkip() skips it and ReorderBufferForget()
> * frees the list. A toplevel abort frees it via ReorderBufferAbort().
Okay, I adopted this, but made still more changes to it, mostly because
I don't think we care very much about the memory freeing; we're mostly
concerned with whether the catalog tuple processing is correct. But I
also changed how we talk about the subxact being "unknown" -- I mean,
it's not that it's really unknown; as I understand it, the problem is
that we don't know that the parent is the parent. I also think that
talking about SnapBuildXactNeedsSkip() is a bit indirect, so I mentioned
DecodeCommit instead.
There's quite a bit of abstraction leakage in this whole thing, which is
probably unavoidable. I mean the relationship between reorderbuffer.c
and decode.c and snapbuild.c. It's probably not surprising that this
patch had to touch all three. So I don't feel bad that the comment in
reorderbuffer.c needs to mention the function in decode.c.
BTW you mention Zhijie's v7, but I think that comment mostly comes from
your version just prior to that ...
> Also, in the inner comment, the clause "or that we entered FULL_SNAPSHOT
> after the subxid was assigned as a child" doesn't work as an
> explanation for finding no entry at all: ReorderBufferProcessXid creates
> the entry before the snapshot-state gate, and a later transition to
> FULL_SNAPSHOT does not itself remove it. Dropping that clause (as in
> v8's wording) reads correct to me.
Okay, done that way.
> And thanks for the terminology fixes; "decoding pass" was indeed not
> the codebase's language.
Many thanks for double-checking.
Feel free to propose more wording changes to these comments if something
is still wrong. At least I think we're better than when we started ...
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
Officer Krupke, what are we to do?
Gee, officer Krupke, Krup you! (West Side Story, "Gee, Officer Krupke")
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-hackers@postgresql.org
Cc: alvherre@kurilemu.de, lucian1412@outlook.com, houzhijie22@gmail.com, kuroda.hayato@fujitsu.com, michael@paquier.xyz, tgl@sss.pgh.pa.us, exclusion@gmail.com, mark.dilger@enterprisedb.com, amit.kapila16@gmail.com, sawada.mshk@gmail.com, pl0h0yp1@gmail.com, a.kozhemyakin@postgrespro.ru
Subject: Re: Bug in logical decoding with DDL and subtransactions
In-Reply-To: <as_BgS7Mcqe7mZdy@alvherre.pgsql>
References: <ME0P300MB0953ED3D18EC0A67B765540FC69D2@ME0P300MB0953.AUSP300.PROD.OUTLOOK.COM> <as_BgS7Mcqe7mZdy@alvherre.pgsql>
* 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