What does the multiply operator do relational algebra?

こ雲淡風輕ζ 提交于 2019-12-11 13:12:13

问题


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

What's the different this and one using join


回答1:


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   )


来源:https://stackoverflow.com/questions/19740758/what-does-the-multiply-operator-do-relational-algebra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!