GATE / CS ARCHIVE

GATE CSE 2019 / QUESTION 55

Projecting and subtracting joined relations

Database Management Systems · Relational Algebra & Calculus · Full GATE CSE 2019 paper

GATE 2019, Q55 2 marks · NAT
Report issue

Relational Algebra & Calculus

Question 55, GATE 2019: Relations: P(X,Y,Z)={(X1,Y1,Z1),(X1,Y1,Z2),(X2,Y2,Z2),(X2,Y4,Z4)}; Q(X,Y,T)={(X2,Y1,2),(X1,Y2,5),(X1,Y1,6),(X3,Y3,1)}; R(Y,V)={(Y1,V1),(Y3,V2),(Y2,V3),(Y2,V2)}. Count tuples in π_X(σ_{P.Y=R.Y and R.V=V2}(P×R)) − π_X(σ_{Q.Y=R.Y and Q.T>2}(Q×R)).
Tap to enlarge
Answer & solution

Official answer: 1

1. Evaluate the two projected sets separately before subtracting them. The left selection is an equality join on Y with the additional restriction R.V=V2.
2. Restricting R to V2 leaves (Y3,V2) and (Y2,V2). P has no Y3 tuple and has exactly one Y2 tuple, (X2,Y2,Z2). Thus the left join contributes X2 and its projection is {X2}. P's Y1 and Y4 rows fail the selection.
3. On the right, first keep Q rows with T>2: (X1,Y2,5) and (X1,Y1,6). The rows with T=2 and T=1 are excluded by the strict inequality.
4. The surviving Y2 row matches two R rows, with V3 and V2; the Y1 row matches (Y1,V1). These three join tuples all carry X1. Relational-algebra projection removes duplicates, so the right projected set is {X1}, not three copies of X1.
5. Set difference keeps left-side tuples absent from the right side: {X2}−{X1}={X2}. The result contains exactly 1 tuple.
6. Difference is directional and is not subtraction of the two row counts. Also, relational algebra uses set projection here; SQL without DISTINCT would require separate attention to bag semantics.

Original paper, page 16 · Answer key