Question
Consider the relations and , where is a primary key and is a foreign key referencing . Consider the query
Let LOJ denote the natural left outer-join operation. Assume that and contain no null values.
Which one of the following queries is NOT equivalent to Q?
Official answer and solution
- Official answer
- C
- From
- Official GATE 2018 answer key
Solution
Analyze tuple containment and NULL preservation when foreign key constraints and selections are combined with left outer join.
Given is primary key and is foreign key referencing , every value of in is guaranteed to exist in .
Query retains only tuples where and .
Evaluate the choices:
- (A) : Because every tuple of matches some tuple of , preserves all tuples. Filtering by produces identical results to .
- (B) : Since every tuple of finds a match in , yields the exact same tuples as . Selection produces identical results to .
- (C) : Here, the right relation is pre-filtered. Tuples of with find no match in . Because this is a LEFT OUTER JOIN, these tuples are retained in the output with NULL values for attribute . In contrast, query discards tuples with . Hence, query C is NOT equivalent to .
- (D) : Pre-filtering keeps only tuples with . Since each has a match in , the left outer join is identical to inner join, matching .
C
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2018 Computer Science and Information Technology (CS)
- Question
- 51 of 65, printed as CS Q.41
- 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.