The DISTINCT in Your COUNT
COUNT(DISTINCT) has no combine function, so PostgreSQL can't merge per-worker results: the whole statement drops to one core and a disk-spilling sort. Push the distinctness into a GROUP BY instead and parallel query comes back.
Summary
PostgreSQL’s handling of COUNT(DISTINCT) can lead to performance issues by forcing operations onto a single core. By using GROUP BY to manage distinct values, you can leverage parallel queries for improved efficiency.
Comments (2 of ) ⌛