Abstract
This paper proposes Query Optimizer as a Service (QOaaS), a vision for a centralized, standalone service that optimizes queries across diverse data engines in a unified LakeHouse ecosystem. By decoupling the "brain" of the database from its execution engine, the authors demonstrate how a single sophisticated optimizer can provide cross-engine optimizations and significant performance gains for engines like Spark. Experimental results on real-world production workloads show up to a 2x speedup on complex joins and an 8x improvement through automated ML-based tuning.
Introduction: The Monolithic Bottleneck
Traditionally, database engines are built as monoliths where storage, execution, and the Query Optimizer (QO) are tightly coupled. In the modern "LakeHouse" era, exemplified by platforms like Microsoft Fabric, this siloed approach is increasingly problematic. Multiple engines—such as Spark for data science and T-SQL for warehousing—now operate on the same data within a shared lake (OneLake).
Maintaining separate, bespoke optimizers for each engine is an engineering challenge and prevents global optimizations. For instance, Spark cannot easily leverage a materialized view created by a SQL engine. The authors identify a major gap: the lack of a centralized mechanism for cross-engine optimization and global, ML-driven tuning across an entire data ecosystem.
The QOaaS Architecture
The proposed solution is to move the QO out of the engine and into a remote service. This architecture relies on three key pillars:
- Substrait as the Lingua Franca: To communicate between the engine and the QO service, the system uses Substrait, an open-source, language-neutral specification for relational algebra. This allows query plans to be serialized, optimized by the service, and returned to the engine.
- The Unified Query Optimizer (UQO): The authors adapted the Cascades-based UQO—which powers Fabric DW and SQL Server—to optimize Spark queries.
- Layered Optimization: The prototype was tested in two versions: QOaaS-v1 (logical optimization only) and QOaaS-v2 (logical optimization plus physical implementation hints, such as Broadcast vs. Shuffle Joins).
Methodology and Evaluation
The researchers evaluated the QOaaS prototype using two primary workloads: TPC-H (10GB to 1TB) and MSSales, a massive internal production workload from Microsoft consisting of 627 tables and 5TB of Parquet data. MSSales is characterized by extremely complex, join-heavy queries.
To optimize the service, the authors integrated MLOS (Microsoft’s ML-based system optimization framework) and LlamaTune to automatically search for and tune the 60+ cost-model parameters that dictate optimizer decisions.
Key Results
The study successfully demonstrated that a SQL-style optimizer can effectively optimize Spark queries via Substrait.
- Performance Gains on Complex Joins: For 40-way joins in the MSSales workload, the QOaaS-v2 prototype improved performance by nearly 2x compared to the native Spark optimizer.
- Impact of Automated Tuning: By using MLOS to tune cost-model parameters for specific workloads, the authors achieved up to an 8x speedup on subsets of the MSSales data.
Discussion and Future Work
Decoupling the QO enables independent innovation, allowing developers to upgrade the "brain" of the database without downtime for the execution layer. However, several challenges remain:
- Transferability: Parameters optimized for TPC-H caused a 7x performance degradation on MSSales, highlighting the need for workload-specific tuning.
- Overhead and Semantics: Communication over RPC introduces latency, requiring efficient metadata caching. Additionally, capturing subtle semantic differences between engines in a universal format remains a significant technical hurdle.
Future work aims for multi-engine federation, where the QOaaS service splits a single query into sub-plans executed by the most efficient engine for each specific task.
Summary updated