interviewpath
  • 0day streak
  • 10total XP
  • Level 1

How Good Are Query Optimizers, Really?

Viktor Leis, Andrey Gubichev, Atanas Mirchev, Peter Boncz, Alfons Kemper, Thomas Neumann. PVLDB, vol. 9, no. 3, 2015.

Open the paper(opens in a new tab)Planning estimate 3 h (editable through its topic)

Who should read it

Read it before doing any query-optimization or learned-optimizer research, and before claiming that a new estimator improves plans: it introduced the Join Order Benchmark and a clean method (injecting estimated and true cardinalities into one engine) for separating the effects of cardinality estimation, the cost model and plan enumeration. It also helps performance engineers who read EXPLAIN output. It is not needed for application-level SQL interviews, and its findings describe specific system versions from around 2015, so treat them as a method and a pattern to re-check rather than as current facts about any product.

Study objectives

  • Explain the classical optimizer architecture and which three components the paper isolates.
  • Describe the cardinality-injection method and why running all plans in one execution engine makes the comparison fair.
  • Explain why estimation errors grow with the number of joins and lean toward underestimation under independence assumptions.
  • Explain when bad estimates actually cause slow queries, and how engine choices and physical design change that.
  • Summarize the conclusions about cost models and about exhaustive versus heuristic join enumeration, and how each was measured.

Prerequisites

Main concepts to understand

  • Join Order Benchmark: real, correlated IMDB data with multi-join queries, in contrast to synthetic benchmarks with independent columns.
  • q-error as a symmetric measure of estimation error, analyzed by the number of joins.
  • Injecting each system’s estimates, and the true cardinalities, into the same optimizer to attribute slowdowns.
  • Risky operator choices driven by underestimates: nested-loop joins without an index and hash tables sized from estimates.
  • Physical design matters: more indexes enlarge the plan space and the damage misestimates can do.
  • Cost model comparison, including tuning for main memory and a deliberately simple cost function.
  • Plan space: exhaustive dynamic programming versus heuristics, and bushy versus restricted tree shapes.

What to inspect in the evaluation

  • Workload: what JOB includes and excludes (one dataset, read-only queries, a fixed query set); ask how far conclusions generalize.
  • Systems: PostgreSQL, HyPer and three anonymized commercial systems at the versions of the time; for the commercial systems only estimates were extracted and injected.
  • Metrics: q-error distributions for estimates and runtime slowdown relative to the plan chosen with true cardinalities; check how timeouts are treated.
  • Controls: the PostgreSQL changes made before later experiments; later results are conditional on them.
  • Setup: single machine with the data cached in memory, single-threaded execution and raised memory settings; consider how disk-bound or parallel settings could differ.
  • Physical designs compared (primary-key indexes only versus additional foreign-key indexes) and their effect on conclusions.

Guarantees versus empirical results

Correctness or design arguments

  • No formal guarantees; the methodological argument is that injecting cardinalities into a single engine isolates estimation quality from execution-engine differences.
  • The design argument that operator choices should account for estimate uncertainty and asymptotic risk, not only for point cost estimates.

Empirical results (depend on setup)

  • Estimation errors of the tested systems grow with the number of joins and are frequently underestimates.
  • On this workload, slow plans are mostly attributable to cardinality misestimates rather than to cost-model errors.
  • Avoiding non-index nested-loop joins and resizing hash tables at runtime removed many catastrophic plans in PostgreSQL.
  • Additional indexes make the optimization problem harder, and exhaustive enumeration outperforms heuristics despite estimation errors.

Reading plan

  1. Pass 1 (30 minutes): abstract, introduction and conclusions; write down the questions the paper asks and its one-line answer to each.
  2. Pass 2 (80 minutes): Sections 2 to 4 (benchmark, method, cardinality estimation, when bad estimates lead to slow queries); sketch the injection pipeline and describe the slowdown distributions in words, without copying numbers.
  3. Pass 3 (70 minutes): Sections 5 and 6 (cost models, plan space); then load JOB into PostgreSQL and run a few queries with EXPLAIN ANALYZE to find the operator where estimates first go wrong.

Discussion prompts

  • Why does the independence assumption tend to produce underestimates on correlated, multi-join queries, and why are underestimates more dangerous than overestimates?
  • Would a perfect cardinality estimator make the optimizer optimal? What does “optimal with respect to the cost model” leave out?
  • How would you design an experiment showing that a learned estimator improves end-to-end query time, not only q-error?
  • Which conclusions might change for a modern engine with adaptive or robust join algorithms, or for a distributed engine?

Related topics

Your structured notes

The guide above is an original annotation; write your own reading of the paper here.

Which component of query optimization is responsible for bad plans, and how large are the effects on realistic data?

Which assumptions do production estimators make (uniformity, independence, containment), and which does the JOB data violate?

How does injecting cardinalities into PostgreSQL separate estimation from cost modeling and from enumeration?

What did the benchmark and the method add that earlier synthetic studies lacked?

Which figures or tables support each main conclusion, and under which configuration?

What is the reference plan, and why is it only optimal with respect to a cost model and search space?

Which components are varied one at a time: estimates, cost model, index configuration, enumeration algorithm?

What does the study not cover: other datasets, updates, parallel or distributed engines, newer system versions?

What would you need to repeat one experiment: data loading, the query set, a way to override estimates, timeouts?

Which later work on learned or robust cardinality estimation would you read, and which JOB-based results would you re-check?