TL;DR
This paper introduces Neo, the first end-to-end learned query optimizer that uses deep neural networks to generate query execution plans. Neo learns from experience, adapts to data patterns, and achieves performance comparable to, and sometimes exceeding, state-of-the-art commercial optimizers, significantly reducing the need for manual tuning.
What Problem Does This Paper Address?
Query optimization is a critical but notoriously complex component of database systems. Traditional query optimizers are often hand-tuned, require extensive engineering effort, and struggle to adapt to evolving workloads and data distributions. While previous research has explored machine learning for specific aspects like cardinality estimation or join ordering, no system has successfully learned an entire query optimizer. This gap leaves many open-source databases with suboptimal performance compared to their commercial counterparts, limiting efficiency and scalability.
Methods
Neo is a novel learning-based query optimizer that leverages deep neural networks. Its core components include:
- Learning from Demonstration & Reinforcement Learning: Neo bootstraps its knowledge from an existing, potentially simpler, query optimizer (like PostgreSQL) to learn initial "expert" plans and their performance. It then continuously improves through reinforcement learning, learning from its own successes and failures on incoming queries.
- Neural Network-based Value Model: Instead of hand-crafted cost models, Neo uses a deep neural network (the "value network") to predict the cost (latency) of query execution plans. This network is trained on collected experience (plan/latency pairs).
- Tree Convolution for Plan Representation: To process the hierarchical structure of query execution plans, Neo employs tree convolution, a technique adapted from image processing, allowing it to learn local patterns and relationships within the plan structure.
- Feature Engineering for Queries and Plans: Neo represents queries and their partial execution plans using sophisticated feature encodings. Notably, it introduces "R-Vectors" (Row Vectors), inspired by word embeddings, to capture semantic correlations within the database, going beyond simple statistical features.
- DNN-Guided Search Strategy: The learned value model guides a best-first search through the vast space of possible query plans, efficiently identifying promising candidates.
Datasets
Neo was evaluated on three distinct datasets:
- JOB: A benchmark designed with complex predicates and queries over the Internet Movie Data Base (IMDB), known for its rich semantic correlations.
- TPC-H: A standard industry benchmark, used with a scale factor of 10.
- Corp: A large, 2TB proprietary dataset from a corporate dashboard application, representing real-world usage.
For initial training, Neo always used PostgreSQL as the "expert" optimizer to generate demonstration data.
Key Insights and Ideas
- End-to-End Learning is Achievable: The paper demonstrates that it's feasible to learn an entire query optimizer, encompassing join ordering, physical operator selection, and index selection, rather than just isolated components.
- Bootstrapping is Crucial for Efficiency: Learning from an existing optimizer significantly speeds up the training process, reducing it from days/weeks to hours, which is critical for practical adoption.
- Semantic Embeddings Capture Deeper Correlations: The R-Vector encoding, by capturing semantic relationships between database values, proves more effective than simpler encodings (like 1-Hot or Histograms) for improving query performance, especially on datasets with complex correlations.
- Robustness to Estimation Errors: Neo can learn to dynamically adjust its reliance on cardinality estimates based on their perceived accuracy, demonstrating a level of robustness not easily achieved by traditional optimizers.
- Adaptability to Optimization Goals: Neo's cost function can be tailored to optimize for different objectives (e.g., minimizing total workload latency vs. improving individual query performance), offering greater flexibility than static optimizers.
Key Results
- Performance Parity/Superiority: Neo consistently achieved performance comparable to, and in many cases superior to, state-of-the-art commercial query optimizers (Oracle, Microsoft SQL Server) on their native platforms, even when bootstrapped from a simpler optimizer like PostgreSQL.
- Significant Speedups: On the JOB workload, Neo generated plans that were 60% faster than PostgreSQL's native optimizer. For MS SQL Server and Oracle, Neo's plans were up to 10% faster on the JOB and Corp workloads.
- Generalization: Neo demonstrated good generalization to unseen queries within the same workload and even to entirely new query sets (Ext-JOB) after minimal additional training.
- Efficient Training: Neo achieved competitive performance within a few hours of training, making it practical for real-world deployment.
Limitations and Future Work
- Generalization to Unseen Schemas: While Neo generalizes to unseen queries, it currently does not generalize to entirely new database schemas. Future work aims to investigate methods for schema generalization, potentially using transfer learning.
- R-Vector Training Time: Training the R-Vector embeddings can be computationally expensive, especially for very large datasets. While the paper shows that the performance gains often justify the training time, further optimization of this process is desirable.
- Bootstrapping from Advanced Optimizers: The paper discusses the trade-offs of bootstrapping from more advanced commercial optimizers, which could lead to faster convergence but might reintroduce dependencies on complex, hand-engineered systems.
- Customization of Optimization Goals: While Neo can adapt to different optimization goals, future work could explore more fine-grained customization, such as prioritizing queries based on user-defined importance or directly incorporating Service-Level Agreements (SLAs).
Summary updated