TL;DR
This paper introduces MRQO, a novel query optimization framework that combines Monte Carlo Tree Search (MCTS) for efficient join order exploration with Learning-to-Rank (LTR) for accurate query plan selection. MRQO aims to overcome the limitations of traditional methods in handling complex queries and large search spaces, demonstrating significant performance improvements over existing optimizers.
What Problem Does This Paper Address?
Database query optimization is crucial for efficient data retrieval, but traditional methods struggle with the exponential growth of possible join orders in complex queries. This challenge is exacerbated by intricate data distributions and the difficulty of accurately estimating query plan costs. Existing machine learning approaches, while promising, often face issues with training resource demands, potential inaccuracies in cost prediction, and limitations in exploring the vast search space effectively. The paper tackles the problem of finding a balance between exploring a comprehensive set of join orders and accurately selecting the best plan from them, aiming for higher efficiency and stability.
Methods
MRQO employs a two-pronged approach:
- Join Order Exploration with MCTS: Instead of exhaustively searching all join orders (an NP-hard problem), MRQO uses Monte Carlo Tree Search (MCTS) to intelligently explore the search space. MCTS balances exploration (trying new paths) and exploitation (focusing on promising paths) to identify a set of high-quality candidate join orders. This is guided by a value estimation network trained to predict the quality of join orders.
- Query Plan Selection with LTR: Once candidate join orders are identified, they are used as hints to generate query plans. MRQO then utilizes a Learning-to-Rank (LTR) model, specifically a Tree Convolutional Neural Network (TCNN), to rank these candidate plans. LTR transforms the problem from predicting exact costs (which can be error-prone) to a relative ranking problem, making it more robust and efficient. This approach also includes a plan generated by the original PostgreSQL optimizer as a baseline.
Datasets
The experiments were conducted on two widely-used public datasets:
- IMDB: A dataset derived from real-world data, comprising 21 tables related to movies, directors, actors, etc. It was used with its corresponding workload, JOB, which contains 113 query templates with varying predicate processing and join relationships (4-17 tables, averaging 8 joins).
- STATS: A dataset with 8 user contribution content tables, known for its complex data distribution. It was used with its workload, containing 146 query templates with different join sizes and types (2-8 tables, averaging 2-18 joins).
For training, 1000 new queries were generated for each dataset by randomly replacing predicates.
Key Insights and Ideas
- MCTS for Intelligent Exploration: Using MCTS to explore join orders is more efficient and less prone to random selection issues than purely random strategies, leading to better candidate join orders.
- LTR for Robust Plan Selection: Shifting from cost estimation to relative ranking with LTR significantly improves the stability and accuracy of selecting the optimal query plan, especially when dealing with complex queries where cost models might be less reliable.
- Synergy of MCTS and LTR: The combination of MCTS for generating diverse, high-quality candidate plans and LTR for their effective selection creates a powerful framework that leverages the strengths of both techniques.
- Candidate Plan Generation Strategy: Including a plan generated by the original optimizer alongside MCTS-hinted plans helps mitigate potential instability from MCTS alone and provides a strong baseline.
Key Results
- Performance Improvement: MRQO demonstrated significant performance improvements. For the JOB workload, it achieved a 54.1% improvement in time efficiency over PostgreSQL and 36.7% over AlphaJoin. For the STATS workload, it showed a 47.3% overall improvement compared to PostgreSQL and 33.8% over AlphaJoin.
- Tail Latency: MRQO showed superior performance in optimizing tail queries (complex queries with the highest execution times). For instance, at the 99th percentile, MRQO's execution time was 37.4 seconds compared to PostgreSQL's 54.7 seconds (a 31.6% improvement) on the IMDB dataset.
- Stability: MRQO consistently outperformed PostgreSQL and Lero, even with limited training data (50% of the workload), indicating its robustness.
Limitations and Future Work
- Training Data Dependency: While MRQO shows robustness, performance regression was observed when test workloads contained query features not present in the training data, a common challenge for machine learning models.
- MCTS Search Space Control: The paper mentions setting a maximum simulation count for MCTS to control the search space, implying that further tuning of these parameters could be beneficial.
- Future Work: The authors suggest that further research could explore more advanced LTR models and potentially integrate more sophisticated join order encoding techniques. The framework's ability to adapt to different database systems and workloads could also be a direction for future exploration.
Summary updated