GATE / CS ARCHIVE

GATE CSE 2002 / QUESTION 17(b)(i)

Self-join view before insertion

Database Management Systems · SQL & Queries · Full GATE CSE 2002 paper

GATE 2002, Q17(b)(i) Descriptive
Report issue

SQL & Queries

Question 17(b)(i), GATE 2002: R(A,B)={(1,2),(2,3),(2,4),(4,5),(6,7),(6,8),(9,10)}. View V is SELECT R1.A,R2.B FROM R R1,R R2 WHERE R1.B=R2.A. Original17(b)(i): Find the current contents of V.
Question 17(b)(i), GATE 2002: R(A,B)={(1,2),(2,3),(2,4),(4,5),(6,7),(6,8),(9,10)}. View V is SELECT R1.A,R2.B FROM R R1,R R2 WHERE R1.B=R2.A. Original17(b)(i): Find the current contents of V.
Question 17(b)(i), GATE 2002: R(A,B)={(1,2),(2,3),(2,4),(4,5),(6,7),(6,8),(9,10)}. View V is SELECT R1.A,R2.B FROM R R1,R R2 WHERE R1.B=R2.A. Original17(b)(i): Find the current contents of V.
Tap to enlarge
Answer & solution

Answer: V={(1,3),(1,4),(2,5)}. (no official key was published)

The view combines a tuple (u,v) in the first copy of R with a tuple (v,w) in the second and returns (u,w), so it enumerates two-edge paths. For R={(1,2),(2,3),(2,4),(4,5),(6,7),(6,8),(9,10)}, the paths 1→2→3 and 1→2→4 yield (1,3),(1,4), while 2→4→5 yields (2,5). No other second component matches a first component. Thus V contains exactly those three tuples. They are distinct, so SQL bag semantics and set semantics give the same contents for this instance.

Original paper, page 9