Histograms and Selectivity Estimation
Estimate a range from bucket counts and distinguish information about the whole bucket from assumptions about values within it.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
A bucket only records an aggregate
An equi-width histogram assigns count to value intervals of equal width. If a bucket has 100 rows and a query covers half its width, a uniform-within-bucket assumption estimates 50 rows from that bucket. The count alone permits anything from zero to 100 in that half. Equi-depth buckets distribute row counts more evenly, while changing width. A separate most-common-values list can capture heavy isolated values.
Explain where estimates can be wrong
Old statistics can miss a changed workload, and even current one-column statistics may miss dependencies between columns. Histograms summarizing two fields independently are insufficient for a reliable estimate of their conjunction under correlation. Selectivity and correlation give a worked example. Query plan inspection can compare estimated and observed rows at the operator where the difference appears.[1][2]