Database Query Subquery Composition for Performance Optimization
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Database systems face inefficiencies in optimizing complex queries due to the presence of multiple subqueries, which leads to suboptimal plan generation and poor performance, as they struggle to identify and reuse equivalent subqueries effectively.
Innovation Solution
The system optimizes database queries by identifying and composing subqueries, determining a new aggregate function based on the inner and outer aggregate functions, and generating a combined query that reuses computations, thereby eliminating duplicated efforts across subqueries.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Productivity
If the database system executes complex queries with multiple nested subqueries as provided by users, then the query functionality is preserved, but the query execution performance deteriorates due to inability to effectively optimize and reuse equivalent subqueries
Solution Approach 1:
The patent combines multiple equivalent subqueries into a single executed subquery by identifying semantic equivalence through expression composition analysis. When the optimizer detects that different subqueries compute the same expression (e.g., nested aggregate functions like SUM(SUM(x)) that can be simplified to SUM(x)), it merges them into one execution unit, eliminating redundant computations while preserving the original query's functional requirements.
Solution Approach 2:
The patent performs preliminary optimization analysis during the query planning phase before execution. The optimizer pre-identifies equivalent subqueries by analyzing their expression structures and determines which subqueries can be composed or eliminated. This preliminary detection and rewriting of equivalent subqueries into a streamlined form occurs before the actual query execution, preventing redundant computations from occurring in the first place.
2Productivity
If the database system performs comprehensive optimization analysis on complex queries, then query execution efficiency improves, but the optimization process itself becomes more complex and computationally intensive
Solution Approach 1:
The patent segments the query optimization process into distinct analytical phases: parsing the query into an expression tree, identifying subquery boundaries, analyzing aggregate function compositions, detecting semantic equivalence, and generating optimized query plans. This segmentation allows the optimizer to systematically handle complex queries by breaking them down into manageable analysis steps, making the optimization process more tractable and efficient.
Solution Approach 2:
The patent changes the parameter representation of query expressions by transforming nested aggregate functions into their composed equivalents (e.g., changing SUM(SUM(x)) to SUM(x)). This parameter transformation simplifies the expression structure while preserving semantic meaning, enabling the optimizer to work with simplified representations that reduce computational complexity during the optimization analysis phase.
Data Source
AI summary
A database system optimizes database queries that comprise subqueries. The database system factors out computation from two or more subqueries to a reusable subquery. The reusable subquery returns a result set. The subqueries are rewritten to use the result set and the database query modified to use the rewritten subqueries. The modified database query performs efficiently since the result set is computed only once for each subquery that uses the reusable query. The database system also composes nested subqueries that compute aggregate values. The database system identifies an inner subquery nested within an outer subquery, each subquery computing an aggregate value. The database system determines a new aggregate function corresponding to a composition of aggregate functions of the inner and the outer queries. The database system determines a composed query using the inner query with the outer query. The composed query uses the new aggregate function.


