GATE 2019 CS – Question 65
Consider the following relations P(X,Y,Z), Q(X,Y,T) and R(Y,V).
| X | Y | Z |
|---|---|---|
| X1 | Y1 | Z1 |
| X1 | Y1 | Z2 |
| X2 | Y2 | Z2 |
| X2 | Y4 | Z4 |
(relation P)
| X | Y | T |
|---|---|---|
| X2 | Y1 | 2 |
| X1 | Y2 | 5 |
| X1 | Y1 | 6 |
| X3 | Y3 | 1 |
(relation Q)
| Y | V |
|---|---|
| Y1 | V1 |
| Y3 | V2 |
| Y2 | V3 |
| Y2 | V2 |
(relation R)
How many tuples will be returned by the following relational algebra query?
$$\Pi_X\left(\sigma_{(P.Y=R.Y\wedge R.V=V2)}(P\times R)\right)-\Pi_X\left(\sigma_{(Q.Y=R.Y\wedge Q.T>2)}(Q\times R)\right)$$
Answer: ________.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 1
Explanation
The first part: tuples of $P$ joined with $R$ on $Y$ where $V=V2$, i.e. $Y\in\{Y3,Y2\}$ with $V2$: $R$ has $(Y3,V2)$ and $(Y2,V2)$. $P$ has $Y2$ with $X2$, so the first set is $\{X2\}$. The second part: $Q$ tuples with $T>2$ are $(X1,Y2,5)$ and $(X1,Y1,6)$, which join with $R$ on $Y$, so the second set is $\{X1\}$. The difference is $\{X2\}$, which has 1 tuple.