Re: Unify parallel worker handling for index builds and instrumentation

From: Lukas Fittl <lukas(at)fittl(dot)com>
To: Tomas Vondra <tomas(at)vondra(dot)me>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Michael Paquier <michael(at)paquier(dot)xyz>, Sami Imseih <samimseih(at)gmail(dot)com>
Subject: Re: Unify parallel worker handling for index builds and instrumentation
Date: 2026-11-26 19:52:46
Message-ID: CAP53PkzPYMNJjVjadtX2u8iv0RrQbbSivreSHyYTDe2h4tM4ew@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Nov 26, 2026 at 5:19 AM Tomas Vondra <tomas(at)vondra(dot)me> wrote:
> Pushed.

Thanks!

See attached an updated v3 that has the existing refactoring patches
with minor changes, and one new 0001 patch (see separate note):

- Dropped the query ID handling in ParallelIndexBuildOpenRelations (it
felt out of place on re-review), instead keeping it in the AM worker
entry points as before - I have some other ideas for how we could deal
with query IDs better that fit better in a new thread
- Cleanup of includes that are no longer needed in
nbtsort.c/gininsert.c/brin.c/vacuumparallel.c due to the refactorings
- Comment improvements for clarity
- Re-ordered the query text helpers commit to be 0002 before the
parallel index build helpers (0003 and 0004) - it's an independent
change and that avoids it sitting between two changes that do relate
together

FWIW, if we think having a unified way to do the table scans in
parallel index builds (the last commit) is reasonable to do, we should
probably squash together 0003 and 0004, so the refactoring is in one
big commit, to avoid some churn.

Doing another LLM supported self-review also found one more
pre-existing bug fixed in a new 0001 (isn't this fun? ..) - BRIN
parallel workers were unnecessarily doing progress tracking work
(updating PgBackendStatus) during the table scan because the
"progress" argument was ignored and not passed through to
table_index_build_scan. This appears to have been another oversight
when parallel index builds for BRIN were first added.

I poked a bit at why we're not doing table scan progress reporting in
the workers: My understanding is that we don't need to do so because
the leader participates in the same parallel table scan, and
participants are handed blocks/pages in ascending order from the
shared scan state. The leader's own progress reporting updates
blocks_done in pg_stat_progress_create_index, which is a close enough
approximation, and parallel index builds always have leader
participation, since DISABLE_LEADER_PARTICIPATION can be assumed not
to be set in production builds.

Thanks,
Lukas

--
Lukas Fittl

Attachment Content-Type Size
v3-0002-Unify-parallel-worker-handling-for-query-text.patch application/octet-stream 13.3 KB
v3-0004-Unify-parallel-index-build-scan-handling.patch application/octet-stream 38.3 KB
v3-0001-Don-t-track-table-scan-progress-in-parallel-BRIN-.patch application/octet-stream 1.6 KB
v3-0003-Unify-parallel-index-build-infrastructure.patch application/octet-stream 52.7 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-11-26 19:58:11 Re: [PATCH] pg_input_is_valid() reuses the first type name inside a PL/pgSQL loop
Previous Message Osama Abdul Qader 2026-11-26 19:28:58 Re: Preserve tablespace of exclusion constraint indexes in ALTER TYPE