Search code examples
databasejoinrelational-databaserelational-algebranatural-join

Is Natural Join distributive over Union?


Given three relations R, S and T, is it true that:

R ⋈ (S U T) = (R ⋈ S) U (R ⋈ T)

If yes, can we prove it?


Solution

  • YES.

    Suppose we have 3 relations R, S, T.

    First of all, you should know that S and T have to be union compatible so as to perform union operation, which means two relations have same fields.

    Prove left -> right:

    Suppose a row r belongs to the set of left opeartion. Then, for those values originally from S or T, they must appear either in relation S or T. Without loss of generality, suppose they are from S. Then, row r belongs to R ⋈ S.

    Prove right -> left:

    Suppose a row r' belongs to the set of right opeartion. Then, r either belongs to R ⋈ S or R ⋈ T.

    Without loss of generality, suppose r belongs to R ⋈ S. Then, for those values originally from S, it also belongs to a row in S U T.

    Hence, r' belongs to R ⋈ (S U T) .

    Therefore, the proposition is correct.