Parallel Query: Workers Planned 0 despite enabled configuration
0 reputation · 07 Nov 2021, 17:22 UTC
0 reputation · 07 Nov 2021, 17:22 UTC
In PostgreSQL (version 10 through 16), the query planner determines whether to utilize parallel workers based on a cost-benefit analysis. Even when max_parallel_workers and max_parallel_workers_per_gather are configured to allow concurrency, the planner may still produce a serial plan if the estimated cost of the operation does not exceed the internal threshold defined by parallel_setup_cost and parallel_tuple_cost.
The decision to spawn workers is not a binary toggle but a cost-based estimation. When EXPLAIN output indicates "Workers Planned: 0", it suggests the planner believes the overhead of coordinating parallel processes outweighs the execution time savings for that specific data volume and query structure.
What specific metrics or hidden cost thresholds trigger the transition from a serial plan to a parallel plan? How can the relationship between parallel_tuple_cost and the planner's decision be verified without guessing parameter values?
When Workers Planned: 0 appears, the planner has decided that the cost of launching and coordinating workers outweighs the potential speed‑up for that query. Even if max_parallel_workers and
max_parallel_workers_per_gather allow concurrency, PostgreSQL’s cost model may still prefer a serial plan.
The planner compares the estimated cost of a serial plan with that of a parallel plan. For a Gather node the inequality that must hold for workers to be planned is:
serial_cost - parallel_cost > parallel_setup_cost * workers + parallel_tuple_cost * estimated_rows
If the estimated number of rows is low, or the operation is cheap, the right‑hand side can dominate, causing the planner to choose 0 workers. The key parameters involved are:
parallel_setup_cost – fixed cost of starting workers.parallel_tuple_cost – per‑tuple cost of master‑worker communication.max_parallel_workers / max_parallel_workers_per_gather – limits on worker count.SHOW parallel_setup_cost;
SHOW parallel_tuple_cost;
SHOW max_parallel_workers;
SHOW max_parallel_workers_per_gather;
EXPLAIN (ANALYZE, BUFFERS, COSTS) SELECT …;
Inspect Workers Planned and the cost columns.
SET parallel_setup_cost = 0;
SET parallel_tuple_cost = 0;
EXPLAIN (ANALYZE, BUFFERS, COSTS) SELECT …;
If workers appear, the original decision was cost‑driven.
SET max_parallel_workers_per_gather = N;
To refine the recommendation, I need the estimated row count for the operation that could use parallel workers (shown as Rows in the EXPLAIN output). This figure determines whether the planner expects a benefit from parallelism.
Please run EXPLAIN (ANALYZE, BUFFERS, COSTS) SELECT …; and share the estimated row count for that operation.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.