diff --git a/src/ivfbuild.c b/src/ivfbuild.c index c4f4d4b..44a4a3a 100644 --- a/src/ivfbuild.c +++ b/src/ivfbuild.c @@ -904,6 +904,27 @@ IvfflatBeginParallel(IvfflatBuildState * buildstate, bool isconcurrent, int requ WaitForParallelWorkersToAttach(pcxt); } +/* + * Compute parallel workers + */ +static int +ComputeParallelWorkers(Relation heap, Relation index) +{ + int parallel_workers; + + /* Make sure it's safe to use parallel workers */ + parallel_workers = plan_create_index_workers(RelationGetRelid(heap), RelationGetRelid(index)); + if (parallel_workers == 0) + return 0; + + /* Use parallel_workers storage parameter on table if set */ + parallel_workers = RelationGetParallelWorkers(heap, -1); + if (parallel_workers != -1) + return Min(parallel_workers, max_parallel_maintenance_workers); + + return max_parallel_maintenance_workers; +} + /* * Scan table for tuples to index */ @@ -923,7 +944,7 @@ AssignTuples(IvfflatBuildState * buildstate) /* Calculate parallel workers */ if (buildstate->heap != NULL) - parallel_workers = plan_create_index_workers(RelationGetRelid(buildstate->heap), RelationGetRelid(buildstate->index)); + parallel_workers = ComputeParallelWorkers(buildstate->heap, buildstate->index); /* Attempt to launch parallel worker scan when required */ if (parallel_workers > 0)