Question
Consider the following relations , and :
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 |
How many tuples will be returned by the following relational algebra query?
Answer: ________.
Official answer and solution
- Official answer
- 1
- From
- Official GATE 2019 answer key
Solution
Evaluate the two projection terms separately and take their set difference.
We are given the relational algebra expression:
Step 1: Evaluate the first term:
- In relation , tuples with are and . So the qualifying values from are and .
- Joining with on , we find tuples in having :
- has (no match)
- has (no match)
- has (matches )
- has (no match)
- Projecting attribute yields:
Step 2: Evaluate the second term:
- In relation , tuples satisfying are:
- with
- with
(Tuple has , and has )
- Now check if these values () exist in relation :
- contains (in ) and (in and ). Both exist in .
- Projecting attribute from the matching tuples:
Both and have .
Thus:
Step 3: Set difference:
The resulting relation contains exactly 1 tuple, namely .
Therefore, the number of tuples returned is 1.
1
Treating as which would include with , making the set difference empty ( tuples).
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2019 Computer Science and Information Technology (CS)
- Question
- 65 of 65, printed as CS Q.55
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.