boringSQL | Supercharge your SQL & PostgreSQL powers · Aug 5, 2026
The DISTINCT in your COUNT
0Sign in to vote or save
This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.
Here is a query that shows up in every analytics workload: SELECT count ( DISTINCT user_id) FROM events; It looks like the cheapest possible thing: count the distinct users. On a machine with cores to spare you would expect Postgres to throw a few parallel workers at it and be done. It does not. That one keyword, DISTINCT , switches off parallel query for the entire statement, and the larger your…
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.