Re: Parallel CREATE INDEX for GIN indexes
Matthias van de Meent <boekewurm+postgres@gmail.com>
From: Matthias van de Meent <boekewurm+postgres@gmail.com>
To: Tomas Vondra <tomas@vondra.me>
Cc: Kirill Reshke <reshkekirill@gmail.com>,
Michael Paquier <michael@paquier.xyz>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-03-07T02:08:10Z
Lists: pgsql-hackers
Attachments
- v20250307-0004-Make-Gin-parallel-builds-use-a-single-tupl.patch (application/octet-stream) patch v20250307-0004
- v20250307-0002-Allow-tuplesort-implementations-to-buffer-.patch (application/octet-stream) patch v20250307-0002
- v20250307-0001-Remove-size-argument-from-GIN-tuplesort-in.patch (application/octet-stream) patch v20250307-0001
- v20250307-0003-Merge-GinTuples-during-tuplesort-before-fl.patch (application/octet-stream) patch v20250307-0003
On Tue, 4 Mar 2025 at 20:50, Tomas Vondra <tomas@vondra.me> wrote: > > I pushed the two smaller parts today. > > Here's the remaining two parts, to keep cfbot happy. I don't expect to > get these into PG18, though. As promised on- and off-list, here's the 0001 patch, polished, split, and further adapted for performance. As seen before, it reduces tempspace requirements by up to 50%. I've not tested this against HEAD for performance. It has been split into: 0001: Some API cleanup/changes that creaped into the patch. This removes manual length-passing from the gin tuplesort APIs, instead relying on GinTuple's tuplen field. It's not critical for anything, and could be ignored if so desired. 0002: Tuplesort changes to allow TupleSort users to buffer and merge tuples during the sort operations. The patch was pulled directly from [0] (which was derived from earlier work in this thread), is fairly easy to understand, and has no other moving parts. 0003: Deduplication in tuplesort's flush-to-disk actions, utilizing API introduced with 0002. This improves temporary disk usage by deduplicating data even further, for when there's a lot of duplicated data but the data has enough distinct values to not fit in the available memory. 0004: Use a single tuplesort. This removes the worker-local tuplesort in favor of only storing data in the global one. This mainly reduces the code size and complexity of parallel GIN builds; we already were using that global sort for various tasks. Open questions and open items for this: - I did not yet update the pg_stat_progress systems, nor docs. - Maybe 0003 needs further splitting up, one for the optimizations in GinBuffer, one for the tuplesort buffering. - Maybe we need to trim the buffer in gin's tuplesort flush? - Maybe we should grow the GinBuffer->items array superlinearly rather than to the exact size requirement of the merge operation. Apart from the complexities in 0003, I think the changes are fairly straightforward. I did not include the 0002 of the earlier patch, as it was WIP and its feature explicitly conflicts with my 0004. Kind regards, Matthias van de Meent Neon (https://neon.tech) [0] https://www.postgresql.org/message-id/CAEze2WhRFzd=nvh9YevwiLjrS1j1fP85vjNCXAab=iybZ2rNKw@mail.gmail.com
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Exercise parallel GIN builds in regression tests
- f6e5d21bf73f 19 (unreleased) landed
- 32593394ee43 18.2 landed
-
Lookup the correct ordering for parallel GIN builds
- db14dcdec69d 19 (unreleased) landed
- eee71a66cc86 18.2 landed
-
Fix memory leak in _gin_parallel_merge
- 1681a70df3d6 18.0 landed
-
Enforce memory limit during parallel GIN builds
- b229c1016477 18.0 landed
-
Compress TID lists when writing GIN tuples to disk
- 0b2a45a5d1f2 18.0 landed
-
Allow parallel CREATE INDEX for GIN indexes
- 8492feb98f6d 18.0 landed