| |
Adding the DISTINCT keyword to a COUNT aggregate in PostgreSQL disables parallel query execution, forcing a single worker to sort all rows by the distinct column—a process that can spill to disk on large tables. While a simple COUNT(*) efficiently uses multiple parallel workers, COUNT(DISTINCT user_id) requires sorting all rows to group duplicates together, making parallelization impossible under Postgres's current execution model. The article explores why this limitation exists and presents strategies to rewrite such queries for better performance.
Read Full Article →
← More Tech news