1) Let R and S be two relations with the following schema R (P,Q,R1,R2,R3) S…

2008

1) Let R and S be two relations with the following schema
R (P,Q,R1,R2,R3)
S (P,Q,S1,S2)
Where {P, Q} is the key for both schemas. Which of the following queries are equivalent?

Answer: D. Only I, III and IVAnswer: Queries I, III and IV are equivalent; II is not. Reasoning: Key fact: {P,Q} is a key for both R and S, so each (P,Q) pair appears at most once in each…

  1. A.

    Only I and II

  2. B.

    Only I and III

  3. C.

    Only I, II and III

  4. D.

    Only I, III and IV

Attempted by 92 students.

Show answer & explanation

Correct answer: D

Answer: Queries I, III and IV are equivalent; II is not.

Reasoning:

  • Key fact: {P,Q} is a key for both R and S, so each (P,Q) pair appears at most once in each relation.

  • I: Π_P(R ⋈ S) returns the set of P values for which there exists a Q such that the pair (P,Q) appears in both R and S (i.e., common (P,Q) pairs).

  • III: Π_P(Π_{P,Q}(R) ∩ Π_{P,Q}(S)) computes the intersection of (P,Q) pairs present in both relations and then projects P. This yields exactly the same set as I.

  • IV: Let A = Π_{P,Q}(R) and B = Π_{P,Q}(S). Then A − (A − B) = A ∩ B, so Π_P(A − (A − B)) = Π_P(A ∩ B), which is the same as III and hence I.

  • II: Π_P(R) ⋈ Π_P(S) joins only on P, so it returns P values that appear in R and in S possibly with different Q values. For example, if R contains (p,q1) and S contains (p,q2) with q1 ≠ q2, II includes p while I, III and IV do not. Therefore II is not equivalent to the others.

Conclusion: I, III and IV are equivalent; II is different because it ignores matching on Q.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…