Abstract

A method for query processing includes receiving a query, and determining a query type by determining if the query is a structured query language (SQL) query including multiple distinct aggregates (MDAs), or a SQL query including cube, rollup or grouping sets operations. Based on the determination, the method includes processing the query to generate an output, and performing a predetermined number of maximum group by operations on the output based on the query type to generate a response to the query.

Claims

What is claimed is: 1 . A method for query processing, the method comprising: receiving a query; determining a query type by determining if the query is a structured query language (SQL) query including multiple distinct aggregates (MDAs), or a SQL query including cube, rollup or grouping sets operations; based on the determination, processing the query to generate an output; and performing, by a processor, a predetermined number of maximum group by operations on the output based on the query type to generate a response to the query. 2 . The method of claim 1 wherein the predetermined number of maximum group by operations is two if the query type is a SQL query including MDAs. 3 . The method of claim 1 , wherein the predetermined number of maximum group by operations is one if the query type is a SQL query including cube, rollup or grouping sets operations. 4 . The method of claim 1 , further comprising: if the query type is a SQL query including MDAs, generating inner and outer group by operations for the SQL query including MDAs. 5 . The method of claim 4 , wherein the inner group by operation includes no aggregates. 6 . The method of claim 4 , wherein the outer group by operation includes a determination of aggregates for the SQL query including MDAs. 7 . The method of claim 1 , further comprising: if the query type is a SQL query including the cube operation, generating groupings, where m is a number of grouping columns for the cube operation. 8 . The method of claim 1 , further comprising: if the query type is a SQL query including the rollup operation, generating m+1 groupings, where m is a number of grouping columns for the rollup operation. 9 . The method of claim I, further comprising: if the query type is a SQL query including the grouping sets operation, generating n groupings, where n is a number of grouping sets in the grouping sets operation. 10 . The method of claim 1 , further comprising: generating groupings to answer the query based on the query type. 11 . A query processing apparatus comprising: a memory storing a module comprising machine readable instructions to: receive a query; determine a query type by determining if the query is a structured query language (SQL) query including multiple distinct aggregates (MDAs), or a SQL query including cube, rollup or grouping sets operations; based on the determination, process the query to generate an output; and perform a single or two successive group by operations on the output based on the query type to generate a response to the query; and a processor to implement the module. 12 . The apparatus of claim 11 , further comprising machine readable instructions to: perform the two successive group by operations if the query type is the SQL query including MDAs. 13 . The apparatus of claim 11 , further comprising machine readable instructions to: generate inner and outer group by operations for a SQL query including MDAs. 14 . The apparatus of claim 11 , further comprising machine readable instructions to: perform the single group by operation if the query type is the SQL query including cube, rollup or grouping sets operations. 15 . A non-transitory computer readable medium having stored thereon machine readable instructions for query processing, the machine readable instructions when executed cause a computer system to: receive a query; determine a query type by determining if the query is a structured query language (SQL) query including multiple distinct aggregates (MDAs), or a SQL query including cube, rollup or grouping sets operations; based on the determination, process the query to generate an output; and perform, by a processor, two successive group by operation on the output if the query type is the SQL query including MDAs, or one group by operation on the output if the query type is the SQL query including the cube, rollup or grouping sets operations to generate a response to the query.
BACKGROUND [0001] Query processing with multiple distinct aggregates, cube, rollup, and grouping sets can include maintaining separate streams of groupings and then performing operations, such as group by, join, etc., on the streams to generate query results. The number of streams and the number of group by or join operations are proportional, for example, to the number of distinct aggregates in the query. This results in increased memory usage and thus increased expense as the number of distinct operations to respond to a query increases. This can further result in a distributed deadlock. BRIEF DESCRIPTION OF DRAWINGS [0002] Features of the present disclosure are illustrated by way of example and not limited in the following figure(s), in which like numerals indicate like elements, in which: [0003] FIG. 1 illustrates an architecture of a query processing apparatus, according to an example of the present disclosure; [0004] FIG. 2 illustrates a method for query processing, according to an example of the present disclosure; [0005] FIG. 3 illustrates further details of the method for query processing, according to an example of the present disclosure; and [0006] FIG. 4 illustrates a computer system, according to an example of the present disclosure. DETAILED DESCRIPTION [0007] For simplicity and illustrative purposes, the present disclosure is described by referring mainly to examples. In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present disclosure. It will be readily apparent however, that the present disclosure may be practiced without limitation to these specific details. In other instances, some methods and structures have not been described in detail so as not to unnecessarily obscure the present disclosure. [0008] Throughout the present disclosure, the terms “a” and “an” are intended to denote at least one of a particular element. As used herein, the term “includes” means includes but not limited to, the term “including” means including but not limited to. The term “based on” means based at least in part on. [0009] A query processing apparatus and method are described herein and provide for efficient answering of structured query language (SQL) queries with multiple distinct aggregates (IVIDAs), and SQL queries with cube, rollup or grouping sets operations. Generally, the query processing apparatus includes a query input module to receive a query. A query determination module determines whether the SQL query includes MDAs, or cube, rollup or grouping sets operations. Based on the determination, an intermediate processing module processes the From and Where clauses of the query and forwards the results to a group generator module. The group generator module generates groupings as an output specific to the query type. For a SQL query including MDAs, a SQL-MDA group by processing module performs two successive group by operations on the output of the group generator module to answer the query. For a SQL query including cube, rollup or grouping sets operations, a SQL cube, rollup and grouping sets group by processing module performs a single group by operation on the output of the group generator module to answer the query. [0010] The apparatus and method provide for the processing of intermediate results (or the results of intermediate groupings) that are generated during processing of SQL queries with MDAs, or cube, rollup or grouping sets operations. The number of group by operations that are needed to answer the foregoing query types are also bound. Furthermore, the intermediate results (i.e., the output of the group generator module) are maintained in a single stream, which eliminates the possibility of distributed deadlock. [0011] For a SQL query including MDAs, the number of group by operations used is two. Thus, for a SQL query including MDAs, the number of group by operations is independent of the number of distinct aggregates in the query and remains at two. For a SQL query including cube, rollup and grouping sets operations, the number of group by operations used is one. Since the number of group by operations are limited, the resources needed are also limited, and are therefore unrelated, for example, to the number of MDAs, or the number of keys in cube or rollup operations, or the number of sets in the grouping sets operation. [0012] FIG. 1 illustrates an architecture of a query processing apparatus 100 , according to an example. Referring to FIG. 1 , the apparatus 100 is depicted as including a query input module 102 to receive a query 104 . The query 104 may be a SQL query including MDAs, or a SQL query including cube, rollup or grouping sets operations. A query determination module 106 determines whether the SQL query includes MDAs, or cube, rollup or grouping sets operations, Based on the determination, an intermediate processing module 108 processes the query and forwards the results to a group generator module 110 . The group generator module 110 processes the query and the input from the intermediate processing module 108 to generate an output 112 for a SQL query including MDAs, or an output 114 for a SQL query including cube, rollup or grouping sets operations. For a SQL query including MDAs, a SQL-MDA group by processing module 116 performs two successive group by operations on the output 112 of the group generator module 110 to answer a query. For a SQL query including cube, rollup or grouping sets operations, a SQL cube, rollup and grouping sets group by processing module 118 performs a single group by operation on the output 114 of the group generator module 110 to answer a query. The answer to the query 104 is output at 120 by a query response module 122 . The query response module 122 also performs any additional processing needed based on the query type on the outputs of the SQL-MDA group by processing module 116 and the SQL cube, rollup and grouping sets group by processing module 118 . [0013] The modules 102 , 106 , 108 , 110 , 116 , 118 and 122 , and other components of the apparatus 100 may comprise machine readable instructions stored on a computer readable medium. In addition, or alternatively, the modules 102 , 106 , 108 , 110 , 116 , 118 and 122 , and other components of the apparatus 100 may comprise hardware or a combination of machine readable instructions and hardware. [0014] Generally, the group generator module 110 generates groupings used to answer the query 104 based on whether the SQL query includes MDAs, or cube, rollup or grouping sets operations. An example of a SQL query with MDAs for a Table 1 (i.e., Table foo) is as follows: [0000] TABLE 1 Table foo a b c integer integer integer [0015] A SQL query with MDAs (e.g., two distinct aggregations for the following example) may include: select a, sum(distinct b), count(distinct c) from foo group by a. A SQL query including cube, rollup and grouping sets operations allows for the performance of multi-level aggregations in a single query. An example of a SQL query including a cube operation for Table 1 may include: select a, b, sum(b) from foo group by cube(a, b). An example of a SQL query including a rollup operation for Table 1 may include: select a, b, sum(b) from foo group by rollup (a, b). Similarly, an example of a SQL query including a grouping sets operation for Table may include: select a, b, sum(b) from foo group by grouping sets (a, (b,c)). [0016] Generally, SQL queries including MDAs or cube, rollup or grouping sets operations use multiple groups that are formed and processed. For the foregoing example of a SQL query including MDAs, the query returns a sum of all unique values of b, and a count of all unique values of c, for each unique value of a. This operation is based on a determination of all unique values of b and c for each unique value of a, which uses the groupings (a, b} and (a, c}. For the foregoing example of a SQL query including a cube operation, the operation uses the groupings { }, {a}, {b}, {a, b}. For the foregoing example of a SQL query including a rollup operation, the operation uses the groupings { }, {a}, {a,b}. Further, for the foregoing example of a SQL query including a grouping sets operation, the operation uses the groupings {a}, {b,c}. As described in detail below, the query processing apparatus and method provide for the generation, propagation and processing of these different groupings. [0017] With regard to the processing of the foregoing SQL query with MDAs, the modules 110 and 116 apply the transformation shown below: [0000] select a, sum(b), count(c) from ( select a, b, c, grouping_id from ( select a, b, null as c, 0 as grouping_id from foo union all select a, null, c, 1 from foo ) group by a, b, c, grouping_id ) group by a [0018] The group generator module 110 thus implements the innermost subquery (i.e., select a, b. null as c, 0 as grouping id from foo union all select a, null, c, 1 from foo) in the foregoing transformation. The two outer select blocks (i.e., select a, b, c, grouping_id from (. . . ) group by a, b, c, grouping_id and select a, sum(b), count(c) from ( . . . ) group by a) present the two group by operations that are applied over the output 112 of the group generator module 110 by the SQL-MDA group by processing module 116 . [0019] For a SQL query with MDAs generally, the specification of the group generator module 110 and the two group by operations that are applied to the output 112 of the group generator module 110 by the SQL-MDA group by processing module 116 are described. [0020] With regard to the general specification of the group generator module 110 for handling SQL queries with MDAs, consider the following generalized SQL: [0021] select g 1 , . . . , g m , agg(a 1 ), . . . , agg(a k ), agg(distinct d 1 ), . . . , agg(distinct d n ) [0022] from < > [0023] where < > [0024] group by g 1 , . . . , g m [0000] The foregoing SQL query with MDAs contains m (m≧0) grouping columns (g 1 , . . . , g m ), k (k≧0) non-distinct aggregates, and n (n>1) distinct aggregates. Since operation of the group generator module 110 is independent of the contents of the foregoing From and Where clauses (i.e., from < >, where < >), no details are provided as to the contents of these clauses. [0025] For the specification of the group generator module 110 , let “foo” represent the input data stream (the result of processing the Where clause (i.e., where < >) by the intermediate processing module 108 ) to the group generator module 110 . The group generator module 110 will output (m+n+k+1) columns at the output 112 , as presented by the following SQL: [0026] select g 1 , . . . , g m , a 1 , . . . , a k , d 1 , . . . , null, . . . , null, 0 as grouping_id from foo [0027] union all [0028] select g 1 , . . . , g m , null, . . . , null, null, . . . , d i , . . . , null, i from foo [0029] union all [0030] select g 1 , . . . , g m , null, . . . , null, . . . , null, . . . , null, . . . , d n , n-1 from foo [0031] For the foregoing generalized SQL query with MDAs, the two group by operations performed by the SQL-MDA group by processing module 116 are specified as follows. The inner group by operation may be specified as follows: [0032] Group by: [0033] Grouping columns: (g 1 , . . . , g m , grouping_id) [0034] Aggregates: agg(a 1 ), . . . , agg(a k ) [0035] The outer group by may be specified as follows: [0036] Group by: [0037] Grouping columns: [0038] Aggregates: (agg(d 1 ), . . . , agg(d n ),agg_convert(a 1 ), . . . , agg_convert(a k ) [0039] For the foregoing outer group, egg_convert is a converted aggregate as specified by the following two rules. For rule 1, if egg is “count” or “count” then agg_convert is “sum”. For rule 2, if egg is neither “count” nor “count(*)” then egg convert is the same as egg. [0040] Based on the foregoing discussion related to operation of the intermediate processing module 108 and the group generator module 110 for generalized SQL queries with MDAs, a SQL query with MDAs is processed by first processing the From and the Where clauses of the query (i.e., the where < > clause in the foregoing example of generalized SQL queries with MDAs). The Where clause is processed by the intermediate processing module 108 . The output of the intermediate processing module 108 is fed into the group generator module 110 , which outputs (m+n+k+1) columns at the output 112 . The output 112 of the group generator module 110 is fed to the SQL-MDA group by processing module 116 , which performs two successive group by operations on the output 112 to answer a query. [0041] An example of an operation of the group generator module 110 for a SQL queries with MDAs is described. The SQL query including MDAs relates to Table 2 (i.e., Table Orders) as follows, which also includes the data specified below: [0000] TABLE 2 Table Orders orderid prodid dealerid amount quantity integer integer integer integer integer 0 0 5 300 10 1 0 10 300 10 2 1 5 1500 500 For Table 2, the terms are specified as follows: [0042] orderid=Order Identification (ID) [0043] prodid=Product ID [0044] dealerid=Dealer ID [0045] amount=Amount [0046] quantity=Quantity [0000] For a SQL query including MDAs, the query may specify: [0047] select prodid, sum(distinct amount) as sum amount, sum(distinct quantity) as [0048] sum_quantity from orders group by prodid; [0049] The output of the SQL query including MDAs is specified in Table 3: [0000] TABLE 3 Output of SQL Query including MDAs prodid sum_amount sum_quantity 0 300 10 1 1500 500 For Table 3, the terms that are not previously defined are specified as follows: [0050] sum_amount=Summation of Amount [0051] sum_quantity=Summation of Quantity [0052] I n order to transform the foregoing example of a SQL query including MDAs, the transformation shown below is applied by the modules 110 and 116 : [0000] select prodid, sum(amount), sum(quantity) from ( select prodid, amount, quantity, grouping_id from ( select prodid, amount, null as quantity, 0 as grouping_id from orders union all select prodid, null, quantity, 1 from orders ) sq group by prodid, amount, quantity, grouping_id ) osq group by prodid [0053] The output of each of the blocks in the foregoing example of a SQL query including MDAs is given below in Tables 4-6. [0000] TABLE 4 Innermost Query Block select prodid, amount, null as quantity, 0 as grouping_id from orders union all select prodid, null, quantity, 1 from orders prodid amount quantity grouping_id 0 300 null 0 0 300 null 0 1 1500  null 0 0 null 10 1 0 null 10 1 1 null 500  1 For Table 4, the terms that are not previously defined are specified as follows: [0054] grouping_id=Grouping ID [0000] TABLE 5 Inner Group by Block select prodid, amount, quantity, grouping_id from (   select prodid, amount, null as quantity, 0 as grouping_id   from orders   union all   select prodid, null, quantity, 1   from orders ) group by prodid, amount, quantity, grouping_id prodid amount quantity grouping_id 0  300 null 0 1 1500 null 0 0 null  10 1 1 null 500 1 [0000] TABLE 6 Outer Group by Block select prodid, sum(amount), sum(quantity) from (   select prodid, amount, quantity, grouping_id   from (    select prodid, amount, null as quantity, 0 as grouping_id    from orders    union all    select prodid, null, quantity, 1    from orders    )   group by prodid, amount, quantity, grouping_id   ) group by prodid prodid sum_amount sum_quantity 0 300 10 1 1500 500 [0055] With regard to a SQL query including cube, rollup or grouping sets operations, generally, the group generator module 110 generates the groupings as the output 114 . The output 114 of the group generator module 110 is fed to the SQL cube, rollup and grouping sets group by processing module 118 , which performs a single group by operation on the output 114 answer a query. The answer to the query 104 is output at 120 by the query response module 122 . [0056] An example of a general SQL query including cube, rollup and grouping sets operations is as follows: [0057] select g 1 , . . . , g m , agg(a 1 ), . . . ,agg(a k ) [0058] from < > [0059] where < > [0060] group by OPR(g 1 , . . . , g m ); [0061] OPR(g 1 , . . . , g m ) may be any of the following: cube(g 1 , . . . , g m ) rollup(g 1 , . . . , g m ) grouping sets(subset 1 (g 1 , . . . , g m ), . . . , subset n (g 1 , . . . , g m )) [0065] With regard to cube(g 1 , . . . , g m ), the group generator module 110 is specified as follows. Cube(g 1 , . . . , g m ) forms 2 m groupings (i.e., all possible combinations over columns (g 1 , . . . , g m )). The group generator module 110 outputs at 114 (m+k+1) columns, as presented by the following SQL: [0000] Let “foo” represent the input data stream (the result of processing the From and Where clauses (i.e., from < >, where < >) by the intermediate processing module 108 to the group generator module 110 . Each “union all” branch below will generate one of the 2 m combinations. [0066] select null, . . . , null, . . . , null, . . . , a 1 , . . . a k , 0 as grouping_id from foo [0067] union all [0068] select g 1 , . . . , null, . . . , null, . . . , a 1 , . . . , a k , 1 from foo [0069] union all [0070] select null, . . . , g 1 , . . . , null, a 1 , . . . , a k , i from foo [0071] union all select null, . . . , null, . . . , g m , a 1 , . . . , a k , m from foo; [0072] union all [0073] select g 1 , . . . , g 1 , . . . , g i , . . . , g m , . . . , a 1 , . . . , a k , 2 m from foo [0074] With regard to rollup(g 1 , . . . , g m ), the group generator module 110 may be specified as follows. The group generator module 110 outputs (m+k+1) columns, as presented by the following SQL. Let “foo” represent the input data stream from the intermediate processing module 108 to the group generator module 110 . Rollup(g 1 , . . . , g m ) will form (m+1) groupings: ( ), (g 1 ), (g 1 , . . . , g 2 ), . . . , (g 1 ,g 2 ,g 3 ), . . . , (g 1 ,g 2 , . . . , g m ). Each “union all” branch below will generate one of the above (m+1) groupings as follows: [0075] select null, . . . , null, . . . , null, a 1 , . . . , a k , 0 as grouping_id from foo [0076] union all [0077] select g 1 , . . . , null, . . . , a 1 , . . . , a k , 1 from foo [0078] union all [0079] select g 1 , . . . , g i , . . . , null, . . . , a 1 , . . . , a k , i from foo [0080] union all [0081] select g 1 , . . . , g i , . . . , g m , a 1 , . . . , a k , m from foo [0082] With regard to grouping sets(subset 1 (g 1 , . . . , g m ), . . . , subset n (g 1 , . . . , g m )), the group generator module 110 may be specified as follows. The group generator module 110 outputs (m+k+1) columns, as presented by the following SQL. Let “foo” represent the input data stream from the intermediate processing module 108 to the group generator module 110 . Grouping sets(subset 1 (g 1 , . . . , g m ), . . . , subset n ,(g 1 , . . . , g m ) will form (n) groupings subset 1 (g 1 , . . . , g mn ), . . . , subset n ,(g f , . . . , g m ), Each “union all” branch below will generate one of the above (n) groupings. [0083] select subset — 1(g 1 , . . . , g m ), a 1 , . . . , a k , 0 as grouping_id from foo [0084] union all [0085] select subset_i(g 1 , . . . , g m ), a 1 , . . . , a k , i from foo [0086] union all [0087] select subset_n(g 1 , . . . , g m ), a 1 , . . . , a k , n from foo [0088] The SQL cube, rollup and grouping sets group by processing module 118 , which receives the output 114 of the group generator module 110 is specified as follows. The group by operation of the SQL cube, rollup and grouping sets group by processing module 118 proceeds as follows: [0089] Group by: [0090] Grouping columns: (g 1 , . . . , g m ,grouping_id) [0091] Aggregates: (agg(a 1 ), . . . , agg(a k )) [0092] Based on the foregoing discussion related to operation of the group generator module 110 for a SQL query including cube, rollup or grouping sets operations, generally, a SQL query including cube, rollup or grouping sets operations is processed by first processing the From and the Where clauses of the query (i.e., the where < > clause in the foregoing example of generalized SQL query including cube, rollup or grouping sets operations). The Where clause is processed by the intermediate processing module 108 . The output of the intermediate processing module 108 is fed into the group generator module 110 . The output 114 of the group generator module 110 is fed to the SQL cube, rollup and grouping sets group by processing module 118 , which performs a single group by operation on the output 114 to answer a query. The answer to the query 104 is output at 120 by the query response module 122 . [0093] An example of an operation of the group generator module 110 for a SQL query including a cube operation is described. The SQL query including a cube operation relates to Table 2 (i.e., Table Orders) as described previously. For the SQL query including a cube operation, the query may specify: [0094] select prodid, dealerid, sum(amount) as sum_amount, sum(quantity) as [0095] sum_quantity [0096] from orders [0097] group by cube(prodid, dealerid) [0098] The output of the SQL query including the cube operation is specified in Table 7: [0000] TABLE 7 Output of SQL Query Including Cube Operation prodid dealerid sum_amount sum_quantity null null 2100 520 null 5 1800 510 null 10 300 10 0 null 600 20 1 null 1500 500 0 5 300 10 0 10 300 10 1 5 1500 500 [0099] In order to transform the foregoing example of the SQL query including the cube operation, the transformation shown below is applied by the modules 110 and 118 : [0000] select prodid, dearlerid, sum(amount) as sum_amount, sum(quantity) as sum_quantity from ( select null as prodid, null as dearlerid, amount, quantity, 0 as grouping_id from orders union all select prodid, null, amount, quantity, 1 from orders union all select null, dealerid, amount, quantity, 2 from orders union all select prodid, dealerid, amount, quantity, 3 from orders ) group by pid, did, grouping_id [0100] The output of inner and outer query blocks in the foregoing example of a SQL query including the cube operation, as processed by the group generator module 110 and the SQL cube, rollup and grouping sets group by processing module 118 , is shown below in Tables 8 and 9, respectively. [0000] TABLE 8 Inner Query Block select null as prodid, null as dealerid, amount, quantity, 0 as grouping_id from orders union all select prodid, null, amount, quantity, 1 from orders union all select null, dealerid, amount, quantity, 2 from orders union all select prodid, dealerid, amount, quantity, 3 from orders prodid dealerid amount quantity grouping_id null null 300 10 0 null null 300 10 0 null null 1500 500 0 0 null 300 10 1 0 null 300 10 1 1 null 1500 500 1 null 5 300 10 2 null 5 1500 500 2 null 10 300 10 2 0 5 300 10 3 0 10 300 10 3 1 5 1500 500 3 [0000] TABLE 9 Outer Query Block select prodid, dearlerid, sum(amount) as sum_amount, sum(quantity) as sum_quantity from (   select null as prodid, null as dearlerid, amount, quantity,   0 as grouping_id   from orders   union all   select prodid, null, amount, quantity, 1   from orders   union all   select null, dealerid, amount, quantity, 2   from orders   union all   select prodid, dealerid, amount, quantity, 3   from orders    ) group by pid, did, grouping_id prodid dealerid sum_amount sum_quantity null null 2100 520 null 5 1800 510 null 10 300 10 0 null 600 20 1 null 1500 500 0 5 300 10 0 10 300 10 1 5 1500 500 [0101] An example of the operation of the group generator module 110 for a SQL query including a rollup operation is described. The SQL query including a rollup operation relates to Table 2 (i.e., Table Orders) as described previously. For the SQL query including a rollup operation, the query may specify: select prodid, dealerid, sum(amount) as sum amount, sum(quantity) as [0102] sum_quantity [0103] from orders [0104] group by rollup(prodid, dealerid) [0105] The output of the SQL query including the rollup operation is specified in Table 10: [0000] TABLE 10 Output of SQL Query Including Rollup Operation prodid dealerid sum_amount sum_quantity null null 2100 520 0 null 600 20 1 null 1500 500 0 5 300 10 0 10 300 10 1 5 1500 500 [0106] In order to transform the foregoing example of the SQL query including the rollup operation, the transformation shown below is applied by the modules 110 and 118 : [0000] select prodid, dealerid, sum(amount) as sum_amount, sum(quantity) as sum_quantity from ( select null as prodid, null as dealerid, amount, quantity, 0 as grouping_id from orders union all select prodid, null, amount, quantity, 1 from orders union all select prodid, dealerid, amount, quantity, 2 from orders ) sq group by prodid, dealerid, grouping_id [0107] The output of inner and outer query blocks in the foregoing example of a SQL query including the rollup operation, as processed by the group generator module 110 and the SQL cube, rollup and grouping sets group by processing module 118 , is shown below in Tables 11 and 12, respectively. [0000] TABLE 11 Inner Query Block select null as prodid, null as dealerid, amount, quantity, 0 as grouping_id from orders union all select prodid, null, amount, quantity, 1 from orders union all select prodid, dealerid, amount, quantity, 2 from orders prodid dealerid amount quantity grouping_id null null 300 10 0 null null 300 10 0 null null 1500 500 0 0 null 300 10 1 0 null 300 10 1 1 null 1500 500 1 0 5 300 10 2 0 10 300 10 2 1 5 1500 500 2 [0000] TABLE 12 Outer Query Block select prodid, dealerid, sum(amount) as sum_amount, sum(quantity) as sum_quantity from (   select null as prodid, null as dealerid, amount, quantity,   0 as grouping_id   from orders   union all   select prodid, null, amount, quantity, 1   from orders   union all   select prodid, dealerid, amount, quantity, 2   from orders   ) group by prodid, dealerid, grouping_id prodid dealerid sum_amount sum_quantity null null 2100 520 0 null 600 20 1 null 1500 500 0 5 300 10 0 10 300 10 1 5 1500 500 [0108] An example of an operation of the group generator module 110 for a SQL query including a grouping sets operation is described. The SQL query including a grouping sets operation relates to Table 2 (Le., Table Orders) as described previously. For the SQL query including a grouping sets operation, the query may specify: [0109] select prodid, dealerid, sum(amount) as sum amount, sum(quantity) as [0110] sum_quantity [0111] from orders [0112] group by grouping sets(dealerid, (prodid, dealerid)) [0113] The output of the SQL query including the grouping sets operation is specified in Table 13: [0000] TABLE 13 Output of SQL Query Including Grouping Sets Operation prodid dealerid sum_amount sum_quantity null 5 1800 510 null 10 300 10 0 5 300 10 0 10 300 10 1 5 1500 500 [0114] In order to transform the foregoing example of the SQL query including the grouping sets operation, the transformation shown below is applied by the modules 110 and 118 : [0000] select prodid, dealerid, sum(amount) as sum_amount, sum(quantity) as sum_quantity from ( select null as prodid, dealerid, amount, quantity, 0 as grouping_id from orders union all select prodid, dealerid, amount, quantity, 1 from orders ) group by prodid, dealerid, grouping_id [0115] The output of inner and outer query blocks in the foregoing example of a SQL query including the grouping sets operation, as processed by the group generator module 110 and the SQL cube, rollup and grouping sets group by processing module 118 , is shown below in Tables 14 and 15, respectively. [0000] TABLE 14 Inner Query Block select null as prodid, dealerid, amount, quantity, 0 as grouping_id from orders union all select prodid, dealerid, amount, quantity, 1 from orders prodid dealerid amount quantity grouping_id null 5 300 10 0 null 5 1500 500 0 null 10 300 10 0 0 5 300 10 1 0 10 300 10 1 1 5 1500 500 1 [0000] TABLE 15 Outer Query Block select prodid, dealerid, sum(amount) as sum_amount, sum(quantity) as sum_quantity from (   select null as prodid, dealerid, amount, quantity, 0 as grouping_id   from orders   union all   select prodid, dealerid, amount, quantity, 1   from orders   ) group by prodid, dealerid, grouping_id prodid dealerid sum_amount sum_quantity null 5 1800 510 null 10 300 10 0 5 300 10 0 10 300 10 1 5 1500 500 [0116] FIGS. 2 and 3 illustrate flowcharts of methods 200 and 300 for query processing, corresponding to the example of a query processing apparatus 100 whose construction is described in detail above. The methods 200 and 300 may be implemented on the query processing apparatus 100 with reference to FIG. 1 by way of example and not limitation. The methods 200 and 300 may be practiced in other apparatus. [0117] Referring to FIG. 2 , for the method 200 , at block 201 , a query is received. For example, referring to FIG. 1 , the query input module 102 receives the query 104 . [0118] At block 202 , a determination is made as to whether the query is a SQL query including MDAs, or a SQL query including cube, rollup or grouping sets operations. For example, referring to FIG. 1 , the query determination module 106 determines whether the SQL query includes MDAs, or cube, rollup or grouping sets operations. [0119] At block 203 , based on the determination, the query is processed to generate an output. For example, referring to FIG. 1 , the intermediate processing module 108 processes the From and the Where clauses of the query and forwards the results to the group generator module 110 . The group generator module 110 processes the query and the input from the intermediate processing module 108 to generate the output 112 for a SQL query including MDAs, or the output 114 for a SQL query including cube, rollup or grouping sets operations. [0120] At block 204 , based on the query type, a predetermined number of maximum group by operations are performed on the output to generate a response to the query. For example, referring to FIG. 1 , the SQL-MDA group by processing module 116 performs two successive group by operations on the output 112 of the group generator module 110 to answer a query. For a SQL query including cube, rollup or grouping sets operations, the SQL cube, rollup and grouping sets group by processing module 118 performs a single group by operation on the output 114 of the group generator module 110 to answer a query. [0121] Referring to FIG. 3 , for the method 300 , at block 301 , a query is received. For example, referring to FIG. 1 , the query input module 102 receives the query 104 . [0122] At block 302 , a determination is made as to whether the query is a SQL query including MDAs, or a SQL query including cube, rollup or grouping sets operations. For example, referring to FIG. 1 , the query determination module 106 determines whether the SQL query includes MDAs, or cube, rollup or grouping sets operations. [0123] At block 303 , the From and the Where clauses of the query are processed. For example, referring to FIG. 1 , the intermediate processing module 108 processes the From and the Where clauses of the query and forwards the results to the group generator module 110 . [0124] At block 304 , for a SQL query including MDAs, a first output is generated. For example, referring to FIG. 1 , the group generator module 110 processes the query and the input from the intermediate processing module 108 to generate the output 112 for a SQL query including MDAs. [0125] At block 305 , for a SQL query including cube, rollup or grouping sets operations, a second output is generated. For example, referring to FIG. 1 , the group generator module 110 processes the query and the input from the intermediate processing module 108 to generate the output 114 for a SQL query including cube, rollup or grouping sets operations. [0126] At block 306 , for a SQL query including MDAs, inner and outer group by operations are generated and performed. For example, referring to FIG. 1 , the SQL-MDA group by processing module 116 performs two successive group by operations on the output 112 of the group generator module 110 to answer a SQL query including MDAs. [0127] At block 307 , for a SQL query including the cube operation, 2 m groupings are generated, where m is a number of grouping columns for the cube operation. For example, cube(g 1 , . . . , g m ) forms 2 m groupings (i.e., all possible combinations over columns [0128] At block 308 , for a SQL query including the rollup operation,rn+1 groupings are generated, where m is a number of grouping columns for the rollup operation. For example, the group generator module 110 outputs m+1 groupings, each with (m+k+1) columns, for a SQL query including the rollup operation with m number of grouping columns and k number of aggregates. [0129] At block 309 , for a SQL query including the grouping sets operation, n groupings are generated, where n is a number of sets for the grouping sets operation. For example, the group generator module 110 outputs n groupings, each with (m+k+1) columns, for a SQL query including the grouping sets operation with n number of grouping sets, in number of grouping columns and k number of aggregates. [0130] At block 310 , for the SQL query including cube, rollup or grouping sets operations, a single group by operation is performed on the output of the group generator module to answer a query. For example, referring to FIG. 1 , the SQL cube, rollup and grouping sets group by processing module 118 performs a single group by operation on the output 114 of the group generator module 110 to answer a SQL query including cube, rollup or grouping sets operations, [0131] FIG. 4 shows a computer system that may be used with the examples described herein. The computer system represents a generic platform that includes components that may be in a server or another computer system. The computer system may be used as a platform for the apparatus 100 . The computer system may execute, by a processor or other hardware processing circuit, the methods, functions and other processes described herein. These methods, functions and other processes may be embodied as machine readable instructions stored on a computer readable medium, which may be non-transitory, such as hardware storage devices (e.g., RAM (random access memory), ROM (read only memory), EPROM (erasable, programmable ROM), EEPROM (electrically erasable, programmable ROM), hard drives, and flash memory). [0132] The computer system includes a processor 402 that may implement or execute machine readable instructions performing some or all of the methods, functions and other processes described herein. Commands and data from the processor 402 are communicated over a communication bus 404 . The computer system also includes a main memory 408 , such as a random access memory (RAM), where the machine readable instructions and data for the processor 402 may reside during runtime, and a secondary data storage 408 , which may be non-volatile and stores machine readable instructions and data. The memory and data storage are examples of computer readable mediums. The memory 406 may include modules 420 including machine readable instructions residing in the memory 406 during runtime and executed by the processor 402 . The modules 420 may include the modules 102 , 106 , 108 , 110 , 116 , 118 and 122 of the apparatus shown in FIG. 1 . [0133] The computer system may include an I/O device 410 , such as a keyboard, a mouse, a display, etc. The computer system may include a network interface 412 for connecting to a network. Other known electronic components may be added or substituted in the computer system. [0134] What has been described and illustrated herein is an example along with some of its variations. The terms, descriptions and figures used herein are set forth by way of illustration only and are not meant as limitations. Many variations are possible within the spirit and scope of the subject matter, which is intended to be defined by the following claims -- and their equivalents -- in which all terms are meant in their broadest reasonable sense unless otherwise indicated.

Description

Topics

Download Full PDF Version (Non-Commercial Use)

Patent Citations (11)

    Publication numberPublication dateAssigneeTitle
    US-2002095430-A1July 18, 2002Decode Genetics EhfSQL query generator utilizing matrix structures
    US-2004236735-A1November 25, 2004Microsoft CorporationDatabase aggregation query result estimator
    US-2007233808-A1October 04, 2007Daniel Egnor, Paul Haahr, Kevin Lacker, John Lamping, Singhal Amitabh K, Ke YangPropagating useful information among related web pages, such as web pages of a website
    US-2009228433-A1September 10, 2009International Business Machines CorporationSystem and method for multiple distinct aggregate queries
    US-2010094829-A1April 15, 2010Castellanos Maria G, Ivo Jose Jimenez RamosDatabase query profiler
    US-2010257191-A1October 07, 2010Microsoft CorporationData parallel query analysis
    US-2011094829-A1April 28, 2011Juergen SeidelMethod and apparatus for roller lubrication
    US-2012110519-A1May 03, 2012Sap AgGraphical manipulation of data objects
    US-6112198-AAugust 29, 2000International Business Machines CorporationOptimization of data repartitioning during parallel query optimization
    US-6212552-B1April 03, 2001At&T Corp.Declarative message addressing
    US-6507835-B1January 14, 2003International Business Machines CorporationGenerating grouping queries using tensor representations

NO-Patent Citations (0)

    Title

Cited By (0)

    Publication numberPublication dateAssigneeTitle