diff --git a/src/hnswbuild.c b/src/hnswbuild.c index b667478b..89c96ca7 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -45,6 +45,7 @@ #include "access/xloginsert.h" #include "catalog/index.h" #include "catalog/pg_type_d.h" +#include "cdb/cdbvars.h" #include "commands/progress.h" #include "hnsw.h" #include "miscadmin.h" @@ -1037,6 +1038,15 @@ ComputeParallelWorkers(Relation heap, Relation index) { int parallel_workers; + /* + * Follow index_build(): parallel workers launched on the QD inherit + * QE-only interconnect state (ic_htab_size, numsegmentsFromQD) that is + * unset in a dispatcher backend, so disable parallelism on the QD and + * for AO tables just like the core btree build path does. + */ + if (Gp_role == GP_ROLE_DISPATCH || AMHandlerIsAO(heap->rd_amhandler)) + return 0; + /* Make sure it's safe to use parallel workers */ parallel_workers = plan_create_index_workers(RelationGetRelid(heap), RelationGetRelid(index)); if (parallel_workers == 0) diff --git a/src/ivfbuild.c b/src/ivfbuild.c index ee2afd40..b8ab09a9 100644 --- a/src/ivfbuild.c +++ b/src/ivfbuild.c @@ -934,8 +934,14 @@ AssignTuples(IvfflatBuildState * buildstate) pgstat_progress_update_param(PROGRESS_CREATEIDX_SUBPHASE, PROGRESS_IVFFLAT_PHASE_ASSIGN); - /* Calculate parallel workers */ - if (buildstate->heap != NULL) + /* + * Follow index_build(): parallel workers launched on the QD inherit + * QE-only interconnect state (ic_htab_size, numsegmentsFromQD) that is + * unset in a dispatcher backend, so disable parallelism on the QD and + * for AO tables just like the core btree build path does. + */ + if (buildstate->heap != NULL && Gp_role != GP_ROLE_DISPATCH && + !AMHandlerIsAO(buildstate->heap->rd_amhandler)) parallel_workers = plan_create_index_workers(RelationGetRelid(buildstate->heap), RelationGetRelid(buildstate->index)); /* Attempt to launch parallel worker scan when required */