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;
wherein 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;
wherein 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;
wherein a table to which the group keys belong is a group table and a table to which the columns used in performing the aggregation belong is an aggregation table;
wherein the first aggregation join is created under a situation that when both the tables are joined, the columns belonging to any one of the tables are selected as the group keys, and the group keys and the join keys do not match each other when the aggregation is performed with the columns belonging to the other table; and
wherein the first aggregation join is configured to;
designate the rows having the same join key as one group to produce each structure to store the aggregation for each designated group; and
calculate an aggregation value for the aggregation structure of the join key group relevant to the join key while searching the aggregation table in a way of calculating each join key group once only even though each join key group has several rows.
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.
24 Citations
15 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; wherein 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; wherein 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; wherein a table to which the group keys belong is a group table and a table to which the columns used in performing the aggregation belong is an aggregation table; wherein the first aggregation join is created under a situation that when both the tables are joined, the columns belonging to any one of the tables are selected as the group keys, and the group keys and the join keys do not match each other when the aggregation is performed with the columns belonging to the other table; and wherein the first aggregation join is configured to; designate the rows having the same join key as one group to produce each structure to store the aggregation for each designated group; and calculate an aggregation value for the aggregation structure of the join key group relevant to the join key while searching the aggregation table in a way of calculating each join key group once only even though each join key group has several rows. - View Dependent Claims (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
-
-
14. A non-transitory computer readable medium comprising machine readable instructions executable by a processor, the instructions comprising a query compiler, the 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; wherein 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; wherein 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; wherein a table to which the group keys belong is a group table and a table to which the columns used in performing the aggregation belong is an aggregation table; wherein the first aggregation join is created under a situation that when both the tables are joined, the columns belonging to any one of the tables are selected as the group keys, and the group keys and the join keys do not match each other when the aggregation is performed with the columns belonging to the other table; and wherein the first aggregation join is configured to; designate the rows having the same join key as one group to produce each structure to store the aggregation for each designated group; and calculate an aggregation value for the aggregation structure of the join key group relevant to the join key while searching the aggregation table in a way of calculating each join key group once only even though each join key group has several rows. - View Dependent Claims (15)
-
Specification