Module 4 · Query optimization
Episode 28 Cardinality Estimation
▶ This video is coming to YouTube soon.
Postgres estimated 200 customers in Paris and France; there were 1,000. This episode shows how row estimates multiply up a plan, why the independence assumption breaks on correlated columns, how two errors compound to an estimate of 6 rows for 29,755, and how CREATE STATISTICS (dependencies, MCV lists, ndistinct, expressions) fixes what it can, all checked against real EXPLAIN ANALYZE output.
Chapters
- 0:00Intro
- 0:13Paris is in France
- 0:33Estimates multiply up the plan
- 1:18How a join is estimated
- 2:14The independence assumption
- 2:56Errors compound across joins
- 3:40Where every estimate comes from
- 4:16Proof: estimated against actual rows
- 4:50Statistics on pairs of columns
- 5:46The code: AND with a dependency
- 6:16Proof: CREATE STATISTICS
- 7:23Which statistic fixes what
- 7:51Recap
- 8:16Next: Join Ordering