Abstract
Modern distributed computing frameworks like Apache Spark often execute redundant computations when multiple users submit similar queries. This paper introduces a novel Multi-Query Optimization (MQO) approach that identifies common subexpressions and caches their combined results in memory. By framing cache admission as a Multiple-Choice Knapsack Problem (MCKP), the system optimizes cluster throughput within strict memory limits. Experimental results demonstrate that this approach can reduce query execution times by up to 80% with minimal overhead.
Introduction
In large-scale data analytics clusters, it is common for different users to submit queries that perform overlapping tasks, such as scanning the same base tables or applying similar filters. Traditional distributed frameworks often optimize these queries in isolation, leading to significant waste of compute and I/O resources. While Multi-Query Optimization (MQO) is a well-studied topic in relational databases, its application to in-memory caching in distributed environments poses unique challenges, primarily due to the high cost and limited availability of RAM. This research addresses the problem of selecting the most beneficial intermediate results to cache to maximize performance gains without exceeding memory capacity.
Methodology
The proposed MQO component for SparkSQL follows a four-stage pipeline to optimize batches of concurrent queries:
- Subexpression Identification: Logical query plans are converted into modified Merkle trees. Cryptographic hashes are used to "fingerprint" sub-trees, enabling rapid identification of structural similarities. The system specifically targets "cache-friendly" operators, avoiding massive joins that might exhaust memory.
- Covering Expressions (CE): To handle queries that are similar but not identical (e.g., different filter predicates on the same column), the system constructs "Covering Expressions." These merge disparate predicates into a single intermediate result that can serve multiple queries.
- Cost-Based Selection: Cache admission is modeled as a Multiple-Choice Knapsack Problem (MCKP). Each candidate CE has an associated value (estimated time saved) and weight (RAM footprint). A dynamic programming solver identifies the optimal set of CEs to materialize.
- Query Rewriting: Original queries are modified to read from the cached relations instead of recomputing from source data.
Experimental Evaluation
The system was evaluated using a prototype built on Apache Spark 2.0 and tested with a subset of 50 TPC-DS queries on an 8-node cluster. The dataset was generated with a scaling factor of 50.
Key Results
The optimization strategy yielded substantial performance improvements:
- Query Speedup: Approximately 82% of queries saw a reduction in runtime. Notably, 60% of the queries achieved an 80% reduction in execution time.
- Aggregate Efficiency: In a windowed execution scenario (batching 20 queries), the system achieved a 45% reduction in median runtime and a 20% reduction in total aggregate runtime.
- Low Overhead: The optimization process, including the MCKP solver, typically completed in under 2 seconds, making it highly efficient for real-time cluster management.
Discussion and Future Work
While the current implementation provides significant gains, several areas for improvement remain. The current model uses a strict 0/1 knapsack approach, whereas Spark's ability to spill to disk suggests that a fractional knapsack formulation might be more flexible. Additionally, the batching process introduces queuing delays for early-arriving queries; future research will investigate the optimal balance between these delays and the resulting execution efficiency. Finally, expanding the set of sharable operators to include joins and unions could further enhance the optimization potential.
Summary updated