Presentation is loading. Please wait.

Presentation is loading. Please wait.

Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science 15-415 - Database Applications C. Faloutsos Relational tuple calculus.

Similar presentations


Presentation on theme: "Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science 15-415 - Database Applications C. Faloutsos Relational tuple calculus."— Presentation transcript:

1 Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science 15-415 - Database Applications C. Faloutsos Relational tuple calculus

2 Carnegie Mellon 15-415 - C. Faloutsos2 General Overview - rel. model history concepts Formal query languages –relational algebra –rel. tuple calculus –rel. domain calculus

3 Carnegie Mellon 15-415 - C. Faloutsos3 Overview - detailed rel. tuple calculus –why? –details –examples –equivalence with rel. algebra –more examples; ‘safety’ of expressions re. domain calculus + QBE

4 Carnegie Mellon 15-415 - C. Faloutsos4 Motivation Q: weakness of rel. algebra? A: procedural –describes the steps (ie., ‘how’) –(still useful, for query optimization)

5 Carnegie Mellon 15-415 - C. Faloutsos5 Solution: rel. calculus –describes what we want –two equivalent flavors: ‘tuple’ and ‘domain’ calculus –basis for SQL and QBE, resp.

6 Carnegie Mellon 15-415 - C. Faloutsos6 Rel. tuple calculus (RTC) first order logic ‘Give me tuples ‘t’, satisfying predicate P - eg:

7 Carnegie Mellon 15-415 - C. Faloutsos7 Details symbols allowed: quantifiers

8 Carnegie Mellon 15-415 - C. Faloutsos8 Specifically Atom

9 Carnegie Mellon 15-415 - C. Faloutsos9 Specifically Formula: –atom –if P1, P2 are formulas, so are –if P(s) is a formula, so are

10 Carnegie Mellon 15-415 - C. Faloutsos10 Specifically Reminders: –DeMorgan –implication: –double negation: ‘every human is mortal : no human is immortal’

11 Carnegie Mellon 15-415 - C. Faloutsos11 Reminder: our Mini-U db

12 Carnegie Mellon 15-415 - C. Faloutsos12 Examples find all student records output tuple of type ‘STUDENT’

13 Carnegie Mellon 15-415 - C. Faloutsos13 Examples (selection) find student record with ssn=123

14 Carnegie Mellon 15-415 - C. Faloutsos14 Examples (selection) find student record with ssn=123

15 Carnegie Mellon 15-415 - C. Faloutsos15 Examples (projection) find name of student with ssn=123

16 Carnegie Mellon 15-415 - C. Faloutsos16 Examples (projection) find name of student with ssn=123 ‘t’ has only one column

17 Carnegie Mellon 15-415 - C. Faloutsos17 ‘Tracing’ s t

18 Carnegie Mellon 15-415 - C. Faloutsos18 Examples cont’d (union) get records of both PT and FT students

19 Carnegie Mellon 15-415 - C. Faloutsos19 Examples cont’d (union) get records of both PT and FT students

20 Carnegie Mellon 15-415 - C. Faloutsos20 Examples difference: find students that are not staff (assuming that STUDENT and STAFF are union-compatible)

21 Carnegie Mellon 15-415 - C. Faloutsos21 Examples difference: find students that are not staff

22 Carnegie Mellon 15-415 - C. Faloutsos22 Cartesian product eg., dog-breeding: MALE x FEMALE gives all possible couples x =

23 Carnegie Mellon 15-415 - C. Faloutsos23 Cartesian product find all the pairs of (male, female)

24 Carnegie Mellon 15-415 - C. Faloutsos24 ‘Proof’ of equivalence rel. algebra rel. tuple calculus

25 Carnegie Mellon 15-415 - C. Faloutsos25 Overview - detailed rel. tuple calculus –why? –details –examples –equivalence with rel. algebra –more examples; ‘safety’ of expressions re. domain calculus + QBE

26 Carnegie Mellon 15-415 - C. Faloutsos26 More examples join: find names of students taking 15-415

27 Carnegie Mellon 15-415 - C. Faloutsos27 Reminder: our Mini-U db

28 Carnegie Mellon 15-415 - C. Faloutsos28 More examples join: find names of students taking 15-415

29 Carnegie Mellon 15-415 - C. Faloutsos29 More examples join: find names of students taking 15-415 projection selection join

30 Carnegie Mellon 15-415 - C. Faloutsos30 More examples 3-way join: find names of students taking a 2-unit course

31 Carnegie Mellon 15-415 - C. Faloutsos31 Reminder: our Mini-U db

32 Carnegie Mellon 15-415 - C. Faloutsos32 More examples 3-way join: find names of students taking a 2-unit course selection projection join

33 Carnegie Mellon 15-415 - C. Faloutsos33 More examples 3-way join: find names of students taking a 2-unit course - in rel. algebra??

34 Carnegie Mellon 15-415 - C. Faloutsos34 Even more examples: self -joins: find Tom’s grandparent(s)

35 Carnegie Mellon 15-415 - C. Faloutsos35 Even more examples: self -joins: find Tom’s grandparent(s)

36 Carnegie Mellon 15-415 - C. Faloutsos36 Hard examples: DIVISION find suppliers that shipped all the ABOMB parts

37 Carnegie Mellon 15-415 - C. Faloutsos37 Hard examples: DIVISION find suppliers that shipped all the ABOMB parts

38 Carnegie Mellon 15-415 - C. Faloutsos38 General pattern three equivalent versions: –1) if it’s bad, he shipped it –2)either it was good, or he shipped it –3) there is no bad shipment that he missed

39 Carnegie Mellon 15-415 - C. Faloutsos39 More on division find (SSNs of) students that take all the courses that ssn=123 does (and maybe even more) find students ‘s’ so that if 123 takes a course => so does ‘s’

40 Carnegie Mellon 15-415 - C. Faloutsos40 More on division find students that take all the courses that ssn=123 does (and maybe even more)

41 Carnegie Mellon 15-415 - C. Faloutsos41 Safety of expressions FORBIDDEN: It has infinite output!! Instead, always use

42 Carnegie Mellon 15-415 - C. Faloutsos42 Overview - conclusions rel. tuple calculus: DECLARATIVE –dfn –details –equivalence to rel. algebra rel. domain calculus + QBE


Download ppt "Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science 15-415 - Database Applications C. Faloutsos Relational tuple calculus."

Similar presentations


Ads by Google