| From: | Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Fix broken HOT chain handling in parallel GIN builds |
| Date: | 2026-11-24 23:27:41 |
| Message-ID: | E1xVzvI-00000000C8X-3wJ5@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Fix broken HOT chain handling in parallel GIN 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 GIN 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 GIN build without this fix leaves indcheckxmin false, so the
first session uses the index: its snapshot's rows are no longer found,
and a search for the new value returns them instead.
Oversight when parallel index builds were added for GIN (8492feb98f6)
and backpatch to 18.
Author: Lukas Fittl <lukas(at)fittl(dot)com>
Reviewed-by: Tomas Vondra <tomas(at)vondra(dot)me>
Reviewed-by: Peter Geoghegan <pg(at)bowt(dot)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: 18
Branch
------
REL_18_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/88284218582cbe15b403839000d2d9ee39c75004
Modified Files
--------------
src/backend/access/gin/gininsert.c | 32 ++++++++++++++------
src/test/isolation/expected/broken-hot-chain.out | 38 ++++++++++++++++++++++++
src/test/isolation/specs/broken-hot-chain.spec | 5 ++++
3 files changed, 66 insertions(+), 9 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tomas Vondra | 2026-11-24 23:27:52 | pgsql: Clarify the parallel BRIN merge comment |
| Previous Message | Tomas Vondra | 2026-11-24 23:27:31 | pgsql: Correct the parallel GIN merge comment |