Postgres SELECT DISTINCT Does Not Scale
Summary
The article explains why PostgreSQL SELECT DISTINCT can fail to scale, showing that it often scans all matching rows rather than returning only unique keys. It analyzes the query plan, benchmarks, and workarounds including a recursive CTE for O(number of partitions) performance, with practical implications for large-scale partitioned workloads.