[Paper Review] Pay One, Get Hundreds for Free: Reducing Cloud Costs through Shared Query Execution
This paper proposes a SQL-level query rewriting technique to enable shared execution of multiple queries in cloud-based query-as-a-service systems like Amazon Athena and Google BigQuery, reducing costs by batching queries into a single execution. By reusing data access across queries without modifying the underlying engine, it achieves up to 107x cost reduction and 66x throughput improvement, with costs often matching that of a single query due to per-byte pricing.
Cloud-based data analysis is nowadays common practice because of the lower system management overhead as well as the pay-as-you-go pricing model. The pricing model, however, is not always suitable for query processing as heavy use results in high costs. For example, in query-as-a-service systems, where users are charged per processed byte, collections of queries accessing the same data frequently can become expensive. The problem is compounded by the limited options for the user to optimize query execution when using declarative interfaces such as SQL. In this paper, we show how, without modifying existing systems and without the involvement of the cloud provider, it is possible to significantly reduce the overhead, and hence the cost, of query-as-a-service systems. Our approach is based on query rewriting so that multiple concurrent queries are combined into a single query. Our experiments show the aggregated amount of work done by the shared execution is smaller than in a query-at-a-time approach. Since queries are charged per byte processed, the cost of executing a group of queries is often the same as executing a single one of them. As an example, we demonstrate how the shared execution of the TPC-H benchmark is up to 100x and 16x cheaper in Amazon Athena and Google BigQuery than using a query-at-a-time approach while achieving a higher throughput.
Motivation & Objective
- To reduce high execution costs in cloud-based query-as-a-service systems where users are charged per byte processed.
- To enable significant cost savings without modifying the underlying database engine or requiring cloud provider support.
- To explore the feasibility and benefits of shared query execution at scale using only SQL-level transformations.
- To demonstrate that batching queries via rewriting can achieve near-zero marginal cost for additional queries under existing pricing models.
Proposed method
- Rewriting multiple concurrent SQL queries into a single batched query using a nested, annotated representation to track which tuples belong to which original query.
- Using a middleware layer to group and rewrite queries transparently, without user or engine modification.
- Annotating intermediate results with query identifiers to enable selective output projection and shared execution at each operator.
- Constructing a global logical execution plan as a DAG to maximize sharing across diverse queries, especially for common joins and scans.
- Manually transforming the global plan into tree-structured plans to avoid cost-based optimization overhead, focusing on materializing high-impact intermediate results.
- Evaluating performance and cost using the TPC-H benchmark across Amazon Athena and Google BigQuery under various batch sizes and configurations.
Experimental results
Research questions
- RQ1Can shared query execution reduce cloud query costs in serverless, SQL-based query-as-a-service systems without engine modifications?
- RQ2To what extent can cost savings be achieved by batching queries through SQL-level rewriting rather than engine-level changes?
- RQ3How does shared execution impact throughput and execution time when queries access overlapping but not identical data?
- RQ4What is the trade-off between materializing common intermediate results and the resulting cost and performance gains?
- RQ5Can a single global execution plan outperform per-type grouping in terms of cost and throughput?
Key findings
- Using shared execution, the cost of running 128 TPC-H Query 6 instances in Amazon Athena was reduced from $3.417 to $0.028, achieving a 122x cost reduction and 66x throughput improvement.
- In Google BigQuery, the same workload achieved a 16x cost reduction (from $16.07 to $0.088) and 10x throughput improvement when Query 10 was excluded, reaching 128x savings.
- The global shared plan in BigQuery achieved a 5x throughput and 9.7x cost improvement over individual execution, with 21% of execution time spent on materializing shared intermediate results.
- Even with materialization overhead, shared execution costs remained nearly flat as batch size increased, due to the per-byte pricing model, making additional queries nearly free.
- The approach achieved up to 107x cost reduction in Amazon Athena and 128x in BigQuery when excluding non-optimizable queries, demonstrating the potential of SQL-level rewriting for cost reduction.
- The method is effective even for complex, non-identical queries by leveraging query-specific annotations and selective result projection.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.