PostgreSQL parallel query planner misestimating costs with expression indexes
19K reputation · 11 Nov 2022, 23:10 UTC
Parallel Execution and Expression Indexes
PostgreSQL 14+ utilizes a cost-based planner to determine if a query should be executed in parallel. This decision depends on the max_parallel_workers_per_gather setting and the estimated cost of a serial plan versus a parallel plan.
When queries rely on expression indexes rather than standard B-tree indexes on base columns, the planner's ability to accurately estimate the cost of parallel scans can be inconsistent. This creates uncertainty regarding whether the planner will correctly identify a plan as 'Parallel Aware' or default to a serial execution path despite available CPU resources.
Given these constraints, what specific factors influence the planner's cost estimation for parallel scans when expression indexes are involved? How does the presence of these indexes impact the selection of the parallel degree?