Ask the Expert

Relating Cartesian product to relational algebra and calculus

What is a Cartesian product and what relation does it have to relational algebra and relational calculus?

    Requires Free Membership to View

Named after the famous french philosopher Renee Descartes, a Cartesian product is a selection mechanism of listing all combination of elements belonging to two or more sets. Usually programmers create a Cartesian product by omitting a join condition accidentally or erroneously.

For example,

Say, I have three numbers in set (table) A --> 1, 2, 3

I have three letters in a different set (table) B --> E, F, G

The Cartesian product of the two sets (A X B) will be the following rows

    1 E
    1 F
    1 G
    2 E
    2 G
    2 G
    3 E
    3 F
    3 G

Relational algebra is used to express queries by applying specialized operators to relations. Relationships (resulting query) are determined and established by attributes (column value) in entities (table) through some operators. Cartesian product is one such operator.

Other operators for relational algebra are:

i) UNION (A U B) 
Set of tuples (result set)  that are in  A or B or both
   
ii) Difference (A - B) 
Set of tuples (result set) that are in A but not in B.
   
ii) Intersection (A ^ B) 
Set of tuples that are both in A and in B.
   
iii) Cartesian Product (A X B) 
All possible combination of entries in A and in B

iv) Project
Selecting a subset of the attributes (columns) of an entity (table).
   
v) Select --> Set of tuples that are in a A through some condition.
   
vi) Join  
   
vii) Division (Quotient)
 

On the other hand relational calculus is an alternative method to relational algebra. However, both are equivalent to one another -- i.e., for each expression of the relational algebra there is an equivalent in the relational calculus. The converse is also true. Relational calculus is closer to the natural language and based on predicate logic. Where as relational algebra is more like a programming language. Relational calculus simply states what the problem is and relational algebra provides a mechanism (procedure) for a solution. SQL is a prime example of relational algebra.

This was first published in February 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: