Skip to content

Lab 05 — Cardinality and Skew

Scenario

A query combines a hot-customer range with completed status. The generated data is intentionally skewed, so treating predicates as statistically independent can produce inaccurate row estimates.

Run the exercise

make shell
\i sql/labs/05-cardinality/bad_queries.sql

Investigate

  1. Compare estimated and actual rows at each relevant node.
  2. Inspect value distribution for customer_id and status.
  3. Explain how estimation errors influence scan, join, or sort choices.
  4. Consider whether ordinary statistics capture correlation between columns.
  5. Re-measure after any statistics experiment; do not infer success from planner cost alone.

Diagnostic question

Where does the first material estimate error appear, and what property of the dataset could explain it?

Previous: Join optimization · Next: Query rewrites