Question

Consider the relations r(A,B)r(A, B) and s(B,C)s(B, C), where s.Bs.B is a primary key and r.Br.B is a foreign key referencing s.Bs.B. Consider the query

Q:r⋈(σB<5(s))Q: r \bowtie (\sigma_{B<5}(s))

Let LOJ denote the natural left outer-join operation. Assume that rr and ss contain no null values.

Which one of the following queries is NOT equivalent to Q?

Choose one option
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 s.Bs.B is primary key and r.Br.B is foreign key referencing s.Bs.B, every value of BB in rr is guaranteed to exist in ss.
Query Q=r⋈(σB<5(s))Q = r \bowtie (\sigma_{B < 5}(s)) retains only tuples where r.B=s.Br.B = s.B and B<5B < 5.

Evaluate the choices:

  • (A) σB<5(r⋈s)\sigma_{B < 5}(r \bowtie s): Because every tuple of rr matches some tuple of ss, r⋈sr \bowtie s preserves all rr tuples. Filtering by B<5B < 5 produces identical results to QQ.
  • (B) σB<5(r LOJ s)\sigma_{B < 5}(r \text{ LOJ } s): Since every tuple of rr finds a match in ss, r LOJ sr \text{ LOJ } s yields the exact same tuples as r⋈sr \bowtie s. Selection σB<5\sigma_{B < 5} produces identical results to QQ.
  • (C) r LOJ (σB<5(s))r \text{ LOJ } (\sigma_{B < 5}(s)): Here, the right relation is pre-filtered. Tuples of rr with B≥5B \ge 5 find no match in σB<5(s)\sigma_{B < 5}(s). Because this is a LEFT OUTER JOIN, these tuples are retained in the output with NULL values for attribute CC. In contrast, query QQ discards tuples with B≥5B \ge 5. Hence, query C is NOT equivalent to QQ.
  • (D) σB<5(r) LOJ s\sigma_{B < 5}(r) \text{ LOJ } s: Pre-filtering rr keeps only tuples with B<5B < 5. Since each has a match in ss, the left outer join is identical to inner join, matching QQ.
Final answer

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.