Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain
Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain
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
Re: Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain
От:
Tomas Vondra <tomas@vondra.me>
Дата:
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
Re: Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain
Hi, On Thu, Nov 19, 2026 at 5:56 PM Tomas Vondra 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]: https://www.postgresql.org/message-id/flat/CAP53PkxEZPeT_G7u-1qF-%3DouBvMxUNka-bN7cJowkv7gms9uCg%40mail.gmail.com#4fb55830a8fdca424c618a66837d1b0d [1]: https://github.com/pgvector/pgvector/commit/9f973cd95f5ac3aab6ccb8ebdfb048188e4025e4 Thanks, Lukas -- Lukas Fittl
Re: Parallel GIN, BRIN builds fail to maintain ii_BrokenHotChain
От:
Tomas Vondra <tomas@vondra.me>
Дата:
On 11/20/26 03:54, Lukas Fittl wrote: > Hi, > > On Thu, Nov 19, 2026 at 5:56 PM Tomas Vondra 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]: https://www.postgresql.org/message-id/flat/CAP53PkxEZPeT_G7u-1qF-%3DouBvMxUNka-bN7cJowkv7gms9uCg%40mail.gmail.com#4fb55830a8fdca424c618a66837d1b0d > [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
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