mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Support parallel btree index builds.
To make this work, tuplesort.c and logtape.c must also support parallelism, so this patch adds that infrastructure and then applies it to the particular case of parallel btree index builds. Testing to date shows that this can often be 2-3x faster than a serial index build. The model for deciding how many workers to use is fairly primitive at present, but it's better than not having the feature. We can refine it as we get more experience. Peter Geoghegan with some help from Rushabh Lathia. While Heikki Linnakangas is not an author of this patch, he wrote other patches without which this feature would not have been possible, and therefore the release notes should possibly credit him as an author of this feature. Reviewed by Claudio Freire, Heikki Linnakangas, Thomas Munro, Tels, Amit Kapila, me. Discussion: http://postgr.es/m/CAM3SWZQKM=Pzc=CAHzRixKjp2eO5Q0Jg1SoFQqeXFQ647JiwqQ@mail.gmail.com Discussion: http://postgr.es/m/CAH2-Wz=AxWqDoVvGU7dq856S4r6sJAj6DBn7VMtigkB33N5eyg@mail.gmail.com
This commit is contained in:
@ -720,7 +720,8 @@ create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
|
||||
{
|
||||
int parallel_workers;
|
||||
|
||||
parallel_workers = compute_parallel_worker(rel, rel->pages, -1);
|
||||
parallel_workers = compute_parallel_worker(rel, rel->pages, -1,
|
||||
max_parallel_workers_per_gather);
|
||||
|
||||
/* If any limit was set to zero, the user doesn't want a parallel scan. */
|
||||
if (parallel_workers <= 0)
|
||||
@ -3299,7 +3300,8 @@ create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel,
|
||||
pages_fetched = compute_bitmap_pages(root, rel, bitmapqual, 1.0,
|
||||
NULL, NULL);
|
||||
|
||||
parallel_workers = compute_parallel_worker(rel, pages_fetched, -1);
|
||||
parallel_workers = compute_parallel_worker(rel, pages_fetched, -1,
|
||||
max_parallel_workers_per_gather);
|
||||
|
||||
if (parallel_workers <= 0)
|
||||
return;
|
||||
@ -3319,9 +3321,13 @@ create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel,
|
||||
*
|
||||
* "index_pages" is the number of pages from the index that we expect to scan, or
|
||||
* -1 if we don't expect to scan any.
|
||||
*
|
||||
* "max_workers" is caller's limit on the number of workers. This typically
|
||||
* comes from a GUC.
|
||||
*/
|
||||
int
|
||||
compute_parallel_worker(RelOptInfo *rel, double heap_pages, double index_pages)
|
||||
compute_parallel_worker(RelOptInfo *rel, double heap_pages, double index_pages,
|
||||
int max_workers)
|
||||
{
|
||||
int parallel_workers = 0;
|
||||
|
||||
@ -3392,10 +3398,8 @@ compute_parallel_worker(RelOptInfo *rel, double heap_pages, double index_pages)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* In no case use more than max_parallel_workers_per_gather workers.
|
||||
*/
|
||||
parallel_workers = Min(parallel_workers, max_parallel_workers_per_gather);
|
||||
/* In no case use more than caller supplied maximum number of workers */
|
||||
parallel_workers = Min(parallel_workers, max_workers);
|
||||
|
||||
return parallel_workers;
|
||||
}
|
||||
|
@ -682,7 +682,9 @@ cost_index(IndexPath *path, PlannerInfo *root, double loop_count,
|
||||
* order.
|
||||
*/
|
||||
path->path.parallel_workers = compute_parallel_worker(baserel,
|
||||
rand_heap_pages, index_pages);
|
||||
rand_heap_pages,
|
||||
index_pages,
|
||||
max_parallel_workers_per_gather);
|
||||
|
||||
/*
|
||||
* Fall out if workers can't be assigned for parallel scan, because in
|
||||
|
Reference in New Issue
Block a user