CS FundamentalsVery hardGATE CS (PYQ pattern)
PA(id, k): (1,1), (2,2), (3,2), (4,3), (5,NULL), (6,4). PB(k, z): (1,9), (2,9), (2,8), (NULL,7). Let p = rows of SELECT * FROM PA LEFT JOIN PB ON PA.k = PB.k WHERE PB.k IS NULL (an anti-join), q = rows of SELECT * FROM PA WHERE k NOT IN (SELECT k FROM PB), and r = rows of SELECT * FROM PA WHERE NOT EXISTS (SELECT 1 FROM PB WHERE PB.k = PA.k). What is (p, q, r)?
- A. (3, 0, 3)
- B. (3, 3, 3)
- C. (4, 0, 4)
- D. (3, 3, 0)
Correct answer: A. (3, 0, 3)
PB contains a NULL k, so NOT IN is never true (q = 0). The anti-join and NOT EXISTS compare with = and keep rows with no match, including the NULL-k row: ids 4, 5 and 6, so p = r = 3.
More DBMS and SQL questions
- GB(id, v): (1,5), (2,12), (3,18), (4,25), (5,31), (6,39), (7,NULL). The query SELECT v / 10, COUNT() FROM GB GROUP BY v / 10 uses integer…
- Three transactions each execute R(A) followed by W(A) on the same item A. Among all interleavings of the six operations (each…
- T1: R(A), W(A), R(B) and T2: R(B), W(B), R(A), each in that order. Of the C(6,3) = 20 interleavings, how many are conflict-serializable?
- T1: W(A) W(B) and T2: W(B) W(A) run under strict 2PL (exclusive locks held until the transaction ends; a schedule counts only if no…
- Table T(x) holds the values 1, 2, 3, NULL and table U(y) holds 2, NULL. Let Q1 = SELECT COUNT() FROM T WHERE x NOT IN (SELECT y FROM U)…
- DEPT(d, name) has rows (10,A), (20,B), (30,C), (40,D) and EMP(id, dept) has 3 employees in dept 10, 2 in dept 20, 1 in dept 30 and none in…