TL;DR
FOSS (a "plan-doctor") is a novel deep reinforcement learning framework that improves database performance by iteratively "fixing" suboptimal query plans generated by traditional optimizers. By combining a fine-grained refinement strategy with a simulated learning environment, FOSS achieves up to an 8.33x speedup over PostgreSQL while training significantly faster than previous state-of-the-art methods.
What Problem Does This Paper Address?
Query optimizers are the "brains" of a database, responsible for finding the most efficient way to execute a SQL query. However, traditional optimizers rely on mathematical models that often make mistakes in "cardinality estimation" (guessing how many rows a join will produce), leading to slow, suboptimal execution plans.
Recent machine learning approaches have tried to solve this in two ways:
- Plan-constructors: These build plans from scratch. They are flexible but incredibly slow to train because they have to "re-learn" basic database principles through trial and error.
- Plan-steerers: These use "hints" to nudge a traditional optimizer. They are faster to train but have a limited "search space"—they can only suggest broad changes, often missing the best possible plan.
FOSS addresses the efficiency-flexibility trade-off. It aims to be as smart as a constructor but as efficient as a steerer by acting as a "doctor" that starts with a traditional plan and surgically repairs its weakest parts.
Methods
The authors introduce a "whitebox-expertise" approach called FOSS, which consists of three main components:
- The Planner (The Doctor): A Deep Reinforcement Learning (DRL) agent. Instead of building a plan from scratch, it takes the plan from a traditional optimizer (like PostgreSQL) and performs a sequence of actions: swapping table positions or overriding join methods (e.g., changing a Hash Join to a Nested Loop Join).
- Asymmetric Advantage Model (AAM): A specialized neural network based on the Transformer architecture. It compares two different query plans and predicts which one is better without actually running them. This is crucial because executing queries to get "ground truth" latency is extremely time-consuming.
- Simulated Learner: Inspired by "Dyna-style" reinforcement learning, FOSS uses the AAM to create a simulated environment. The agent can "practice" in this simulation, generating thousands of high-quality experiences rapidly before ever touching the real database.
Datasets
The authors evaluated FOSS on three diverse and standard database benchmarks:
- Join Order Benchmark (JOB): Based on the real-world IMDb dataset (3.6GB). It is known for being particularly challenging due to complex correlations in the data.
- TPC-DS: A standard industry benchmark for decision support systems, scaled to 10GB.
- Stack Overflow: A large-scale dataset (100GB) containing 18 million questions and answers, representing a massive real-world workload.
Key Insights and Ideas
- Don't Reinvent the Wheel: The "Aha!" moment here is that traditional optimizers aren't totally broken; they are usually 90% correct. By starting with the traditional plan (addressing the "Learning from scratch" problem), FOSS reaches high performance much faster than agents that start from zero.
- The Power of Simulation: One of the biggest bottlenecks in ML for databases is the "latency wall"—waiting minutes for a query to finish just to get one data point for training. The AAM acts as a "proxy" for the database, allowing the agent to learn from "hallucinated" experiences that are statistically grounded in reality.
- Fine-Grained Control: Unlike "plan-steerers" that might disable a join type for an entire query, FOSS can change a single node in the plan tree. This "surgical" precision allows it to explore a much larger search space.
Key Results
- Massive Speedups: Compared to the standard PostgreSQL optimizer, FOSS achieved total latency speedups of 6.25x on JOB, 1.15x on TPC-DS, and 1.75x on Stack Overflow during training. On unseen test queries, the speedup reached as high as 8.33x.
- Superior to SOTA: FOSS consistently outperformed other leading ML optimizers like Bao, Balsa, Loger, and HybridQO in both execution speed and training efficiency.
- Rapid Convergence: On the TPC-DS and Stack Overflow workloads, FOSS converged to a high-performance state in about one hour, whereas previous methods often required significantly more time or failed to handle the complexity of the Stack Overflow dataset.
Limitations and Future Work
- Left-Deep Constraint: Currently, FOSS only considers "left-deep" join trees (a specific structure of query plans). While common, "bushy trees" can sometimes be more efficient for very large queries. The authors leave the expansion to bushy trees for future work.
- PostgreSQL Dependency: The current implementation relies on the
pg_hint_planextension to force the database to follow the agent's refined plans. - Static vs. Dynamic Data: While FOSS handles different queries well, the paper doesn't deeply explore how the model reacts to massive, real-time data updates (e.g., a database that grows by 50% every day), which might require retraining the AAM.
Summary updated