IP Library Granted Patent US 8,666,969
Granted Patent B2
US 8,666,969 · App. 13/295,984 · Granted Mar 4, 2014

Query rewrite for pre-joined tables

Inventors: Thomas A. Beavin (Milpitas, CA); Mengchu Cai (San Jose, CA); Ruiping Li (Cupertino, CA); James A. Ruddy (San Jose, CA)
Assignee: International Business Machines Corporation
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 8,666,969
App. No.
13/295,984
Granted
Mar 4, 2014
Kind
B2
Abstract

Various aspects of this disclosure are directed to receiving, by a computing device, a first table join query that may include a first group of table identifiers that identify the two or more tables. The computing device may determine whether the first table join query includes an outer join command. When the first table join query includes the outer join command, the computing device may compare the first group of table identifiers and a second group of table identifiers of one or more pre-joined tables to determine whether each of the first table identifiers matches at least one of the second group of table identifiers. The computing device may further determine whether a predicate associated with each table identifier matches a predicate associated with a matching second table identifier. When each of the predicates match, the computing device may rewrite the first table join query.

Claims (57)

1. A method comprising:

receiving, by a computing device, a first table join query to select information from two or more tables of a database, wherein the first table join query comprises a first group of table identifiers that identify the two or more tables;

determining, by the computing device, whether the first table join query includes an outer join command;

when the first table join query includes the outer join command:

comparing, by the computing device, the first group of table identifiers and a second group of table identifiers that identify one or more pre-joined tables to determine whether each of the table identifiers of the first group matches at least one of the table identifiers of the second group;

when each of the table identifiers of the first group matches at least one of the table identifiers of the second group, determining, by the computing device and for each table identifier of the first group, whether a predicate associated with the respective table identifier matches a predicate associated with a second table identifier of the second group, wherein the second table identifier matches the respective table identifier;

responsive to determining that the predicate associated with the respective table identifier does not match a respectively ordered predicate associated with a second table identifier, determining whether at least two instances of the respective table identifier are included in a first order in the first table join query;

responsive to determining that the at least two instances of the respective table identifier are included in the first order in the first table join query, determining by the computing device, that at least two predicates associated with the at least two instances of the respective table identifier are common to predicates associated with one or more instances of the second table identifier that are included in a second, different ordering of a query used to generate the one or more pre-joined tables;

determining, by the computing device, that the at least two predicates are interchangeable such that the one or more pre-joined tables are usable to service the first table join query when the first order of the at least two predicates are swapped to the second order; and

generating, by the computing device and based on the determination that the at least two predicates are interchangeable when the first order of the at least two predicates are swapped to the second order, a second table join query based at least in part on the first table join query, wherein the second table join query specifies at least one of the one or more pre-joined tables.

2. The method of claim 1 , further comprising:

when fewer than all of the first group of table identifiers match at least one of the second group of table identifiers, determining, by the computing device, for each table identifier of the first group of table identifiers that matches a table identifier of the second group of table identifiers, whether the predicate associated with the respective table identifier of the first group matches the predicate associated with the second table identifier of the second group, wherein the second table identifier matches the first table identifier,

wherein generating the second table join query comprises generating one or more table expressions that include a table identifier associated with each of the at least one of the second group of table identifiers that match the at least one of the first group of table identifiers.

3. The method of claim 1 , further comprising:

when each of the first group of table identifiers matches at least one of the second group of table identifiers, determining, by the computing device, whether each of the second group of table identifiers matches at least one of the first group of table identifiers; and

when each of the second group of table identifiers does not match at least one of the first group of table identifiers, determining, by the computing device, and for each table identifier of the second group that does not match at least one of the first group of table identifiers, that a predicate associated with each of the table identifiers results in a loss-less join.

4. The method of claim 1 , wherein comparing the first group of table identifiers and the second group of table identifiers of the one or more pre-joined tables further comprises determining, for each table identifier of the first group of table identifiers whether a table mapping flag of a table mapping structure of the computing device indicates that the table identifier matches at least one of the second group of table identifiers.

5. The method of claim 1 , wherein determining, for each table identifier of the first group of table identifiers whether the predicate associated with the table identifier matches the predicate associated with the second table identifier of the second group further comprises determining, for each table identifier of the first group of table identifiers whether a predicate mapping flag of a predicate mapping structure of the computing device indicates that the predicate associated with the table identifier matches the predicate associated with the second table identifier of the second group.

6. The method of claim 1 , wherein generating the second table join query further comprises substituting a table name associated with a table identifier included in the first table join query with a table name associated with a table identifier included in the second group of table identifiers that identify the one or more pre-joined tables.

7. A computer program product comprising a non-transitory computer-readable storage medium having computer-readable program code embodied therein, the computer-readable program code comprising:

computer-readable program code to receive a first table join query to select information from two or more tables of a database, wherein the first table join query comprises a first group of table identifiers that identify the two or more tables;

computer-readable program code to determine whether the first table join query includes an outer join command;

computer-readable program code to compare the first group of table identifiers and a second group of table identifiers of one or more pre-joined tables to determine whether each of the first table identifiers of the first group matches at least one of the table identifiers of the second group, when the first table join query includes the outer join command;

computer-readable program code to determine for each table identifier of the first group whether a predicate associated with the respective table identifier matches a predicate associated with a second table identifier of the second group when each of the table identifiers of the first group matches at least one of the table identifiers of the second table group, wherein the second table identifier matches the respective table identifier;

computer-readable program code to, responsive to determining that the predicate associated with the respective table identifier does not match a respectively ordered predicate associated with a second table identifier, determine whether at least two instances of the respective table identifier are included in a first order in the first table join query;

computer-readable program code to, responsive to determining that the at least two instances of the respective table identifier are included in the first order in the first table join query, determine that at least two predicates associated with the at least two instances of the respective table identifier are common to predicates associated with one or more instances of the second table identifier that are included in a second, different ordering of a query used to generate the one or more pre-joined tables;

computer-readable program code to, determine that the at least two predicates are interchangeable such that the one or more pre-joined tables are usable to service the first table join query when the first order of the at least two predicates are swapped to the second order; and

computer-readable program code to generate, and based on the determination that the at least two predicates are interchangeable when the first order of the at least two predicates are swapped to the second order, a second table join query based at least in part on the first table join query, wherein the second table join query specifies at least one of the one or more pre-joined tables.

8. The computer program product of claim 7 , the computer-readable program code further comprising:

computer-readable program code to determine for each table identifier of the first group of table identifiers that matches a table identifier of the second group of table identifiers, whether the predicate associated with the respective table identifier of the first group matches the predicate associated with the second table identifier of the second group, when fewer than all of the first group of table identifiers match at least one of the second group of table identifiers, wherein the second table identifier matches the first table identifier,

wherein generating the second table join query comprises generating one or more table expressions that include a table identifier associated with each of the at least one of the second group of table identifiers that match the at least one of the first group of table identifiers.

9. The computer program product of claim 7 , the computer-readable program code further comprising:

computer-readable program code to determine whether each of the second table identifiers matches at least one of the first table identifiers, when each of the first table identifiers matches at least one of the second table identifiers; and

computer-readable program code to determine for each of the second table identifiers that does not match at least one of the first table identifiers that a predicate associated with each of the table identifier results in a loss-less join, when each of the second table identifiers does not match at least one of the first table identifiers.

10. The computer program product of claim 7 , wherein the computer-readable program code to compare the first group of table identifiers and the second group of table identifiers of the one or more pre-joined tables further comprise computer-readable program code to determine, for each table identifier of the first group of table identifiers whether a table mapping flag of a table mapping structure of the computer program product indicates that the table identifier matches at least one of the second group of table identifiers.

11. The computer program product of claim 7 , wherein the computer-readable program code to determine, for each table identifier of the first group of table identifiers whether the predicate associated with the table identifier matches the predicate associated with the second table identifier of the second group further comprises, computer-readable program code to determine, for each table identifier of the first group of table identifiers whether a predicate mapping flag of a predicate mapping structure of the computer program product indicates that the predicate associated with the table identifier matches the predicate associated with the second table identifier of the second group.

12. The computer program product of claim 7 , wherein the computer-readable program code to generate the second table join query further comprises computer-readable program code to substitute a table name associated with a table identifier included in the first table join query with a table name associated with a table identifier included in the second group of table identifiers that identify the one or more pre-joined tables.

13. A computing device, comprising:

one or more processors; and

a query processing module executable by the one or more processors to:

receive a first table join query to select information from two or more tables of a database, wherein the first table join query comprises a first group of table identifiers that identify the two or more tables;

determine whether the first table join query includes an outer join command;

when the first table join query includes the outer join command:

compare the first group of table identifiers and a second group of table identifiers of one or more pre-joined tables to determine whether each of the first table identifiers of the first group matches at least one of the table identifiers of the second group;

determine for each table identifier of the first group whether a predicate associated with the respective table identifier matches a predicate associated with a second table identifier of the second group when each of the first table identifiers of the first group matches at least one of the second table identifiers of the second group, wherein the second table identifier matches the respective table identifier;

responsive to determining that the predicate associated with the respective table identifier does not match a respectively ordered predicate associated with a second table identifier, determine whether at least two instances of the respective table identifier are included in a first order in the first table join query;

responsive to determining that the at least two instances of the respective table identifier are included in the first order in the first table join query, determine that at least two predicates associated with the at least two instances of the respective table identifier are common to predicates associated with one or more instances of the second table identifier that are included in a second, different ordering of a query used to generate the one or more pre-joined tables;

determining, by the computing device, that the at least two predicates are interchangeable such that the one or more pre-joined table re usable to service the first table join query when the first order of the at least two predicates are swapped to the second order; and

generate, and based on the determination that the at least two predicates are interchangeable when the first order of the at least two predicates are swapped to the second order, a second table join query based at least in part on the first table join query, wherein the second table join query specifies at least one of the one or more pre-joined tables.

14. The computing device of claim 13 , wherein the query processing module is further executable by the one or more processors to:

determine for each table identifier of the first group of table identifiers that matches a table identifier of the second group of table identifiers, whether the predicate associated with the respective table identifier of the first group matches the predicate associated with the second table identifier of the second group, when fewer than all of the first group of table identifiers match at least one of the second group of table identifiers, wherein the second table identifier matches the first table identifier,

wherein generating the second table join query comprises generating one or more table expressions that include a table identifier associated with each of the at least one of the second group of table identifiers that match the at least one of the first group of table identifiers.

15. The computing device of claim 13 , wherein the query processing module is further executable by the one or more processors to:

determine whether each of the second table identifiers matches at least one of the first table identifiers, when each of the first table identifiers matches at least one of the second table identifiers; and

determine for each of the second table identifiers that does not match at least one of the first table identifiers, that a predicate associated with each of the table identifier results in a loss-less join, when each of the second table identifiers does not match at least one of the first table identifiers.

16. The computing device of claim 13 , wherein comparing the first group of table identifiers and the second group of table identifiers of the one or more pre-joined tables further comprises determining, for each table identifier of the first group of table identifiers whether a table mapping flag of a table mapping structure of the computing device indicates that the table identifier matches at least one of the second group of table identifiers.

17. The computing device of claim 13 , wherein the query processing module is further executable by the one or more processors to determine, for each table identifier of the first group of table identifiers whether a predicate mapping flag of a predicate mapping structure of the computing device indicates that the predicate associated with the table identifier matches the predicate associated with the second table identifier of the second group.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Nov 14, 2011
From: BEAVIN, THOMAS A.; CAI, MENGCHU; LI, RUIPING; RUDDY, JAMES A.
To: INTERNATIONAL BUSINESS MACHINES CORPORATION
Reel/Frame 027224/0435 →
Continuity (1)
Related Publication 20130124500A1 · May 16, 2013