Search code examples
relational-algebra

What does the multiply operator do relational algebra?


I'm new to relational algebra. I found the * operator in the following expression

enter image description here

What's the different this and one using join

enter image description here


Solution

  • The * should more correctly be written × as it represents a Cartesian product. This operation returns the set of all tuples that are the concatenation of tuples from each operand. A join filters the Cartesian product down to only those tuples with matching values on specified attributes. If the join is a natural join, as in your example, the attributes matched on are those with identical names.

    For example, given the following two relations R and S as shown:

    R ( a, b, c )      S ( b, c, d )
      ( 1, 2, 3 )        ( 2, 7, 9 )
      ( 2, 4, 6 )        ( 5, 3, 4 )
      ( 3, 6, 9 )        ( 2, 3, 6 )
    

    The Cartesian product R × S is:

      ( R.a, R.b, R.c, S.b, S.c, S.d )
      ( 1,   2,   3,   2,   7,   9   )
      ( 1,   2,   3,   5,   3,   4   )
      ( 1,   2,   3,   2,   3,   6   )
      ( 2,   4,   6,   2,   7,   9   )
      ( 2,   4,   6,   5,   3,   4   )
      ( 2,   4,   6,   2,   3,   6   )
      ( 3,   6,   9,   2,   7,   9   )
      ( 3,   6,   9,   5,   3,   4   )
      ( 3,   6,   9,   2,   3,   6   )
    

    The natural join R ⨝ S is the product filtered to only tuples where the b and c values match:

      ( a, b, c, d )
      ( 1, 2, 3, 6 )
    

    The join R ⨝b S is the product filtered to only tuples where the b values match:

      ( R.a, b,   R.c, S.c, S.d )
      ( 1,   2,   3,   7,   9   )
      ( 1,   2,   3,   3,   6   )