| From: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Reorderbuffer: handle catalog-change-bearing aborted subxacts be |
| Date: | 2026-10-14 17:52:57 |
| Message-ID: | E1xH39t-00000001cZI-2tS8@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Reorderbuffer: handle catalog-change-bearing aborted subxacts better
When constructing a historic snapshot for logical decoding,
reorderbuffer needs to keep track of movement of tuples in catalog
tables. For the most part this works correctly, except that when a
subtransaction that wrote a catalog tuple aborts, we failed to "forget"
about that change. There's no known reports of anything actually
breaking except assertion failures, but it is likely possible to
construct cases where historical snapshots produce bogus visibility
answers, potentially causing incorrect decoding output.
To fix, have the decode of a subtransaction abort go over the TUPLECID
list that has been accumulated on the ReorderBufferTXN for its topmost
parent transaction, and remove all the entries that were marked as
originating from the aborted subtransaction or its children. There are
some little details in which various devils lie, which the added code
comments explain (we hope).
Add a couple of isolation test cases that trip the assertions with the
original coding. They're not ideal test design, because they pass in
non-assert builds without the fix. But we'd rather have the fix be
verified in that limited scenario than nowhere at all, and they are
cheap enough.
This bug is sibling to the one fixed in commit 8c67d29fd51c and, like
that one, it goes all the way back to the introduction of
reorderbuffers, so backpatch to all live branches.
While reviewing this, I (Álvaro) was bothered by the snapmgr.c
tuplecid_data file-scoped variable, as it's easily confused with a
function parameter used widely in reorderbuffer.c. In branches 19 and
master, rename that to avoid confusion.
Reported-by: Arseny Sher <a(dot)sher(at)postgrespro(dot)ru>
Reported-by: Mark Dilger <mark(dot)dilger(at)enterprisedb(dot)com>
Reported-by: Alexander Kozhemyakin <a(dot)kozhemyakin(at)postgrespro(dot)ru>
Author: Bingshuai Li <lucian1412(at)outlook(dot)com>
Author: Hayato Kuroda <kuroda(dot)hayato(at)fujitsu(dot)com>
Author: Zhijie Hou <houzhijie22(at)gmail(dot)com>
Backpatch-through: 14
Bug: #19555
Discussion: https://postgr.es/m/87r2c8xocq.fsf@ars-thinkpad
Discussion: https://postgr.es/m/CAHgHdKu5e3XY5e90Tuaxq_R4WrKxSV734Q%2BLwo5y39Omp2A-Gg@mail.gmail.com
Discussion: https://postgr.es/m/19555-3c700f40a13045cd@postgresql.org
Branch
------
REL_17_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/624bd2b1fc0c9750c28a55b436e17b109b72d701
Modified Files
--------------
contrib/test_decoding/Makefile | 3 +-
contrib/test_decoding/expected/tuplecid_nested.out | 32 ++++++
.../test_decoding/expected/tuplecid_restart.out | 68 ++++++++++++
contrib/test_decoding/meson.build | 2 +
contrib/test_decoding/specs/tuplecid_nested.spec | 77 +++++++++++++
contrib/test_decoding/specs/tuplecid_restart.spec | 74 +++++++++++++
src/backend/replication/logical/decode.c | 11 +-
src/backend/replication/logical/reorderbuffer.c | 119 ++++++++++++++++++++-
src/backend/replication/logical/snapbuild.c | 2 +-
src/include/replication/reorderbuffer.h | 14 ++-
10 files changed, 393 insertions(+), 9 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-10-14 18:01:04 | pgsql: Doc: improve documentation of the JSON object aggregates. |
| Previous Message | Tom Lane | 2026-10-14 17:30:32 | pgsql: Fix jsonb_object_agg() and related aggs used as window functions |