postgresql/src/backend/access
Tomas Vondra b437571714 Allow parallel CREATE INDEX for BRIN indexes
Allow using multiple worker processes to build BRIN index, which until
now was supported only for BTREE indexes. For large tables this often
results in significant speedup when the build is CPU-bound.

The work is split in a simple way - each worker builds BRIN summaries on
a subset of the table, determined by the regular parallel scan used to
read the data, and feeds them into a shared tuplesort which sorts them
by blkno (start of the range). The leader then reads this sorted stream
of ranges, merges duplicates (which may happen if the parallel scan does
not align with BRIN pages_per_range), and adds the resulting ranges into
the index.

The number of duplicate results produced by workers (requiring merging
in the leader process) should be fairly small, thanks to how parallel
scans assign chunks to workers. The likelihood of duplicate results may
increase for higher pages_per_range values, but then there are fewer
page ranges in total. In any case, we expect the merging to be much
cheaper than summarization, so this should be a win.

Most of the parallelism infrastructure is a simplified copy of the code
used by BTREE indexes, omitting the parts irrelevant for BRIN indexes
(e.g. uniqueness checks).

This also introduces a new index AM flag amcanbuildparallel, determining
whether to attempt to start parallel workers for the index build.

Original patch by me, with reviews and substantial reworks by Matthias
van de Meent, certainly enough to make him a co-author.

Author: Tomas Vondra, Matthias van de Meent
Reviewed-by: Matthias van de Meent
Discussion: https://postgr.es/m/c2ee7d69-ce17-43f2-d1a0-9811edbda6e6%40enterprisedb.com
2023-12-08 18:15:26 +01:00
..
brin Allow parallel CREATE INDEX for BRIN indexes 2023-12-08 18:15:26 +01:00
common Make ResourceOwners more easily extensible. 2023-11-08 13:30:50 +02:00
gin Allow parallel CREATE INDEX for BRIN indexes 2023-12-08 18:15:26 +01:00
gist Allow parallel CREATE INDEX for BRIN indexes 2023-12-08 18:15:26 +01:00
hash Allow parallel CREATE INDEX for BRIN indexes 2023-12-08 18:15:26 +01:00
heap Apply quotes more consistently to GUC names in logs 2023-11-30 14:11:45 +09:00
index Check if ii_AmCache is NULL in aminsertcleanup 2023-11-27 16:53:06 +01:00
nbtree Allow parallel CREATE INDEX for BRIN indexes 2023-12-08 18:15:26 +01:00
rmgrdesc Index SLRUs by 64-bit integers rather than by 32-bit integers 2023-11-29 01:40:56 +02:00
spgist Allow parallel CREATE INDEX for BRIN indexes 2023-12-08 18:15:26 +01:00
table Add const to values and nulls arguments 2023-10-10 07:50:43 +02:00
tablesample Update copyright for 2023 2023-01-02 15:00:37 -05:00
transam Allow parallel CREATE INDEX for BRIN indexes 2023-12-08 18:15:26 +01:00
Makefile Introduce access/{table.h, relation.h}, for generic functions from heapam.h. 2019-01-21 10:51:36 -08:00
meson.build Update copyright for 2023 2023-01-02 15:00:37 -05:00