Relational Algebra: Natural Join having the same result as Cartesian product

社会主义新天地 提交于 2019-12-24 09:57:46

问题


I am trying to understand what will be the result of performing a natural join between two relations R and S, where they have no common attributes.

By following the below definition, I thought the answer might be an empty set:
Natural Join definition.
My line of thought was because the condition in the 'Select' symbol is not met, the projection of all of the attributes won't take place.
When I asked my lecturer about this, he said that the output will be the same as doing a cartezian product between R and S.
I can't seem to understand why, would appreciate any help )


回答1:


Natural join combines a cross product and a selection into one operation. It performs a selection forcing equality on those attributes that appear in both relation schemes. Duplicates are removed as in all relation operations.

There are two special cases:

• If the two relations have no attributes in common, then their natural join is simply their cross product.

• If the two relations have more than one attribute in common, then the natural join selects only the rows where all pairs of matching attributes match.

Notation: r s
Let r and s be relation instances on schema R and S
respectively.
The result is a relation on schema R ∪ S which is
obtained by considering each pair of tuples tr from r and ts from s.
If tr and ts have the same value on each of the attributes in R ∩ S, a
tuple t is added to the result, where
– t has the same value as tr on r
– t has the same value as ts on s

Example:

R = (A, B, C, D)
S = (E, B, D)
Result schema = (A, B, C, D, E)
r s is defined as:
πr.A, r.B, r.C, r.D, s.E (σr.B = s.B r.D = s.D (r x s))



回答2:


The definition of the natural join you linked is:

It can be broken as:

1.First take the cartezian product.

2.Then select only those row so that attributes of the same name have the same value

3.Now apply projection so that all attributes have distinct names.

If the two tables have no attributes with same name, we will jump to step 3 and therefore the result will indeed be cartezian product.



来源:https://stackoverflow.com/questions/48080795/relational-algebra-natural-join-having-the-same-result-as-cartesian-product

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