postgresql/src
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
..
backend Allow parallel CREATE INDEX for BRIN indexes 2023-12-08 18:15:26 +01:00
bin Fix path of regress shared library in pg_upgrade test 2023-12-08 10:36:23 +09:00
common Shrink Unicode category table. 2023-12-07 15:44:03 -08:00
fe_utils Remove unneeded assignments in for loop header 2023-11-21 16:10:27 +01:00
include Allow parallel CREATE INDEX for BRIN indexes 2023-12-08 18:15:26 +01:00
interfaces Fix handling of errors in libpq pipelines 2023-12-05 12:43:24 +01:00
makefiles Remove distprep 2023-11-06 15:18:04 +01:00
pl Don't specify number of dimensions in cases where we don't know it. 2023-11-17 11:29:46 -05:00
port Optimize pg_readv/pg_pwritev single vector case. 2023-11-29 17:19:25 +13:00
template Use unnamed POSIX semaphores on Cygwin. 2023-01-06 10:33:28 +13:00
test Allow parallel CREATE INDEX for BRIN indexes 2023-12-08 18:15:26 +01:00
timezone Remove distprep 2023-11-06 15:18:04 +01:00
tools Allow parallel CREATE INDEX for BRIN indexes 2023-12-08 18:15:26 +01:00
tutorial Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
.gitignore
DEVELOPERS
Makefile Remove distprep 2023-11-06 15:18:04 +01:00
Makefile.global.in Don't clean initdb files on template creation failure 2023-12-08 13:42:54 +01:00
Makefile.shlib Stop using "-multiply_defined suppress" on macOS. 2023-09-26 21:06:21 -04:00
meson.build Integrate pg_bsd_indent into our build/test infrastructure. 2023-02-12 12:22:21 -05:00
nls-global.mk Remove distprep 2023-11-06 15:18:04 +01:00