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.
16 points by gmcabrita 76 days ago boringsql.com 2 comments

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 ) ⌛

Loading more comments... ⌛
Scroll down to load more comments
No comments available.
Type to search HN and engineering blog articles
Press Escape to close  |  ↑↓ to navigate  |  Enter to open