Relational Algebra: 1. Under what circumstances does (R Natural Join R) = R hold
ID: 3597055 • Letter: R
Question
Relational Algebra:
1. Under what circumstances does (R Natural Join R) = R hold true? R is a bag.
2. Given S(B, C) and R(A, B) where A, B, and C have the data type 'int'. Do NOT make any assumption about keys. Consider the following expressions:
Two of the above expressions are equivalent (i.e., always produce the same answer), while one of them can produce a different answer. Which expression can produce a different answer? Provide a database instance you can think of where a different answer is produced by that expression.
Explanation / Answer
1. First of all we will see what is a natural join,
Natural Join ()
Natural join does not use any comparison operator. It does not concatenate the way a Cartesian product does. We can perform a Natural Join only if there is at least one common attribute that exists between two relations. In addition, the attributes must have the same name and domain.
Natural join acts on those matching attributes where the values of attributes in both the relations are same.
So, if there are relations, Courses and HoD then
Courses
CID
Course-name
Dept
ME01
Mechanics
ME
CS01
Database
CS
PH01
Physics
PH
HoD
Dept
Head
ME
Marya
CS
Alex
PH
Bob
Couses HoD
Dept
CID
Course-name
Head
ME
ME01
Mechanics
Marya
CS
CS01
Database
Alex
PH
PH01
Physics
Bob
2. In the relational algebra, (pi) means 'select' ,and sigma means 'where' condition of the query. Here in this example, A,B,C are all integers.
i) A,C (R owtie sigma B=1 S)
ii) A (sigma B=1 R) x C (sigma B=1 S)
iii) A, C( A R x sigma B=1 S)
S
B
C
1
10
2
11
3
12
R
A
B
51
2
52
1
53
3
A
B
C
52
1
10
A
B
C
51
1
10
52
1
10
53
1
10
CID
Course-name
Dept
ME01
Mechanics
ME
CS01
Database
CS
PH01
Physics
PH