Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain

Started by Peter Geoghegan5 days ago7 messageshackers
Jump to latest

My LLM produced the attached patch, which adds an isolation test
showing that parallel index builds of both GIN and BRIN indexes fail
to maintain ii_BrokenHotChain correctly. The test fails, demonstrating
incorrect results.

The underlying bug is straightforward: both GIN and BRIN lack the
required handling. If any individual parallel worker sets
ii_BrokenHotChain, then it has to be passed on to the leader so that
pg_index.indcheckxmin gets set correctly. Otherwise, older snapshots
can use the index even though it isn't guaranteed to have index tuples
for every row version that the snapshot can still see. nbtree gets
this right, but that precedent seems to have been missed.

--
Peter Geoghegan

Attachments:

t259519_1
v1-0001-Add-isolation-test-for-index-builds-over-broken-H.patchapplication/octet-stream; name=v1-0001-Add-isolation-test-for-index-builds-over-broken-H.patchDownload+184-1
#2Tomas Vondra
tomas@vondra.me
In reply to: Peter Geoghegan (#1)
Re: Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain

On 11/20/26 01:46, Peter Geoghegan wrote:

My LLM produced the attached patch, which adds an isolation test
showing that parallel index builds of both GIN and BRIN indexes fail
to maintain ii_BrokenHotChain correctly. The test fails, demonstrating
incorrect results.

The underlying bug is straightforward: both GIN and BRIN lack the
required handling. If any individual parallel worker sets
ii_BrokenHotChain, then it has to be passed on to the leader so that
pg_index.indcheckxmin gets set correctly. Otherwise, older snapshots
can use the index even though it isn't guaranteed to have index tuples
for every row version that the snapshot can still see. nbtree gets
this right, but that precedent seems to have been missed.

Thanks for noticing it, and for the reproducer. I'll get it fixed
(unless you want to take care of that).

regards

--
Tomas Vondra

#3Lukas Fittl
lukas@fittl.com
In reply to: Tomas Vondra (#2)
Re: Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain

Hi,

On Thu, Nov 19, 2026 at 5:56 PM Tomas Vondra <tomas@vondra.me> wrote:

On 11/20/26 01:46, Peter Geoghegan wrote:

My LLM produced the attached patch, which adds an isolation test
showing that parallel index builds of both GIN and BRIN indexes fail
to maintain ii_BrokenHotChain correctly. The test fails, demonstrating
incorrect results.

The underlying bug is straightforward: both GIN and BRIN lack the
required handling. If any individual parallel worker sets
ii_BrokenHotChain, then it has to be passed on to the leader so that
pg_index.indcheckxmin gets set correctly. Otherwise, older snapshots
can use the index even though it isn't guaranteed to have index tuples
for every row version that the snapshot can still see. nbtree gets
this right, but that precedent seems to have been missed.

Thanks for noticing it, and for the reproducer. I'll get it fixed
(unless you want to take care of that).

I actually ran into the exact same issue and reported it over at [0]/messages/by-id/CAP53PkxEZPeT_G7u-1qF-=ouBvMxUNka-bN7cJowkv7gms9uCg@mail.gmail.com
together with a refactoring to prevent problems like this from
happening in the future. pgvector had the same issue and Andrew fixed
it recently based on that report [1]https://github.com/pgvector/pgvector/commit/9f973cd95f5ac3aab6ccb8ebdfb048188e4025e4.

For easier reference, attached the v2 patch from here that fixes that
specific issue as 0002, together with Peter's isolation test
reproducer from v1 kept as 0001. This now passes the test for me
locally.

[0]: /messages/by-id/CAP53PkxEZPeT_G7u-1qF-=ouBvMxUNka-bN7cJowkv7gms9uCg@mail.gmail.com
[1]: https://github.com/pgvector/pgvector/commit/9f973cd95f5ac3aab6ccb8ebdfb048188e4025e4

Thanks,
Lukas

--
Lukas Fittl

Attachments:

t259519_3
v2-0002-Fix-broken-HOT-chain-handling-in-parallel-BRIN-an.patchapplication/octet-stream; name=v2-0002-Fix-broken-HOT-chain-handling-in-parallel-BRIN-an.patchDownload+47-19
v2-0001-Add-isolation-test-for-index-builds-over-broken-H.patchapplication/octet-stream; name=v2-0001-Add-isolation-test-for-index-builds-over-broken-H.patchDownload+184-1
#4Tomas Vondra
tomas@vondra.me
In reply to: Lukas Fittl (#3)
Re: Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain

On 11/20/26 03:54, Lukas Fittl wrote:

Hi,

On Thu, Nov 19, 2026 at 5:56 PM Tomas Vondra <tomas@vondra.me> wrote:

On 11/20/26 01:46, Peter Geoghegan wrote:

My LLM produced the attached patch, which adds an isolation test
showing that parallel index builds of both GIN and BRIN indexes fail
to maintain ii_BrokenHotChain correctly. The test fails, demonstrating
incorrect results.

The underlying bug is straightforward: both GIN and BRIN lack the
required handling. If any individual parallel worker sets
ii_BrokenHotChain, then it has to be passed on to the leader so that
pg_index.indcheckxmin gets set correctly. Otherwise, older snapshots
can use the index even though it isn't guaranteed to have index tuples
for every row version that the snapshot can still see. nbtree gets
this right, but that precedent seems to have been missed.

Thanks for noticing it, and for the reproducer. I'll get it fixed
(unless you want to take care of that).

I actually ran into the exact same issue and reported it over at [0]
together with a refactoring to prevent problems like this from
happening in the future. pgvector had the same issue and Andrew fixed
it recently based on that report [1].

For easier reference, attached the v2 patch from here that fixes that
specific issue as 0002, together with Peter's isolation test
reproducer from v1 kept as 0001. This now passes the test for me
locally.

[0]: /messages/by-id/CAP53PkxEZPeT_G7u-1qF-=ouBvMxUNka-bN7cJowkv7gms9uCg@mail.gmail.com
[1]: https://github.com/pgvector/pgvector/commit/9f973cd95f5ac3aab6ccb8ebdfb048188e4025e4

Thanks,
Lukas

Thanks. That is very helpful, I'll use it for my fix.

regards

--
Tomas Vondra

#5Tomas Vondra
tomas@vondra.me
In reply to: Tomas Vondra (#4)
Re: Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain

Hi,

Here's a slightly reworked version of the patches posted by Lukas
earlier. It mostly just splits the test/fix commits into the BRIN and
GIN part, as those need to be backpatched to different releases.

The "TEST" parts should be squashed into the following fix commits, I
kept it this way as it makes it easier to test without the fix.

The commit messages probably still need more work, but the code changes
seem correct to me (I've also confirmed it to what btree does).

regards

--
Tomas Vondra

Attachments:

t259519_5
v3-0004-Fix-broken-HOT-chain-handling-in-parallel-GIN-bui.patchtext/x-patch; charset=UTF-8; name=v3-0004-Fix-broken-HOT-chain-handling-in-parallel-GIN-bui.patchDownload+23-10
v3-0003-Add-isolation-test-for-index-builds-over-broken-H.patchtext/x-patch; charset=UTF-8; name=v3-0003-Add-isolation-test-for-index-builds-over-broken-H.patchDownload+43-1
v3-0002-Fix-broken-HOT-chain-handling-in-parallel-BRIN-bu.patchtext/x-patch; charset=UTF-8; name=v3-0002-Fix-broken-HOT-chain-handling-in-parallel-BRIN-bu.patchDownload+24-10
v3-0001-Add-isolation-test-for-index-builds-over-broken-H.patchtext/x-patch; charset=UTF-8; name=v3-0001-Add-isolation-test-for-index-builds-over-broken-H.patchDownload+141-1
#6Tomas Vondra
tomas@vondra.me
In reply to: Tomas Vondra (#5)
Re: Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain

On 11/20/26 14:11, Tomas Vondra wrote:

Hi,

Here's a slightly reworked version of the patches posted by Lukas
earlier. It mostly just splits the test/fix commits into the BRIN and
GIN part, as those need to be backpatched to different releases.

The "TEST" parts should be squashed into the following fix commits, I
kept it this way as it makes it easier to test without the fix.

The commit messages probably still need more work, but the code changes
seem correct to me (I've also confirmed it to what btree does).

I've pushed/backpatched this, with some minor tweaks (mostly wording of
comments and commit messages, but I've also switched the test to use
parallel_workers to force parallel index builds).

Thanks to both of you!

--
Tomas Vondra

#7Lukas Fittl
lukas@fittl.com
In reply to: Tomas Vondra (#6)
Re: Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain

On Tue, Nov 24, 2026 at 3:31 PM Tomas Vondra <tomas@vondra.me> wrote:

I've pushed/backpatched this, with some minor tweaks (mostly wording of
comments and commit messages, but I've also switched the test to use
parallel_workers to force parallel index builds).

Thanks to both of you!

Great, thank you for pushing the fixes!

Thanks,
Lukas

--
Lukas Fittl