Repository navigation
Conversation
lfittl
force-pushed
the
refactor-parallel-workers-v2
branch
2 times, most recently
from
October 31, 2026 17:55
c18c6ed to
eb19ca8
Compare
Commit 6fd5071 made parallel workers for VACUUM, BRIN and btree index builds report the query ID of the leader, so that they show up with the correct query_id in pg_stat_activity. Parallel GIN index builds were added later by 8492feb, but did not include this, so GIN build workers have always reported a query ID of 0. Fix by storing the leader's query ID in the shared build state and reporting it in the worker, like the other index AMs already do. Author: Lukas Fittl <lukas@fittl.com> Discussion: https://postgr.es/m/CAP53Pkw3WcVbg61G29AmN=6XkuxGryoWKnhTyC1JmkT08i8qVA@mail.gmail.com
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 and GIN parallel index builds do 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 both AMs, like btree does, and copying it back into the ambuild IndexInfo in the leader after all participants are done. Oversight when parallel index builds were added for BRIN (b437571) and GIN (8492feb) and backpatch to 17 and 18 respectively. Author: Lukas Fittl <lukas@fittl.com> Reviewed-by: Discussion: https://postgr.es/m/CAP53Pkw3WcVbg61G29AmN=6XkuxGryoWKnhTyC1JmkT08i8qVA@mail.gmail.com
lfittl
force-pushed
the
refactor-parallel-workers-v2
branch
from
October 31, 2026 19:11
eb19ca8 to
af025d7
Compare
The three in-tree index AMs that currently support parallel index builds (nbtree, gin and brin) each share very similar code for initializing parallel workers, allocating shared memory and communicating between the leader and the workers. To reduce duplication, introduce shared helpers for parallel index builds, unifying the existing code. Author: Lukas Fittl <lukas@fittl.com> Reviewed-by: Sami Imseih <samimseih@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CAP53Pkw3WcVbg61G29AmN=6XkuxGryoWKnhTyC1JmkT08i8qVA@mail.gmail.com
Multiple parallel mechanisms outside of the executor (nbtree/GIN/BRIN index builds, vacuum) all had the same implementation for passing query text to the parallel workers. To reduce duplicated code, introduce new helper functions to: (1) estimate the needed shared memory space for the query text, (2) store the query text in shared memory, and (3) restore the query text in the worker. Author: Lukas Fittl <lukas@fittl.com> Reviewed-by: Sami Imseih <samimseih@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CAP53Pkw3WcVbg61G29AmN=6XkuxGryoWKnhTyC1JmkT08i8qVA@mail.gmail.com
lfittl
force-pushed
the
refactor-parallel-workers-v2
branch
2 times, most recently
from
October 31, 2026 20:06
9ddc792 to
29127d2
Compare
The parallel index build helpers left it to each AM to pass the ii_BrokenHotChain flag from the IndexInfo used for its heap scan into ParallelIndexBuildReportScanDone(), and to read it back out of ParallelIndexBuildWaitForWorkers() into the IndexInfo passed to ambuild. This is brittle and both GIN and BRIN have gotten this wrong in the past, and there extensions that handle this incorrectly today. Instead, introduce ParallelIndexBuildScan(), which builds the IndexInfo, joins the shared parallel scan, runs table_index_build_scan() and records a broken HOT chain itself. ParallelTableScanDescData is now stored in a separate shmem TOC entry for easier handling. Author: Lukas Fittl <lukas@fittl.com> Reviewed-by: Discussion: https://postgr.es/m/CAP53Pkw3WcVbg61G29AmN=6XkuxGryoWKnhTyC1JmkT08i8qVA@mail.gmail.com
lfittl
force-pushed
the
refactor-parallel-workers-v2
branch
from
October 31, 2026 20:19
29127d2 to
8946374
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.