Skip to content

Refactor parallel workers v3 - #91

Open
lfittl wants to merge 4 commits into
masterfrom
refactor-parallel-workers-v3
Open

lfittl wants to merge 4 commits into
masterfrom
refactor-parallel-workers-v3

Conversation

@lfittl

@lfittl lfittl commented Nov 26, 2026

Copy link
Copy Markdown
Owner

No description provided.

_brin_parallel_scan_and_build() takes a "progress" argument, which the
leader passes as true and parallel workers pass as false, but it ignored
the argument and always asked table_index_build_scan() to report
progress. Progress reporting is wasted effort on workers, since the scan
writes it to the worker's own backend entry, which is not shown in
pg_stat_progress_create_index and is not copied to the leader.

Adjust to match how GIN and nbtree handle it, by passing the argument
through to the underlying scan.

Oversight in b437571, which added parallel index builds for BRIN.

Author: Lukas Fittl <lukas@fittl.com>
Reviewed-by:
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
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
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 are extensions that handled this wrong as well.

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
lfittl force-pushed the refactor-parallel-workers-v3 branch from 6c366d5 to a8f3f93 Compare November 26, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant