AlphaQO: Robust Learned Query Optimizer

Xiang Yu, Chengliang Chai, Xinning Zhang, Nan Tang, Ji Sun, Guoliang Li

Abstract

Learned Query Optimizers (LQOs) offer the potential for more accurate cost modeling in database systems but often suffer from a lack of robust training data. We present AlphaQO, a reinforcement learning framework that utilizes an adversarial training loop to improve LQO performance. By pairing a learned optimizer with a query generator that specifically targets its weaknesses, AlphaQO achieves superior generalization and data efficiency compared to traditional and state-of-the-art optimizers.

Introduction

Query optimization is a critical component of database engines, determining the most efficient execution plans for SQL queries. While traditional optimizers rely on manual cost models, recent research has shifted toward Learned Query Optimizers (LQOs) that use deep learning. However, these models are often fragile, requiring vast amounts of high-quality training data to handle complex, real-world workloads. Randomly generated queries often fail to challenge the optimizer, leading to poor performance on "long-tail" edge cases.

The AlphaQO Framework

AlphaQO addresses the data scarcity problem by treating query optimization as a competitive game between two reinforcement learning components. This closed-loop system ensures that the optimizer is constantly challenged by increasingly difficult queries.

The AlphaQO reinforcement learning loop, featuring an agent (query generator) and an environment (DBMS with learned optimizer).

The system consists of:

  1. The Query Generator (Agent): An LSTM-based network that constructs SQL queries step-by-step by navigating a graph representation of the database schema.
  2. The Learned Optimizer (Environment): The target system that executes generated queries and provides feedback.

The core innovation lies in the reward signal. The generator receives higher rewards when it produces queries that the learned optimizer handles significantly worse than a baseline (e.g., PostgreSQL). This adversarial pressure forces the generator to act as a "digital sparring partner," proactively finding and exposing the optimizer's blind spots.

Adversarial Query Generation

The query generation process is formalized as a graph-generation problem. The agent selects subgraphs and instantiates predicates to build valid SQL queries that are likely to be computationally expensive or difficult to optimize.

The two-step process of SQL query generation: subgraph enumeration followed by predicate instantiation.

By focusing on "hard" queries, AlphaQO avoids the inefficiency of random generation. In experiments, the generator learned to produce queries that were up to 10,000 times more difficult for the optimizer than random baselines within just 40 iterations.

Evaluation and Results

AlphaQO was evaluated using the IMDB dataset and the Join Order Benchmark (JOB). Key findings include:

  • Superior Performance: AlphaQO-trained optimizers outperformed the native PostgreSQL optimizer on the JOB dataset after seeing fewer than 100 targeted queries.
  • Data Efficiency: The framework reached performance levels with only 10% of a real-world workload that typically require 70% of the data when using standard training methods.
  • Robust Generalization: AlphaQO significantly outperformed other learned methods like ReJoin and DQ, particularly on unseen, complex query templates (JOB-EXT).

Conclusion

AlphaQO demonstrates that the quality of training data is more important than quantity for learned query optimizers. By using an adversarial RL loop, the system builds robustness against complex queries that typically degrade database performance. Future work will focus on expanding the framework to support more complex SQL features, such as subqueries and window functions, and testing its compatibility with a broader range of LQO architectures.

Summary updated

BibTeX
@article{yu2022alphaqo,
  author = {Xiang Yu and Chengliang Chai and Xinning Zhang and Nan Tang and Ji Sun and Guoliang Li},
  title = {{AlphaQO: Robust Learned Query Optimizer}},
  journal = {Int. J. Softw. Informatics},
  year = {2022},
  doi = {10.21655/ijsi.1673-7288.00275},
}
Figure