The DISTINCT in your COUNT
Summary
The article analyzes how PostgreSQL handles COUNT(DISTINCT) and why it typically fails to parallelize, illustrating a serial plan due to the need to deduplicate across workers. It demonstrates a parallelizable rewrite using GROUP BY to push the distinctness into a form that benefits from parallel execution, with performance comparisons and practical guidance. It also touches on approximate methods like HyperLogLog for large-scale dashboards.