CREATE STATISTICS - what is it for
summary
Postgres 10 adds CREATE STATISTICS to collect multi‑column stats so the planner stops multiplying independent selectivities into nonsense: a 1.7 million‑row UK postcode table gives single‑column estimates like ~14,000 vs 13,889 actual, but a two‑column equality query falls to 115 vs ~12,000. functional dependencies raise the estimate toward ~9,200; n‑distinct coefficients cut a GROUP BY estimate from ~170,000 to ~13,221 and drop runtime from 1.5s to 0.4s; Postgres 12’s most common value lists can make some estimates exact. Future work targets expression stats and better join estimates.
AI-written summary · about
chapters (12)
- 0:00Introduction to CREATE STATISTICS
- 1:17How PostgreSQL estimates row cardinalities
- 5:55Understanding EXPLAIN and estimates
- 11:20Correlated columns and estimation errors
- 15:37Consequences of estimation errors
- 19:33Introduction to extended statistics
- 21:22Functional dependencies explained
- 26:43Limitations of functional dependencies
- 29:35N-distinct coefficients for GROUP BY
- 34:19Fixing GROUP BY estimates with n-distinct
- 37:33Most common value lists in PostgreSQL 12
- 42:38Future improvements and Q&A
