JOIN TYPE FOR OPTIMIZING DATABASE QUERIES
First Claim
1. A method for optimizing database queries in a query compiler, comprising:
- searching a subquery within a query;
analyzing the searched subquery to identify a candidate of a scalar subquery;
analyzing the candidate scalar subquery to identify a candidate of a correlated scalar subquery; and
transforming the query having the candidate correlated scalar subquery into a query of a quasi-JOIN depending on a result type of the candidate correlated scalar subquery,wherein the quasi-JOIN is a join to process grouping and aggregation, in which Group by Aggregation and Join that is a lower node of the Group by Aggregation are merged together and the quasi-JOIN includes a first aggregation join in which join keys and group keys do not match each other and a second aggregation join in which join keys and group keys match each other; and
the first aggregation join creates a result in which the group keys are partially grouped and subjected to Aggregation when the join keys and the groups have a matching condition, wherein the results for the rows with the group keys that are duplicated are grouped at a Group by Aggregation that is an upper node;
the second aggregation join returns a result in which the group keys are grouped and subjected to Aggregation when the join keys and the groups have a matching condition.
3 Assignments
0 Petitions
Accused Products
Abstract
A query complier analyzes a query to identify a correlated scalar subquery. The query complier transforms the query having the correlated scalar subquery into a query of AGGREGATION INNER/OUTER JOIN or MAX1ROW INNER/OUTER JOIN depending on a result type of the correlated scalar subquery. The AGGREGATION INNER/OUTER JOIN performs JOIN on the rows of the correlated scalar subquery with the rows of a main query and AGGREGATE on the joined rows and returns a result of the joined rows of the main query and aggregation value thereof. The MAX1ROW INNER/OUTER JOIN performs JOIN on the rows of the correlated scalar subquery with the rows of a main query, raises Error when the number of joined rows of the subquery is two or more and returns a result of the row of the main query and the joined row of the subquery.
-
Citations
18 Claims
-
1. A method for optimizing database queries in a query compiler, comprising:
-
searching a subquery within a query; analyzing the searched subquery to identify a candidate of a scalar subquery; analyzing the candidate scalar subquery to identify a candidate of a correlated scalar subquery; and transforming the query having the candidate correlated scalar subquery into a query of a quasi-JOIN depending on a result type of the candidate correlated scalar subquery, wherein the quasi-JOIN is a join to process grouping and aggregation, in which Group by Aggregation and Join that is a lower node of the Group by Aggregation are merged together and the quasi-JOIN includes a first aggregation join in which join keys and group keys do not match each other and a second aggregation join in which join keys and group keys match each other; and the first aggregation join creates a result in which the group keys are partially grouped and subjected to Aggregation when the join keys and the groups have a matching condition, wherein the results for the rows with the group keys that are duplicated are grouped at a Group by Aggregation that is an upper node; the second aggregation join returns a result in which the group keys are grouped and subjected to Aggregation when the join keys and the groups have a matching condition. - View Dependent Claims (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
-
-
16. A query compiler, comprising:
-
a parser configured to parse a query provided to the query compiler; a query rewriter configured to analyze the parsed query to identify a correlated scalar subquery, and transform the query having the identified correlated scalar subquery into a query of a quasi-JOIN according to a result type of the identified correlated scalar subquery; and a query optimizer configured to make a plurality of execution plans from the transformed query of a quasi-JOIN using statistical information, and select a query execution plan having a minimum cost among the plurality of execution plans, wherein the quasi-JOIN is a join to process grouping and aggregation, in which Group by Aggregation and Join that is a lower node of the Group by Aggregation are merged together and the quasi-JOIN includes a first aggregation join in which join keys and group keys do not match each other and a second aggregation join in which join keys and group keys match each other; and the first aggregation join creates a result in which the group keys are partially grouped and subjected to Aggregation when the join keys and the groups have a matching condition, wherein the results for the rows with the group keys that are duplicated are grouped at a Group by Aggregation that is an upper node; and the second aggregation join returns a result in which the group keys are grouped and subjected to Aggregation when the join keys and the groups have a matching condition. - View Dependent Claims (17, 18)
-
Specification