GATE / CS ARCHIVE

GATE CSE 1991 / QUESTION 12(b.ii)

Projects with an outside-city supplier

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

GATE 1991, Q12(b.ii) Descriptive
Report issue

Relational Algebra & Calculus

Question 12(b.ii), GATE 1991: SUPPLIER(SCODE,SNAME,CITY), PART(PCODE,PNAME,PDESC,CITY), PROJECTS(PRCODE,PRNAME,CITY), SPPR(SCODE,PCODE,PRCODE,QTY). SPPR records shipments of parts by suppliers to projects. Give relational algebra for project codes supplied by at least one supplier in a different city.
Question 12(b.ii), GATE 1991: SUPPLIER(SCODE,SNAME,CITY), PART(PCODE,PNAME,PDESC,CITY), PROJECTS(PRCODE,PRNAME,CITY), SPPR(SCODE,PCODE,PRCODE,QTY). SPPR records shipments of parts by suppliers to projects. Give relational algebra for project codes supplied by at least one supplier in a different city.
Question 12(b.ii), GATE 1991: SUPPLIER(SCODE,SNAME,CITY), PART(PCODE,PNAME,PDESC,CITY), PROJECTS(PRCODE,PRNAME,CITY), SPPR(SCODE,PCODE,PRCODE,QTY). SPPR records shipments of parts by suppliers to projects. Give relational algebra for project codes supplied by at least one supplier in a different city.
Tap to enlarge
Answer & solution

Answer: π_P.PRCODE(σ_S.CITY≠P.CITY((ρ_S SUPPLIER) ⋈_S.SCODE=X.SCODE (ρ_X SPPR) ⋈_X.PRCODE=P.PRCODE (ρ_P PROJECTS))). (no official key was published)

Rename SUPPLIER as S, SPPR as X and PROJECTS as P so that both CITY attributes can be referenced explicitly. Form J=(S ⋈_{S.SCODE=X.SCODE} X) ⋈_{X.PRCODE=P.PRCODE} P. Then return π_{P.PRCODE}(σ_{S.CITY≠P.CITY}(J)).

The joins establish that S actually supplies P through a shipment row. The selection keeps witnesses whose endpoint cities differ, and the projection returns the set of project codes having at least one such witness. A project may also have local suppliers and must still appear: the condition is existential, not a requirement that every supplier be out of town. A natural join over unrenamed relations would wrongly equate the two CITY attributes and suppress precisely the rows sought, so use explicit theta joins or rename the city columns before joining.

Original paper, page 7