Introduction
In the realm of database management systems (DBMS), the query optimizer serves as the central intelligence, responsible for translating declarative SQL queries into efficient execution plans. Traditionally, these optimizers have relied on a "Least Specific Cost" (LSC) approach. This strategy assumes that system parameters—such as available memory, data selectivity, and concurrent load—can be accurately predicted as single point-estimates.
This 1999 paper from Cornell University challenges this fundamental assumption. The authors argue that optimizing for the "average" or "most likely" case is inherently risky due to the non-linear nature of database performance. Instead, they propose a decision-theoretic framework that optimizes for Least Expected Cost (LEC), treating system parameters as random variables with associated probability distributions.
The Problem: The Fragility of Point Estimates
Standard optimizers are prone to two significant failures when relying on point estimates:
- The "Cliff" Problem: Database cost functions are rarely linear. For instance, a join operation might perform exceptionally well if it fits entirely in memory but suffer a 100x performance degradation if it spills to disk. If an optimizer assumes 10MB of RAM is available and the actual system state provides only 9.9MB, the chosen plan may hit a performance "cliff." LSC ignores the catastrophic risk of being slightly off-target.
- The Volatility Problem: System environments are dynamic. Parameters like the size of the buffer cache or the number of concurrent users can fluctuate during the execution of a long-running query. Traditional optimizers assume these values remain constant, leading to sub-optimal execution as the environment shifts.
Proposed Methodology: From Points to Distributions
The authors suggest that rather than picking a single value, the DBMS should model parameters as probability distributions. To find the LEC plan—the plan that performs best on average across all likely scenarios—the paper introduces three algorithmic approaches:
Algorithm A: The Black Box Approach
This method treats the existing optimizer as a black box. The parameter space is divided into "buckets" (e.g., low, medium, and high memory). The optimizer is run for each bucket, and the expected cost of each resulting plan is calculated across the entire distribution. The plan with the lowest overall expected cost is selected.
Algorithm B: Top-C Candidates
Recognizing that the best plan for a specific point might not be the best overall, Algorithm B modifies the optimizer to retain the "Top C" candidate plans for each scenario. This increases the likelihood of discovering a "robust" plan—one that might not be the absolute fastest in any single scenario but maintains high efficiency across the entire distribution.
Algorithm C: Modified System R
This is the paper’s primary contribution. The authors extend the classic System R dynamic programming algorithm. In the standard version, the algorithm discards all but the cheapest plan for every sub-goal. Algorithm C instead stores the plan with the lowest expected cost, calculated by integrating the cost function over the parameter's probability distribution at each step of the plan construction.
Theoretical Foundation and Results
While the paper is primarily theoretical, it utilizes analytical cost models for standard join algorithms (Sort-Merge, Grace Hash, and Nested-Loop) to validate its claims.
- Formal Proof: The authors provide a formal proof (Theorem 3.3) demonstrating that their modified dynamic programming approach successfully identifies the LEC left-deep plan.
- Computational Feasibility: A common concern with probabilistic modeling is computational overhead. The authors show that because join algorithms only have a few "regimes" of behavior (e.g., in-memory vs. multi-pass), the number of buckets required to represent the distribution is small, keeping the LEC calculation efficient.
- Risk Aversion: The LEC framework effectively makes the DBMS risk-averse. By maximizing expected utility (where utility is defined as the negative of cost), the optimizer naturally avoids plans that carry a high risk of catastrophic failure.
Limitations and Future Work
The paper acknowledges several areas for further development:
- Model Scope: The focus is largely on left-deep trees and does not account for the complexities of modern bushy trees or massive parallelism.
- Parameter Independence: The current multi-parameter model assumes that variables like memory and selectivity are independent. The authors suggest that Bayesian networks could eventually address correlations between these variables.
- Empirical Validation: The study lacks large-scale benchmarking on live database engines, leaving the exact trade-off between optimization overhead and runtime gains as a subject for future empirical research.
Conclusion
"Least Expected Cost Query Optimization" represents a foundational shift in how we think about database performance. By moving away from the fragile pursuit of the "perfect" plan for a single guess, and toward the selection of robust plans that survive environmental uncertainty, the authors laid the groundwork for more resilient and predictable database systems.
Summary updated