CS FundamentalsHardIBM · Deloitte pattern

A query optimizer estimates the selectivity of `WHERE age = 30` using a histogram on the age column rather than assuming a uniform distribution across all possible ages. Why does a histogram typically give a more accurate cardinality estimate?

  1. A. Histograms only work for numeric columns, never strings
  2. B. Histograms are always 100% accurate, unlike any other statistic
  3. C. A histogram captures the actual, possibly skewed, frequency distribution of values (e.g. many more 30-year-olds than 90-year-olds in a customer table) rather than assuming every value occurs equally often, which uniform-distribution assumptions get wrong for skewed data
  4. D. Histograms eliminate the need for an index on the column

Correct answer: C. A histogram captures the actual, possibly skewed, frequency distribution of values (e.g. many more 30-year-olds than 90-year-olds in a customer table) rather than assuming every value occurs equally often, which uniform-distribution assumptions get wrong for skewed data

Real-world data is often skewed (far more rows for common values than rare ones). A histogram buckets the column's actual value distribution, letting the optimizer estimate `age = 30`'s selectivity from the real frequency of 30s rather than (total rows / number of distinct values), which badly misestimates cost whenever the distribution is uneven.

More DBMS and SQL questions

Exams that ask this topic