Relational Algebra - Cartesian Product vs Natural Join?

前端 未结 3 1876
被撕碎了的回忆
被撕碎了的回忆 2021-02-15 11:02

I am studying for exams and am failing to find a solid criteria by which I can determine if the Cartesian Product x is to be used or if Natural Join |X|

相关标签:
3条回答
  • 2021-02-15 11:07

    I think there are two extreme situation:

    1. there are no duplicate rows in inner join: inner join is equal to intersect (i mean only the result). distinct inner join ~ intersect

    2. there are no common feature in the inner join: inner join is equal to Cartesian product.

    0 讨论(0)
  • 2021-02-15 11:27

    Cartesian product is just a special case of natural join where the joined relations don't have any attribute names in common. In Codd's original algebra renaming was a separate operation altogether. To obtain a true cartesian product of two relations that have some attributes in common you would have to rename those attributes before doing the (natural) join.

    In the interests of brevity the renamings are sometimes left out of written examples and the product symbol used instead. Unfortunately this obscures the important point, that there is only one kind of join.

    0 讨论(0)
  • 2021-02-15 11:31

    A natural join, as I understand it, is a projected, filtered Cartesian product:

    • You take the Cartesian product, then
    • select it, so that the values in columns of the same name have the same value, and
    • project it, so that all columns have distinct names.

    Under this assumption, your answer is isomorphic to the actual answer.

    To see this, you might want to expand the natural join to the above sequence of operators, and float them around using the laws of relational algebra. You'll see that the projection disappears due to the projection to name, and the selection criterion is fused with the selection above. You'll end up with exactly the same tree as the actual answer, even though you never changed the meaning of your own answer!


    I can think of one reason why your lecturer uses these concepts interchangeably: your lecturer wants you to understand that these concepts can be used interchangeably, because "the natural join is just a shortcut" (though that's debatable).

    0 讨论(0)
提交回复
热议问题