Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 TRC vs DRC 2003. 10. 12 한욱신. 2 Queries in TRC and DRC  TRC Q = {t| f(t)} where t is a (free) tuple variable and f(t) is a well-formed formula  DRC.

Similar presentations


Presentation on theme: "1 TRC vs DRC 2003. 10. 12 한욱신. 2 Queries in TRC and DRC  TRC Q = {t| f(t)} where t is a (free) tuple variable and f(t) is a well-formed formula  DRC."— Presentation transcript:

1 1 TRC vs DRC 2003. 10. 12 한욱신

2 2 Queries in TRC and DRC  TRC Q = {t| f(t)} where t is a (free) tuple variable and f(t) is a well-formed formula  DRC Q = {x 1,x 2,..,x k | f(x 1,x 2,..,x k )} where x i is a (free) domain variable and f(x 1,x 2,..,x k ) is a well- formed formula

3 3 Well-formed formula  Wffs are constructed using the following rules  Each atomic formula is a wff  If P, Q are wffs, then so are NOT P, (P AND Q), (P OR Q), and (P  Q)  If x is a (tuple or domain) variable and P is a wff, then so are  x P, and  x P

4 4 Atomic formulas in TRC and DRC  TRC R(t) where R is a relation name and t is a tuple variable t i [A]  t j [B] where t i and t j are tuple variables; A and B are attributes names;  is a comparison operator (=,, , ,  ) t i [A]  constant  DRC R(x 1,x 2,…,x k ) where R is a relation name and x i is a domain variable or constant x  y where x and y are domain variables x  constant where x is a domain variable

5 5 Example Schema  Sailors(sid, sname, rating, age)  Boats(bid, bname, color)  Reserves(sid, bid, date)

6 6 Q1) Find sailors who’ve reserved at least one boat  sid (Sailors Reserves) {p|(  r)(  s)(Reserves(r) AND Sailors(s) AND /* initiate tuple variables */ r[sid] = s[sid] AND /* join condition */ p[1st attr] = s[sid])}/* projection */ {s| (  b)(  d)(  s2)(  sn)(  r)(  a)(Reserves(s,b,d) AND Sailors(s2, sn, r,a) AND /* initiate tuple variables */ s = s2) /* join condition */ } Relational Algebra TRC DRC

7 7 Q2) Find sid’s of sailors who’ve reserved a red or a green boat {p|(  r)(  s)(  b)(Reserves(r) AND Sailors(s) AND Boats(b) AND /* initiate tuple variables */ r[sid] = s[sid] AND /* join condition */ r[bid] = b[bid] AND /* join condition */ (b[color] = ‘red’ OR b[color] = ‘green’) AND /* selection condition */ p[1st attr] = s[sname])}/* projection */ {s| (  b)(  d)(  s2)(  sn)(  r)(  a)(  b2)(  bn)(  c)(Reserves(s,b,d) AND Sailors(s2, sn, r,a) AND Boats(b2, bn, c) AND /* initiate tuple variables */ s = s2 AND b=b2 AND /* join condition */ (c = ‘red’ OR c = ‘green’))} Relational Algebra TRC DRC

8 8 Q3) Find sid’s of sailors who’ve reserved a red and a green boat {p|(  r)(  s)(  b)(Sailors(s) AND Boats(b1) AND Reserves(r1) AND Boats(b2) AND Reserves(r2) AND /* initiate tuple variables */ s[sid]=r1[sid] AND r1[bid]=b1[bid] AND s[sid]=r2[sid] AND r2[bid]=b2[bid] AND (b1[color]=‘red’ AND b2[color]=‘green’ AND p[1st attr] = s[sname])}/* projection */ {s| (  b)(  d)(  s2)(  sn)(  r)(  a)(  b2)(  bn)(  c) )(  s2’)(  sn’)(  r’)(  a’)(  b2’)(  bn’)(  c’) ( Reserves(s,b,d) AND Sailors(s2, sn, r,a) AND Boats(b2, bn, c) AND Sailors(s2’, sn’, r’,a’) AND Boats(b2’, bn’, c’) AND /* initiate tuple variables */ s = s2 AND b=b2 AND s = s2’ AND b=b2’ AND/* join condition */ (c = ‘red’ AND c’ = ‘green’))} Relational Algebra TRC DRC


Download ppt "1 TRC vs DRC 2003. 10. 12 한욱신. 2 Queries in TRC and DRC  TRC Q = {t| f(t)} where t is a (free) tuple variable and f(t) is a well-formed formula  DRC."

Similar presentations


Ads by Google