AQORA: A Fast Learned Adaptive Query Optimizer with Stage-Level Feedback for Spark SQL

Jiahao He, Yutao Cui, Cuiping Li, Jikang Jiang, Yuheng Hou, Hong ChenarXiv 2025 · DOI

Introduction

In the realm of big data, query optimization serves as the critical "brain" of the database, determining the most efficient sequence of joins and filters to process massive datasets. Traditional optimizers, however, often struggle with the "optimize-then-execute" paradigm, where decisions are finalized before a single row of data is processed. LQRS (Learned Query Re-optimization) is a novel reinforcement learning framework for Spark SQL that breaks this mold. By leveraging actual runtime data to re-optimize query plans while they are running, LQRS achieves up to a 90% reduction in execution time compared to state-of-the-art learned query optimizers.

Taxonomy of query optimization techniques, highlighting LQRS's unique role in both pre- and in-execution optimization.

The Challenge of Static Optimization

Traditional query optimizers rely on mathematical cost models to estimate the best execution path. These models frequently fail because they lack perfect information about real-world data distributions, leading to "guesses" that result in suboptimal performance. Recently, Learned Query Optimizers (LQOs) have emerged, using machine learning to improve these estimates based on historical execution data.

Despite their promise, most LQOs share a fundamental flaw: they make a final decision before the query starts. If a query discovers during execution that a table is significantly larger or smaller than predicted, a static plan becomes a performance bottleneck. LQRS addresses this by enabling in-execution re-optimization, allowing the system to pivot its strategy based on the "ground truth" observed at runtime.

The LQRS Framework

LQRS is built directly upon Spark SQL’s Adaptive Query Execution (AQE) framework, treating query optimization as a sequential decision-making process. It utilizes an Actor-Critic reinforcement learning approach to navigate the complex space of potential query plans.

The LQRS architecture featuring an Actor-Critic reinforcement learning model with TreeCNN for query plan encoding.

The system's technical core consists of several key components:

  • TreeCNN Architecture: A Tree-based Convolutional Neural Network encodes the hierarchical structure of query plans into vector representations, capturing the intricate relationships between database operations.
  • Stage-Level Feedback: Unlike traditional models that learn only from total execution time, LQRS receives feedback at every query stage—the boundaries where Spark shuffles data. This provides a feedback loop at least 3x denser than previous methods.
  • Action Space: The "Actor" model can choose from five distinct actions: initializing the plan, swapping leaf nodes, "leading" specific tables to the front of a join sequence, enforcing broadcast joins, or performing a no-op (no operation).
  • Curriculum Learning: To ensure training stability, the model follows a curriculum, first mastering simple initialization tasks before progressing to complex, mid-execution adjustments.

Evaluation and Results

The researchers evaluated LQRS using four industry-standard benchmarks: JOB (Join Order Benchmark), ExtJOB, STACK, and TPC-H (Scale Factor 100). To increase the challenge, the JOB dataset was expanded to 10x its original size.

LQRS consistently outperformed both standard Spark SQL and leading learned optimizers like Lero and AutoSteer. Key performance metrics include:

  • Execution Time Reduction: Total execution time was reduced by 16.3% to 73.3% across the benchmarks.
  • Peak Performance: On specific complex queries, such as STACK q13#1, execution time plummeted from over 300 seconds to just 41.94 seconds.
  • Operational Efficiency: LQRS demonstrated significantly lower optimization overhead. By making decisions based on actual runtime data rather than simulating thousands of "what-if" scenarios, it minimizes planning time in favor of execution.

Key Insights

The success of LQRS stems from the realization that runtime is reality. Even the most sophisticated pre-execution model is ultimately making an educated guess. By waiting until the initial stages of a query are complete, LQRS gains access to exact row counts, enabling it to correct suboptimal join orders that would otherwise cripple performance.

Furthermore, the inclusion of a no-op action is vital. It allows the model to remain conservative, intervening only when the potential performance gains clearly outweigh the overhead of re-planning. This synergy with Spark's built-in AQE allows LQRS to act as a "plug-and-play" extension, guiding existing re-optimization hooks with learned intelligence.

Conclusion and Future Directions

While LQRS represents a significant leap forward, challenges remain. In rare instances, the model can make "regressions" by incorrectly prioritizing tables, and the current action space excludes certain complex predicate types. Future work may involve moving toward offline RL with a comprehensive experience buffer to further stabilize model selection and improve reliability in diverse production environments.

Summary updated

BibTeX
@misc{he2025aqora,
  author = {Jiahao He and Yutao Cui and Cuiping Li and Jikang Jiang and Yuheng Hou and Hong Chen},
  title = {{AQORA: A Fast Learned Adaptive Query Optimizer with Stage-Level Feedback for Spark SQL}},
  year = {2025},
  eprint = {2510.10580},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.10580},
}
Figure