Patent ID: 8417690

Claim:
A method comprising: determining that a Cartesian product join should be automatically avoided for a database query; beginning construction of an execution data structure that indicates how to implement the database query on a database; while constructing the execution data structure, determining that implementing the database query in accordance with a current state of the execution data structure will result in a Cartesian product join; determining whether a referential constraint between data sources indicated in the database query can be identified; in response to identifying a first referential constraint between the data sources indicated in the database query, modifying the current state of the execution data structure to leverage the identified first referential constraint to avoid the Cartesian product join; and completing construction of the execution data structure with the modified current state of the execution data structure; and in response to identifying the first referential constraint and a second referential constraint between the data sources indicated in the database query, generating two versions of the execution data structure, wherein a first version of the execution data structure leverages the first referential constraint between the data sources, and wherein a second version of the second execution data structure leverages the second referential constraint between the data sources.