Learned Query Optimizer in Alibaba MaxCompute: Challenges, Analysis, and Solutions

Lianggui Weng, Dandan Liu, Wenzhuang Zhu, Rong Zhu, Junzheng Zheng, Bolin Ding, Zhiguo Zhang, Jingren ZhouarXiv 2026

TL;DR

LOAM is a practical learned query optimization framework designed for large-scale, multi-tenant cloud data warehouses like Alibaba MaxCompute. By introducing statistics-free plan encoding, environment-aware cost modeling, and zero-execution model refinement, LOAM bridges the gap between theoretical machine learning models and production realities. Deployed on real-world production workloads, it achieves up to 30% CPU cost savings with negligible operational overhead.

What Problem Does This Paper Address?

Over the past decade, learned query optimizers (LQOs) have shown massive potential in research labs. By replacing or augmenting traditional cost models with machine learning, they can better capture complex data distributions and pick more efficient execution plans.

However, when you try to deploy these models in the wild—specifically in massive, distributed, multi-tenant cloud data warehouses like Alibaba MaxCompute—they break down due to four harsh production realities:

  1. Environment Variation: Unlike isolated testbeds, production clusters dynamically allocate resources from massive pools shared by thousands of tenants. This multi-tenant interference causes identical queries to experience up to a 50% fluctuation in CPU cost based on machine load.
  2. Missing Statistics: At exabyte scale, automatically maintaining up-to-date data statistics (like histograms) is prohibitively expensive. Optimizers must frequently fly blind without accurate data distribution info.
  3. Infeasible Model Refinement: Traditional LQOs learn by executing alternative "candidate" plans to see how well they perform. In a system where heavy queries routinely consume massive CPU cycles, running extra plans just for model training is unacceptably expensive and risky.
  4. Workload Heterogeneity: Data warehouses host hundreds of thousands of distinct user projects. A learned model that excels on one project might cause disastrous performance regressions on another.

The authors present the query execution workflow of MaxCompute and highlight these challenges in Figure 1.

Figure 1: Query execution workflow in MaxCompute.

Methods

To tackle these challenges, the authors introduced LOAM (Learned Query Optimization framework for MaxCompute). LOAM operates in a "steering" style: it guides the native optimizer to generate a diverse set of candidate plans and then uses an adaptive cost predictor to select the best one.

LOAM's architecture (shown in Figure 2) relies on several core innovations:

Figure 2: The framework of LOAM.
  • Statistics-Free Plan Encoding: Instead of relying on explicit data histograms, LOAM encodes operator attributes (like table identifiers via a custom collision-resistant hash encoding, and the number of partitions/columns accessed). This allows the model to implicitly infer data volume and distribution details purely from historical query patterns.
  • Environment-Aware Cost Modeling: LOAM explicitly incorporates dynamic machine load metrics (such as CPU idle time and system load) into its training phase. Because the exact environment is unknown at the time a query is optimized, LOAM utilizes a practical smoothing strategy: it evaluates all candidate plans under a representative, "average-case" system load condition.
  • Preemptive Generalization via Domain Adaptation: To avoid the high cost of executing extra candidate plans for model refinement, LOAM uses unsupervised domain adaptation. By training a domain classifier with a Gradient Reversal Layer (shown in Figure 3), LOAM forces its plan embedding layer to produce representations that are invariant to the differences between historical default plans and unseen candidate plans.
  • Automatic Project Selection: LOAM includes a two-stage pipeline to find the projects most likely to benefit from a learned optimizer. It first filters out unpromising projects using rule-based heuristics (e.g., insufficient query volume or highly unstable temporary tables) and then ranks the remaining projects using a lightweight XGBoost model.

Datasets

The framework was trained and evaluated using real production workloads from Alibaba Group's internal projects on MaxCompute. Out of a massive pool of over 100,000 projects, the authors applied their rule-based filter to workloads collected over three consecutive days, leaving a filtered set of roughly 40.5% of all projects. From this subset, they randomly sampled 30 projects and focused their deep end-to-end evaluations on the 5 projects (Projects 1–5) identified as having the highest potential optimization headroom. Training data was capped at 10,000 historical queries per project.

Key Insights and Ideas

  • The Monotonicity of Machine Load: The authors discovered that while multi-tenant noise makes cost prediction highly volatile, environmental features have a discernibly linear and monotonic influence on plan costs (illustrated in Figure 5). This insight justifies their practical inference strategy: evaluating plans under empirical mean conditions provides a fair and highly stable approximation of expected costs without requiring expensive Monte Carlo sampling.
Figure 5: CPU cost of a recurring query w.r.t. machine load.
  • Learning Statistics Implicitly: Production workloads are heavily driven by parameterized, template-based queries. By observing how minor changes in filtering predicates alter execution costs over time, the machine learning model can implicitly decode data selectivity and distributions without ever seeing an actual data histogram.
  • Refinement Without Execution: Traditional machine learning requires labels (actual execution costs) for candidate plans to generalize well. LOAM turns this into an adversarial game: it trains the model to predict costs accurately on historical data while simultaneously trying to trick a domain classifier into thinking candidate plans look exactly like default plans. This forces the model to generalize safely to new plan structures for free.

Key Results

  • Significant Cost Savings: LOAM consistently outperformed MaxCompute's native optimizer and other state-of-the-art learned baselines (like Transformer and GCN-based models). It achieved CPU cost savings of 10% on Project 1, 23% on Project 2, and 30% on Project 5.
  • Negligible Overhead: LOAM requires less than an hour of offline training time and has a tiny memory footprint of around 20 MB. At query time, generating candidate plans takes under 0.1 seconds, and model inference adds just 0.1 to 0.5 seconds per query—representing a tiny fraction (0.23%–0.74%) of total execution time.
  • Massive Fleet-Wide Potential: Extrapolating from their 30-project sample pool, the authors estimate that at least 4% of MaxCompute's 100,000+ projects would see performance gains of $\ge 10\%$, pointing to massive real-world resource and financial savings at cloud scale.

Limitations and Future Work

The primary limitation of LOAM is that its performance gains are fundamentally bounded by its current plan exploration strategies. To keep evaluation overhead manageable and safe in production, the plan explorer was restricted to toggling only 6 specific optimization flags and scaling cardinalities for subqueries. In some cases (like Project 1), the optimal candidate plan generated was only capable of a 15% improvement over the default plan. The authors note that incorporating more aggressive and diversified plan exploration strategies in the future could drastically improve LOAM's overall optimization ceiling.

Summary updated

BibTeX
@misc{weng2026learned,
  author = {Lianggui Weng and Dandan Liu and Wenzhuang Zhu and Rong Zhu and Junzheng Zheng and Bolin Ding and Zhiguo Zhang and Jingren Zhou},
  title = {{Learned Query Optimizer in Alibaba MaxCompute: Challenges, Analysis, and Solutions}},
  year = {2026},
  eprint = {2602.07336},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.07336},
}
Figure