GATE / CS ARCHIVE

GATE CSE 2018 / QUESTION 41

Selection and left outer join

Database Management Systems · Relational Algebra & Calculus · Full GATE CSE 2018 paper

GATE 2018, Q41 2 marks · MCQ
Report issue

Relational Algebra & Calculus

Question 41, GATE 2018: Relations r(A,B),s(B,C) have no nulls; s.B is primary and r.B foreign key to s.B. Q=r⋈σ_(B<5)(s). Which differs? A σ_(B<5)(r⋈s); B σ_(B<5)(r LOJ s); C r LOJ σ_(B<5)(s); D σ_(B<5)(r) LOJ s.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Method

An enforced non-null foreign key means each r tuple initially has exactly one matching s tuple. Consequently an unfiltered left outer join has no unmatched left tuples and behaves like an inner join. Applying the filter on r first also guarantees all its retained tuples match. Filtering only the right input before an outer join changes this: left tuples whose matches were filtered out still survive with null extension. This is why moving a predicate across an outer join requires more care than across an inner join.

Solution

Every r tuple has a matching s tuple by the non-null foreign key. Thus the unfiltered natural left join equals the inner join, and filtering B<5 before or after it gives the same matched rows. In C, filtering s first removes matches for r rows with B≥5, but the left join preserves those r rows with null-extended C. Q discards them instead. For example r={(a, 6)}, s={(6, c)} makes Q empty while option C retains(a, 6, NULL). Hence C alone is not equivalent.

Original paper, page 17 · Answer key