Question:hard

Consider the given relations \(X\), \(Y\) and \(Z\). The relation \(X\) has three columns P, Q and R. The relation \(Y\) has three columns P, Q and S. The relation \(Z\) has two columns P and T.

Relation X:
PQR
P1Q1R1
P2Q2R2
P3Q3R2

Relation Y:
PQS
P1Q12
P1Q25
P2Q16
P3Q31

Relation Z:
PT
P1T1
P3T2
P4T3
P4NULL


Consider the relational algebra expression
\[ \Pi_{P,R,S}\Big[\big(\sigma_{(Q=Q3 \vee R=R2)}[X \Join Y]\big) \Join \big(\sigma_{(S>1)}[Y \Join Z]\big)\Big] \]
where \(\Join\) denotes natural join operation.

Which of the following options is the correct output for the given expression?

Show Hint

Compute \(X \Join Y\) and \(Y \Join Z\) separately, apply each selection, then check whether the surviving P values on the two sides can ever match before joining them.
Updated On: Jul 22, 2026
  • Two rows (P1, R1, 2) and (P1, R1, 5)
  • Three rows (P1, R1, 2), (P1, R1, 5) and (P2, R2, 6)
  • One row (P1, R1, 2)
  • Zero rows
Show Solution

The Correct Option is D

Solution and Explanation

Step 1: Work out each branch's key value first, before computing every column.
The final operation is a natural join of two intermediate relations on their common columns P, Q, S. A natural join can only produce rows where the P values actually agree, so it helps to track just the P values on each side before doing the full column-by-column join.

Step 2: Track the P value on the left branch.
\(X \Join Y\) only keeps rows where P and Q match between X and Y. Checking each X row against Y gives two survivors: (P1,Q1,R1,2) and (P3,Q3,R2,1).
Applying \(\sigma_{(Q=Q3 \vee R=R2)}\): the P1 row has Q=Q1 and R=R1, neither condition holds, so it is removed. The P3 row has Q=Q3, so it survives.
So the left branch collapses to a single row with P=P3.

Step 3: Track the P value on the right branch.
\(Y \Join Z\) matches on P alone. P1 appears twice in Y and once in Z, giving two joined rows with P=P1: (P1,Q1,2,T1) and (P1,Q2,5,T1). P2 has no partner in Z. P3 gives (P3,Q3,1,T2).
Applying \(\sigma_{(S>1)}\): the two P1 rows have S=2 and S=5, both greater than 1, so both survive. The P3 row has S=1, which fails \(S>1\), so it is removed.
So the right branch collapses to two rows, and both of them have P=P1 (the P3 row was filtered out by the S>1 condition).

Step 4: Compare the P values across the two branches.
The left branch only has P=P3. The right branch only has P=P1. Since a natural join requires equal P values to produce any tuple, and P3 never equals P1, there is no way for any pair of rows to combine.

Step 5: Conclude without needing to check Q or S at all.
Because the P values already disagree completely between the two sides, the join is empty regardless of what the Q and S columns contain, and projecting an empty relation onto P, R, S still gives zero rows. This matches option (D).\[ \boxed{\text{Zero rows}} \]
Was this answer helpful?
0