Patent ID: 8635206

Claim:
A computer-implemented method for efficiently transforming a database query comprising: detecting a database query; and in response to detecting the database query, performing operations including: (a) determining that the database query includes a first sub-query and a second sub-query, wherein the first sub-query and second sub-query are operands for a Union operation, wherein a first result of the first sub-query is associated with a first Group By operation, wherein a second result of the second sub-query is associated with a second Group By operation, and wherein a result of the Union operation is associated with a third Group By operation, (b) determining that partitioning columns are the same for the first and second Group By operations, (c) determining that the first and second sub-queries include identical algebraic functions, (d) determining that the first Group By operation and first sub-query are not referenced elsewhere in the query, and transforming the database query into an optimized query, wherein the optimized query does not include the Union operation.