pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix broken HOT chain handling in parallel BRIN builds
7+ messages / 1 participants
[nested] [flat]

* pgsql: Fix broken HOT chain handling in parallel BRIN builds
@ 2026-11-24 23:27 Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Tomas Vondra @ 2026-11-24 23:27 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8cfc2bdf314d8600c3b67a6d8865ddb3dcd910a2

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(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix broken HOT chain handling in parallel GIN builds
@ 2026-11-24 23:27 Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Tomas Vondra @ 2026-11-24 23:27 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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@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: 18

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/bae27968b76d3b2b804e5ffb088181ed34b9b4c2

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(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix broken HOT chain handling in parallel BRIN builds
@ 2026-11-24 23:27 Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Tomas Vondra @ 2026-11-24 23:27 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix broken HOT chain handling in parallel GIN builds
@ 2026-11-24 23:27 Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Tomas Vondra @ 2026-11-24 23:27 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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@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: 18

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e96a8a8fc8ff1c0b5f731a17db7273fc483ff9b7

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(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix broken HOT chain handling in parallel BRIN builds
@ 2026-11-24 23:27 Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Tomas Vondra @ 2026-11-24 23:27 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/989a95a747309808b5c350fb5b74b4aaf96f26bb

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(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix broken HOT chain handling in parallel GIN builds
@ 2026-11-24 23:27 Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Tomas Vondra @ 2026-11-24 23:27 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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@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: 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(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix broken HOT chain handling in parallel BRIN builds
@ 2026-11-24 23:27 Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Tomas Vondra @ 2026-11-24 23:27 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1a570e363d72cbb138a7b53981f8038611fcb800

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(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2026-11-24 23:27 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 23:27 pgsql: Fix broken HOT chain handling in parallel BRIN builds Tomas Vondra <tomas.vondra@postgresql.org>
2026-11-24 23:27 pgsql: Fix broken HOT chain handling in parallel GIN builds Tomas Vondra <tomas.vondra@postgresql.org>
2026-11-24 23:27 pgsql: Fix broken HOT chain handling in parallel BRIN builds Tomas Vondra <tomas.vondra@postgresql.org>
2026-11-24 23:27 pgsql: Fix broken HOT chain handling in parallel GIN builds Tomas Vondra <tomas.vondra@postgresql.org>
2026-11-24 23:27 pgsql: Fix broken HOT chain handling in parallel BRIN builds Tomas Vondra <tomas.vondra@postgresql.org>
2026-11-24 23:27 pgsql: Fix broken HOT chain handling in parallel GIN builds Tomas Vondra <tomas.vondra@postgresql.org>
2026-11-24 23:27 pgsql: Fix broken HOT chain handling in parallel BRIN builds Tomas Vondra <tomas.vondra@postgresql.org>

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