pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix broken HOT chain handling in parallel BRIN builds
Date: Tue, 24 Nov 2026 23:27:31 +0000
Message-ID: <E1xVzv8-00000000C7R-3yt3@gemulon.postgresql.org> (raw)

Fix broken HOT chain handling in parallel BRIN builds

When a non-concurrent index build encounters a RECENTLY_DEAD tuple that
was HOT-updated, heapam_index_build_range_scan() skips it, indexing only
the live tuple at the end of the HOT chain, and sets ii_BrokenHotChain.
index_build() then marks the index with indcheckxmin, so that
transactions with a snapshot older than index creation don't use the
index, as it may be missing tuple versions still visible to them.

In parallel index builds this requires each worker to report back to the
leader whether it encountered a broken HOT chain. btree correctly does
this, but BRIN parallel index builds did not. As a result, indcheckxmin
was never set, and a transaction holding an older snapshot could use the
new index and get wrong results.

Fix by tracking the brokenhotchain flag in the shared state of the AM,
like btree does, and copying it back into the ambuild IndexInfo in the
leader after all participants are done.

Adds an isolation test with a REPEATABLE READ session counting the rows
of a table, while a second session HOT-updates every row and builds an
index with a parallel build, and the first session counts again.  A
parallel BRIN build without this fix leaves indcheckxmin false, so the
first session uses the index: its snapshot's rows are no longer found.

Oversight when parallel index builds were added for BRIN (b4375717147),
backpatch to 17.

Author: Lukas Fittl <lukas@fittl.com>
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAP53PkxEZPeT_G7u-1qF-%3DouBvMxUNka-bN7cJowkv7gms9uCg%40mail.gmail.com
Discussion: https://postgr.es/m/CAH2-Wz%3DUKBJ-f2oZpG8XJTnGbivmjM2nuyhw%2B5P3xBzeWmhSWw%40mail.gmail.com
Backpatch-through: 17

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7108530663d22f2daa0df0cf2ce944e958ec4478

Modified Files
--------------
src/backend/access/brin/brin.c                   | 33 +++++++---
src/test/isolation/expected/broken-hot-chain.out | 77 ++++++++++++++++++++++++
src/test/isolation/isolation_schedule            |  1 +
src/test/isolation/specs/broken-hot-chain.spec   | 62 +++++++++++++++++++
4 files changed, 164 insertions(+), 9 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1xVzv8-00000000C7R-3yt3@gemulon.postgresql.org>
Permalink:  ../E1xVzv8-00000000C7R-3yt3@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xVzv8-00000000C7R-3yt3@gemulon.postgresql.org

 · 

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-committers@postgresql.org
  Cc: tomas.vondra@postgresql.org
  Subject: Re: pgsql: Fix broken HOT chain handling in parallel BRIN builds
  In-Reply-To: <E1xVzv8-00000000C7R-3yt3@gemulon.postgresql.org>
  References: <E1xVzv8-00000000C7R-3yt3@gemulon.postgresql.org>

* 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