Optimizing database queries using subquery composition
First Claim
1. A computer implemented method for optimizing a database queries, the method comprising:
- Receiving, by a database system, a request to optimize a database query, the database query configured to process a plurality of records of a database table stored in the database systemIdentifying an inner subquery and an outer subquery in the database query, the inner subquery nested within the outer subquery, wherein each of the inner subquery and the out subquery specifies one or more expression representing results of the subquery;
Identifying an inner aggregate function in the one or more expressions representing results of the inner subquery and an outer aggregate function in the one or more expressions representing results of the outer subquery, wherein each aggregate function receives a plurality of input values and determines a numeric results by aggregating the plurality of input values;
Determining if the result of the inner aggregate function is provided as an input to the outer aggregate function;
Selecting a new aggregate function based on the inner aggregate function and the outer aggregate function if the result of the inner aggregate function is determined to be provided as an input to the outer aggregate functionGenerating a combined database query based on the outer subquery and the inner subquery, the combined database query specifying the new aggregate function; and
Storing the combined database query.
6 Assignments
0 Petitions
Accused Products
Abstract
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.
19 Citations
20 Claims
-
1. A computer implemented method for optimizing a database queries, the method comprising:
-
Receiving, by a database system, a request to optimize a database query, the database query configured to process a plurality of records of a database table stored in the database system Identifying an inner subquery and an outer subquery in the database query, the inner subquery nested within the outer subquery, wherein each of the inner subquery and the out subquery specifies one or more expression representing results of the subquery; Identifying an inner aggregate function in the one or more expressions representing results of the inner subquery and an outer aggregate function in the one or more expressions representing results of the outer subquery, wherein each aggregate function receives a plurality of input values and determines a numeric results by aggregating the plurality of input values; Determining if the result of the inner aggregate function is provided as an input to the outer aggregate function; Selecting a new aggregate function based on the inner aggregate function and the outer aggregate function if the result of the inner aggregate function is determined to be provided as an input to the outer aggregate function Generating a combined database query based on the outer subquery and the inner subquery, the combined database query specifying the new aggregate function; and Storing the combined database query. - View Dependent Claims (2, 3, 4, 5, 6, 7)
-
-
8. A non-transitory computer-readable storage medium storing instructions for:
-
Receiving, by a database system, a request to optimize a database query, the database query configured to process a plurality of records of a database table stored in the database system; identifying an inner subquery and an outer subquery in the database query, the inner subquery nested within the outer subquery, wherein each of the inner subquery and the outer subquery specifies one or more expressions representing results of the subquery; identifying an inner aggregate function in the one or more expressions representing results of the inner subquery and an outer aggregate function in the one or more expressions representing results of the outer subquery, wherein each aggregate function receives a plurality of input values and determines a numeric result by aggregating the plurality of input values; determining if the result of the inner aggregate function is provided as an input to the outer aggregate function; selecting a new aggregate function based on the inner aggregate function and the outer aggregate function if the result of the inner aggregate function is determined to be provided as an input to the outer aggregate function; generating a combined database query based on the outer subquery and the inner subquery, the combined database query specifying the new aggregate function; and storing the combined database query. - View Dependent Claims (9, 10, 11, 12, 13, 14)
-
-
15. A computer-implemented system, comprising:
-
a computer processor; and a non-transitory computer-readable storage medium storing instructions for; receiving, by a database system, a request to optimize a database query, the database query configured to process a plurality of records of a database table stored in the database system; identifying an inner subquery and an outer subquery in the database query, the inner subquery nested within the outer subquery, wherein each of the inner subquery and the outer subquery specifies one or more expressions representing results of the subquery; identifying an inner aggregate function in the one or more expressions representing results of the inner subquery and an outer aggregate function in the one or more expressions representing results of the outer subquery, wherein each aggregate function receives a plurality of input values and determines a numeric result by aggregating the plurality of input values; determining if the result of the inner aggregate function is provided as an input to the outer aggregate function; selecting a new aggregate function based on the inner aggregate function and the outer aggregate function if the result of the inner aggregate function is determined to be provided as an input to the outer aggregate function; generating a combined database query based on the outer subquery and the inner subquery, the combined database query specifying the new aggregate function; and storing the combined database query. - View Dependent Claims (16, 17)
-
-
18. A computer-readable non-transitory storage medium storing computer-executable code for optimizing queries of a database system, the code, when executed by a processor, causing the processor to:
-
receive, by a database system, a request to optimize a database query; identify an inner subquery and an outer subquery in the database query, the inner subquery nested within the outer subquery; determine that the inner subquery specifies a first where clause that computes a first set of values; determine that the outer subquery specifies a second where clause that computes a second set of values; compare the first set of values with the second set of values; and determine that the second set of values is a subset of the first set of values; determine whether a result of the inner subquery is provided as an input to the outer subquery; generate a combined database query corresponding to a composition of the outer subquery and the inner subquery if the result of the inner subquery is determined to be an input to the outer subquery and the second set of values is determined to be a subset of the first set of values, the combined database query having the second where clause; and store the combined database query. - View Dependent Claims (19, 20)
-
Specification