Skip to content

Commit

Permalink
Improved number of parallel workers for HNSW index builds - closes #397
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jan 6, 2024
1 parent 81d13bd commit 6132428
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/hnswbuild.c
Expand Up @@ -853,6 +853,27 @@ HnswBeginParallel(HnswBuildState * buildstate, bool isconcurrent, int request)
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;
}

/*
* Build graph
*/
Expand All @@ -865,7 +886,7 @@ BuildGraph(HnswBuildState * buildstate, ForkNumber forkNum)

/* Calculate parallel workers */
if (hnsw_enable_parallel_build)
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)
Expand Down

0 comments on commit 6132428

Please sign in to comment.