Cost-Based Query Optimization via AI Planning

Nathan Robinson, Sheila A. McIlraith, David Toman

Abstract

Join-order optimization is a fundamental NP-hard problem in relational database management systems (RDBMS). Traditional optimizers typically employ dynamic programming or branch-and-bound search. This paper re-evaluates join-order selection as an AI automated planning task. By introducing a logical state encoding and integrating production-quality relational cost models, we demonstrate that modern AI planning techniques can effectively find optimal or near-optimal query execution plans for complex relational queries.

Introduction

In relational databases, the "Query Optimizer" is responsible for selecting the most efficient execution path for a given SQL query. A core challenge is join-order selection—deciding the sequence in which tables are joined and which indices are utilized. While AI planning has been proposed for this task in the past, previous efforts often relied on simplified rewriting rules that ignored physical data properties such as table sizes and disk I/O costs. This work addresses these limitations by incorporating System-R style cost models directly into the planning process.

Methodology

The proposed approach bridges AI planning and database theory through two primary innovations:

  1. Logical State Encoding: Instead of encoding the physical structure of a query plan into the state, the planner encodes the logical progress achieved (e.g., "ID and Name retrieved from Table A"). This allows the planner to recognize when different join sequences lead to the same logical state, facilitating more effective pruning of suboptimal paths.
  2. Context-Sensitive Cost Models: Unlike standard planning where actions have fixed costs, database join costs depend on the size of input relations, which vary based on preceding operations. The authors implement a "lazy" cost calculation based on the current state's physical properties.

The study evaluates three main algorithmic strategies:

  • Delete-Free Exploration (DF): A fast, greedy approach for finding initial solutions.
  • A* Search: An optimal search utilizing domain-specific admissible heuristics, most notably $h_{admissLA}$ (one-step lookahead).
  • Greedy Best-First Search (GR): A heuristic-driven approach balancing search speed and plan quality.

Experimental Results

The performance of the planning-based optimizer was tested using generated random schemata and complex conjunctive queries.

Scalability and Optimality

The A* planner, particularly when paired with the $h_{admissLA}$ heuristic, showed significant capability in solving problems with up to 10 relations optimally and scaling further within reasonable time limits.

Percentage of problems solved optimally vs. number of relations for various algorithms and V/R ratios.

As illustrated in Figure 1, the percentage of problems solved optimally decreases as the number of relations increases. However, the choice of heuristic and the ratio of variables to relations (V/R) significantly influence the planner's success rate.

Anytime Performance

For interactive query scenarios, the speed of finding a "good enough" plan is paramount. The DF and Gr(admissLA) algorithms excel in this regard, often finding near-optimal plans almost instantaneously.

Convergence of solution quality over time for the DF and Gr(admissLA) algorithms across multiple problem instances.

Figure 3 demonstrates the convergence behavior of these algorithms. Both DF and Gr(admissLA) rapidly reduce the ratio of solution quality to optimal, frequently reaching near-optimal levels (ratio ≈ 1) within a fraction of a second.

Conclusion

This research demonstrates that AI planning is a viable and powerful framework for cost-based query optimization. By focusing on logical achievements and integrating realistic cost models, planners can navigate the vast search space of join orders effectively. Future work will explore the inclusion of "bushy" plans and more sophisticated statistical cost models to further align with modern industrial RDBMS requirements.

Summary updated

BibTeX
@inproceedings{robinson2014cost,
  author = {Nathan Robinson and Sheila A. McIlraith and David Toman},
  title = {{Cost-Based Query Optimization via AI Planning}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2014},
  doi = {10.1609/aaai.v28i1.9045},
}
Figure