Natural Join in Relational Algebra - Database Theory

968 views Asked by At

Could I have still came up with the correct answer if I deleted the yellow part? Is it even neccesary?

image

2

There are 2 answers

6
N. Paul On BEST ANSWER

Assuming this is no homework:

I guess |X| is natural join and # denotes the primary key attributes.

The highlighted projection on S# is not necessary with respect to correctness of the query result (effectiveness).

However, it may increase efficiency: Project as early as possible to remove duplicates before the join. This avoids the unnecessary effort of first producing duplicate natjoined tuples which the projection on sname then has to remove.

1
Erwin Smout On

In order to know whether or not you can leave it out, you have to look at what the predicates are that correspond to the expression and its sub-expressions.

For example, that innermost restrict says (I presume because the example is familiar) "Supplier S# supplies part P# in quantity QUANTITY AND P# = 3". Or shorter "Supplier S# supplies part 3 in quantity QUANTITY".

The projection on S# of that then says "there exists some quantity q such that supplier S# supplies part 3 in that quantity".

The JOIN with S of that then says "Supplier S# is named SNAME, [familiar part snipped] AND there exists some quantity q such that supplier S# supplies part 3 in that quantity". Or shorter "Supplier S# is named SNAME, [familiar part snipped] AND supplies part 3 in some quantity".

The projection on SNAME of that then says "there exists some S#, CITY, STATUS such that Supplier S# is named SNAME, [familiar part snipped] AND supplies part 3 in some quantity".

You do the same for the case when the "inner projection" is left out and then try to prove that the predicate obtained must be equivalent to this one. If you can, you know including that projection is unnecessary. [And if you can't you must try harder :-) ]