-1

Here (at slide #46) says: Show that the intersection R ∩ S can be expressed using a combination of projection and an equijoin.

How is it possible? For what I know, R ∩ S = R - (R - S), so for the intersection the two relations must have the same attributes. Having them the same attributes, why should we need projection?

user402843
  • 89
  • 1
  • 9
  • Because - is not equijoin, it is difference/minus. PS Please make your question self-contained: Put or paraphrase the relevant excerpt and the source in your post as text. That includes the defintions of the opertaors & "relation". For symbols google unicode or use their names or the names of their operators. – philipxy Jan 21 '18 at 20:36
  • Re "the same attributes": Your equijoin is defined in terms of your product, whose return value has output arity that is the sum of input arities. So it does not return "the same attributes" in the sense that you mean by that (unclear) phase. Work through an example. – philipxy Jan 21 '18 at 20:54
  • Your slides are an example of a presentation that uses sloppy undefined pseudo-math non-algebraic expressions that are really SQL. Eg `F.name` in the example of equijoin. You should complain to your lecturer that it makes no sense. It *says* "If R and S have an attribute A in common, then we use the notation R.A and S.A to disambiguate" but that takes R & S as *name parts of schemas* not values and there are no columns R.A & S.A. That sweeps lot of fuzziness under the rug. (See my comments at [the very last relational-algebra question](https://stackoverflow.com/q/48080795/3404097)). – philipxy Jan 21 '18 at 21:56

1 Answers1

2

In slide 27 of the file that you have linked, it is said that the relations argument of the union and difference must only have the same arity, not necessarily the same attributes, and this is true also for the intersection.

So they can have different names, and in this case if you do an equijoin on R and S over the attributes in the same position the result is equivalent to the intersection but with more attributes that those necessary, so the projection is required to get a relation with the right number of attributes.

For instance, suppose you have:

R(A, B, C) ∩ S(D, E, F) = The set of tuples appearing both in R and S

This is equivalent to:

π(A,B,C) (R(A, B, C) ⋈(A=D ∧ B=E ∧ C=F) S(D, E, F))

Note that the projection could be done by chosing any of the two attributes for each couple (A, D), (B, E) and (C, F).

Finally note that other definitions of the set operators on relational algebra require that operands have attributes with the same name and type.

Renzo
  • 26,848
  • 5
  • 49
  • 61
  • This is not clear but I'm not going to go into details. Partly it's not clear because it is not reflecting or clearly talking about the actual operators & expressions defined in the slides--but then, it's difficult to write something clear & correct when the source material is nonsense. Nevertheless you *could* be clear by only mentioning certain properties while avoiding details. Eg an equijoin expression (*not* operator, pace the slides) (which, notice, takes 3 *expressions* not values, 2 being schema names) denotes a selection of a product, so has arity the sum of input schemas'. – philipxy Jan 21 '18 at 22:19
  • "union and difference must only have the same arity, not necessarily the same attributes" Yeah, that's exactly the point where I made confusion. Thank you. – user402843 Jan 22 '18 at 00:20