A Learned Cost Model-based Cross-engine Optimizer for SQL Workloads

András Strausz, Niels Pardon, Ioana GiurgiuarXiv 2025 · DOI

Abstract

Modern data lakehouse architectures provide multiple specialized engines for SQL execution, yet selecting the most efficient engine for a specific query often requires manual expert intervention. This paper introduces a learned cost model (LCM) integrated into a cross-engine optimizer. By employing a multi-task Graph Neural Network (GNN) architecture with shared query embeddings and engine-specific predictor heads, the system can estimate costs across multiple engines simultaneously. Evaluation across diverse benchmarks demonstrates that this approach reduces total workload runtime by up to 30.4% compared to random routing, while maintaining high inference efficiency and adaptability to new engines.

Introduction

The evolution of data architectures toward "Lakehouse" systems, such as IBM’s watsonx.data, allows users to query the same data using various specialized engines (e.g., Presto for interactive queries, Spark for batch processing). However, choosing the optimal engine is non-trivial, as each possesses unique performance characteristics. Users often default to a single engine out of habit, leading to suboptimal resource utilization and higher operational costs. Existing learned cost models typically require training separate models for every engine configuration, which is computationally expensive and difficult to scale as new engines or hardware are added.

Methodology

The proposed cross-engine optimizer follows a three-stage workflow designed to bridge traditional query optimization with modern machine learning:

  1. Plan Creation: Raw SQL is transformed into an optimized logical plan using Apache Calcite. This plan includes join ordering and predicate pushdown and is decorated with cardinality hints before being serialized via the Substrait open standard.
  2. Plan Encoding: The serialized plan is converted into a vectorized graph representation where nodes represent relational operations (Join, Filter, etc.) enriched with metadata like row counts and data types.
  3. Multi-task GNN Architecture: A Bottom-up GNN processes the query tree to generate a shared embedding. This embedding is then fed into multiple "predictor heads"—small multi-layer perceptrons (MLPs)—each dedicated to a specific engine or hardware configuration (e.g., Spark with 4 workers vs. Presto with 8 workers).
System architecture overview showing SQL input, plan creation, and the ML-based cost estimation pipeline.

Experimental Evaluation

The system was evaluated on five diverse datasets: TPC-H, TPC-DS, IMDB (JOB), Stack Overflow, and Donor. To overcome the lack of training data in standard benchmarks, the authors utilized a synthetic query generator to produce thousands of training samples.

Key Results

  • Runtime Performance: In "zero-shot" scenarios (testing on unseen databases), the optimizer reduced runtime by 25.2% compared to random routing. With "few-shot" fine-tuning (using only 250 queries), this improvement reached 30.4%.
  • Estimation Accuracy: The model achieved a median Q-error of 1.21, meaning half of the predictions were within 21% of actual execution time.
  • Inference Efficiency: The overhead is minimal, with inference taking approximately 4.5ms per query on a GPU, which is negligible compared to the execution time saved.
Comparison of workload runtimes across different benchmarks (IMDB, Stack Overflow, TPC-H) showing the performance of Zero-shot and Few-shot models against random and static baselines.

Discussion and Future Work

A significant insight from the study was that using optimized logical plans as input reduced estimation errors by 12.6% compared to unoptimized plans, proving that traditional optimization techniques can significantly assist ML models. Furthermore, the multi-task learning approach allows the model to capture general SQL characteristics that benefit all engine predictors, making it highly extensible; adding a new engine only requires fine-tuning a new head rather than retraining the entire GNN.

Limitations include the reliance on synthetic query generation, which may not always reflect real-world human behavior. Future research will explore Reinforcement Learning for more realistic query generation and the inclusion of factors such as data movement and real-time engine load in the cost model.

Summary updated

BibTeX
@misc{strausz2025learned,
  author = {András Strausz and Niels Pardon and Ioana Giurgiu},
  title = {{A Learned Cost Model-based Cross-engine Optimizer for SQL Workloads}},
  year = {2025},
  eprint = {2506.02802},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.02802},
}
Figure