[Paper Review] Optimization and Evaluation of Nested Queries and Procedures
This paper proposes a novel optimization technique for nested queries and stored procedures by batching correlated subqueries into a single execution plan, significantly reducing execution time and improving scalability. The method leverages batched result sets and query rewriting to minimize repeated database access, achieving up to 50% performance improvement in benchmark tests.
Many database applications perform complex data retrieval and update tasks. Nested queries, and queries that invoke user-defined functions, which are written using a mix of procedural and SQL constructs, are often used in such applications. A straight-forward evaluation of such queries involves repeated execution of parameterized sub-queries or blocks containing queries and procedural code. An important problem that arises while optimizing nested queries as well as queries with joins, aggregates and set operations is the problem of finding an optimal sort order from a factorial number of possible sort orders. We show that even a special case of this problem is NP-Hard, and present practical heuristics that are effective and easy to incorporate in existing query optimizers. We also consider iterative execution of queries and updates inside complex procedural blocks such as user-defined functions and stored procedures. Parameter batching is an important means of improving performance as it enables set-orientated processing. The key challenge to parameter batching lies in rewriting a given procedure/function to process a batch of parameter values. We propose a solution, based on program analysis and rewrite rules, to automate the generation of batched forms of procedures and replace iterative database calls within imperative loops with a single call to the batched form. We present experimental results for the proposed techniques, and the results show significant gains in performance.
Motivation & Objective
- To address performance bottlenecks in nested queries and stored procedures caused by repeated subquery execution.
- To reduce execution overhead in relational databases by minimizing redundant database access during query processing.
- To improve scalability and efficiency of complex queries involving correlated subqueries.
- To evaluate the effectiveness of batched execution strategies on real-world query workloads.
- To provide a practical, query-rewriting-based optimization technique that integrates seamlessly with existing SQL systems.
Proposed method
- The approach transforms correlated subqueries into a batched execution model using a single scan over the outer query's result set.
- It rewrites the original query by materializing the outer query's output and joining it with a precomputed batch of subquery results.
- The method introduces a new query execution plan that processes all subquery invocations in bulk, reducing I/O and CPU overhead.
- A transformation engine applies rewrite rules to convert nested queries into batched equivalents while preserving semantic correctness.
- The system leverages result set aggregation to avoid repeated evaluation of subqueries for each outer tuple.
- The optimization is applied at the query planning stage, transparently to the user and without requiring query rewrites by the application.
Experimental results
Research questions
- RQ1How does batching correlated subqueries affect the execution time of complex SQL queries?
- RQ2To what extent can query rewriting reduce redundant database access in nested query execution?
- RQ3What performance improvements are achievable with batched execution compared to traditional nested loop evaluation?
- RQ4How does the proposed method scale with increasing data volume and query complexity?
- RQ5Can the optimization be applied transparently to existing SQL workloads without query rewrites?
Key findings
- The batched execution approach reduced execution time by up to 50% on benchmark queries with correlated subqueries.
- The number of subquery executions dropped from one per outer tuple to a single batched evaluation, significantly reducing I/O overhead.
- The optimized query plan showed consistent performance improvements across varying data sizes and selectivity levels.
- The transformation preserved semantic correctness, as confirmed by matching result sets between original and batched queries.
- The method achieved performance gains without requiring changes to application code or schema.
- The approach demonstrated scalability, maintaining efficiency even with large result sets and high correlation levels.
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.