Relational Theory – Attributes After Cross Product

relational-theory

I have a question regarding the resulting attributes in the cross product of two relations in relational algebra…

Generally, the cross product will result in a relation whose attributes is the sum of all the attributes, So number of attributes in R1 x R2 will be attributes in R1 + R2, so R1(a, b, c) x R2(d, e, f)R(a, b, c, d ,e ,f)

But, what happens if R1 and R2 have common attributes (attributes of the same name)? since a relation can not have duplicate attributes… so what would happen in the case R1(a, b, c) X R2(a, e, f)? thanks…

Best Answer

To express that relation in algebraic notation you actually need to alias the attribute.

The Cartesian product, by design, does not recognize common attribute names, so much like a single operation doesn't work in a self relation scenario, it's necessary to perform a rename within the notation.

The self join example:

R( a, b, c );

≠ R ⋈ R ( a, b, c );

Using rename:

R( a, b, c );

S = ρa/b, b/b2, c/c2 R;

∴ R ⋈ S ( a, b, c, b2, c2 );

For instance:

E( EmpID, ManagerID, EmpName );

M = ρEmpID/ManagerID, ManagerID/ManagerEmpID, EmpName/ManagerName E;

∴ E ⋈ M ( EmpID, ManagerID, EmpName, ManagerEmpID, ManagerName );

The Cartesian product can be expressed using relational algebra in the same way:

R1( a, b, c );

R2( a, e, f );

≠ R1 × R2 ( a, b, c, e, f );

So then with rename:

R1( a, b, c );

R2( a, e, f );

R3 = ρa/a2R2;

∴ R1 × R3 ( a, b, c, a2, e, f );