TL;DR
This paper introduces Kepler, a novel learning-based system that significantly speeds up parameterized queries by intelligently generating and selecting query plans. By bypassing traditional, often inaccurate, query optimizer cost models and leveraging actual execution data, Kepler achieves substantial performance improvements while maintaining robustness against regressions.
What Problem Does This Paper Address?
Databases frequently execute parameterized queries, which are queries with the same structure but varying input values. Optimizing these queries is crucial for performance, as they are run repeatedly. Traditional query optimizers rely on cost models to choose the best execution plan, but these models are often inaccurate, leading to suboptimal performance. Existing approaches to address this, like parametric query optimization (PQO), primarily focus on reducing query planning time rather than improving execution performance. Furthermore, many machine learning-based query optimization techniques suffer from high inference times, inconsistent performance, and a significant risk of performance regressions, making them unsuitable for production environments. This paper tackles the challenge of optimizing parameterized queries by simultaneously improving both query planning and execution performance in a robust and efficient manner.
Methods
Kepler employs a two-pronged approach:
- Row Count Evolution (RCE): This is a novel candidate plan generation algorithm. Instead of relying on the optimizer's potentially flawed cardinality estimates, RCE generates a diverse set of candidate plans by "perturbing" these estimates. It does this by iteratively modifying sub-plan cardinalities and feeding these modified estimates back into the database's query optimizer to generate new plans. This evolutionary process aims to discover plans that are significantly better than the optimizer's default.
- Robust Machine Learning Models: Kepler uses these generated candidate plans and actual query execution data to train machine learning models. These models learn to predict the best plan for a given query instance based on its parameter values. To ensure robustness and avoid performance regressions, Kepler utilizes Spectral-normalized Neural Gaussian Processes (SNGPs), which provide uncertainty estimates. If the model's confidence in its prediction is low, Kepler falls back to the database's default optimizer.
Datasets
The paper uses two primary datasets:
- TPC-H: A standard benchmark with uniform and skewed data distributions.
- Stack: A dataset derived from real-world StackExchange data, augmented with additional query templates.
The authors also release a dataset comprising approximately 14.2 years of CPU time from 200 million query executions across 131 query templates, intended to facilitate future research.
Key Insights and Ideas
- Optimizer Inaccuracies are a Major Bottleneck: The paper strongly suggests that even well-established optimizers like PostgreSQL have significant room for improvement, particularly in cardinality estimation. Kepler's success hinges on its ability to bypass these inaccuracies.
- Candidate Generation is Key: The novel RCE algorithm demonstrates that generating a rich set of candidate plans is more effective than solely relying on the optimizer's single best guess. RCE's ability to explore the plan space by perturbing cardinalities is a significant contribution.
- Robustness is Paramount: The risk of performance regressions is a major hurdle for ML in production systems. Kepler's use of SNGPs for uncertainty estimation and a fallback mechanism to the default optimizer is crucial for achieving reliable speedups.
- Parameter Sensitivity Matters: The study highlights that many parameterized queries are highly sensitive to parameter values, meaning different inputs can lead to vastly different optimal plans. This justifies the need for per-query or per-template optimization.
Key Results
- Overall Speedup: Kepler achieves an overall geometric mean speedup of 2.41x on the Stack benchmark.
- RCE Performance: RCE alone provides significant speedups, achieving over 2x speedup on 32.2% of queries in PostgreSQL. It also discovers plans that are often faster than those generated by exact cardinality matching.
- ML Model Performance: Kepler's ML models capture a substantial portion of the speedup generated by RCE (over 80% on most Stack queries) while minimizing regressions.
- Low Inference Overhead: The ML model inference time is negligible, typically less than 5% of PostgreSQL's planning time.
- Robustness: The fallback mechanism significantly reduces regression frequency, with only a small sacrifice in speedup.
Limitations and Future Work
- Training Data Cost: The current training data collection process is computationally expensive (39 CPU days per query template). The authors suggest future work on more efficient training strategies, such as active learning.
- Static Workloads: Kepler's current implementation assumes relatively static system states (database configuration, data distribution). While it has some robustness to dynamic workloads via fallback, more advanced adaptation mechanisms could be explored.
- DBMS Independence: While Kepler's empirical approach is believed to be DBMS-agnostic, it has only been evaluated on PostgreSQL. Extending to other database systems is a natural next step.
- Feature Engineering: Future work could explore augmenting model features with query plan trees and selectivity estimates, and leveraging shared structures between similar query templates.
- Generative Cardinality Models: Incorporating generative cardinality models (like NeuroCard) could improve RCE's sampling efficiency.
Summary updated