Relational Calculus   Logic, like whiskey, loses its beneficial effect when taken in too large quantities. --Lord Dunsany.

Slides:



Advertisements
Similar presentations
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra) Query Formulation Exercise.
Advertisements

Relational Algebra Chapter 4, Part A
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Part B.
1 TRC vs DRC 한욱신. 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.
Relational Algebra Rohit Khokher. Relational Algebra Set Oriented Operations UnionIntersectionDifference Cartesian Product Relation Oriented Operations.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A Modified by Donghui Zhang.
INFS614, Fall 08 1 Relational Algebra Lecture 4. INFS614, Fall 08 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of.
1 Relational Calculus Chapter 4 – Part II. 2 Formal Relational Query Languages  Two mathematical Query Languages form the basis for “real” languages.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4.
Relational Algebra Content based on Chapter 4 Database Management Systems, (Third Edition), by Raghu Ramakrishnan and Johannes Gehrke. McGraw Hill, 2003.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
R ELATIONAL A LGEBRA M ORE POINTERS FROM T UESDAY.
1 Relational Algebra. 2 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports.
Relational Calculus. Another Theoretical QL-Relational Calculus n Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus.
1 Lecture 5: Relational calculus
Relational Calculus CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth   We will occasionally use this arrow notation unless there is danger of.
CS 4432query processing1 CS4432: Database Systems II.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Introduction to Database Systems 1 Relational Algebra Relational Model: Topic 3.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Relational Calculus R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion. Ronald Graham Elements of Ramsey.
Introduction to Database Systems 1 Relational Calculus Relational Model : Topic 2.
Rutgers University Relational Algebra 198:541 Rutgers University.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Relational Calculus CS 186, Fall 2003, Lecture 6 R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion.
Rutgers University Relational Calculus 198:541 Rutgers University.
CSCD343- Introduction to databases- A. Vaisman1 Relational Algebra.
Relational Algebra, R. Ramakrishnan and J. Gehrke (with additions by Ch. Eick) 1 Relational Algebra.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4.
1 Relational Algebra. 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports.
Database Management Systems,1 Relational Calculus.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science Database Applications Lecture#6: Relational calculus.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
Relational Calculus R&G, Chapter 4. Relational Calculus Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus (DRC). Calculus.
Relational Calculus CS 186, Spring 2005, Lecture 9 R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1 Relational Algebra and Calculas Chapter 4, Part A.
Database Management Systems 1 Raghu Ramakrishnan Relational Algebra Chpt 4 Xin Zhang.
Relational Algebra.
1 Relational Algebra Chapter 4, Sections 4.1 – 4.2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 4 Relational Algebra.
CSCD34-Data Management Systems - A. Vaisman1 Relational Algebra.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 – DB Applications C. Faloutsos & A. Pavlo Lecture#5: Relational calculus.
1 Copyright © Kyu-Young Whang Relational Calculus Chapter 4, Part B.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L5_Relational Calculus 1 Relational Calculus Chapter 4 – Part B.
Relational Calculus Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
1 CS122A: Introduction to Data Management Lecture #7 Relational Algebra I Instructor: Chen Li.
1 Relational Algebra. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational model supports.
Relational Calculus Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Relational Calculus Chapter 4, Section 4.3.
Relational Algebra & Calculus
Relational Calculus Chapter 4, Part B
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Relational Algebra.
Lecture#5: Relational calculus
Relational Calculus.
CS 186, Fall 2002, Lecture 8 R&G, Chapter 4
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Relational Algebra & Calculus
Relational Calculus Chapter 4, Part B 7/1/2019.
Relational Algebra Chapter 4 - part I.
Relational Calculus Chapter 4 – Part II.
Relational Calculus Chapter 4, Part B
Presentation transcript:

Relational Calculus   Logic, like whiskey, loses its beneficial effect when taken in too large quantities. --Lord Dunsany

Relational Calculus Query has the form: {T | p(T)} –p(T) is a formula containing T Answer = tuples T for which p(T) = true.

Formulae Atomic formulae: T  Relation T.a op T.b T.a op constant … op is one of A formula can be: – an atomic formula –

Free and Bound Variables Quantifiers:  and  Use of or binds X. –A variable that is not bound is free. Recall our definition of a query: –{T | p(T)} Important restriction: — T must be the only free variable in p(T). — all other variables must be bound using a quantifier.

Simple Queries Find all sailors with rating above 7 Find names and ages of sailors with rating above 7. –Note: S is a variable of 2 fields (i.e. S is a projection of Sailors) { S |S  Sailors  S.rating > 7} { S |  S1  Sailors ( S1.rating > 7  S.sname = S1.sname  S.age = S1.age )}

Find sailors rated > 7 who’ve reserved boat #103 { S | S  Sailors  S.rating > 7   R(R  Reserves  R.sid = S.sid  R.bid = 103) } Joins

Joins (continued) This may look cumbersome, but it’s not so different from SQL! { S | S  Sailors  S.rating > 7   R(R  Reserves  R.sid = S.sid   B(B  Boats  B.bid = R.bid  B.color = ‘red’)) } Find sailors rated > 7 who’ve reserved a red boat

Universal Quantification Find sailors who’ve reserved all boats { S | S  Sailors   B  Boats (  R  Reserves (S.sid = R.sid  B.bid = R.bid)) }

A trickier example… { S | S  Sailors   B  Boats ( B.color = ‘red’   R(R  Reserves  S.sid = R.sid  B.bid = R.bid)) } Find sailors who’ve reserved all Red boats in existence… { S | S  Sailors   B  Boats ( B.color  ‘red’   R(R  Reserves  S.sid = R.sid  B.bid = R.bid)) } Alternatively…

a  b is the same as  a  b a T F T F b T TT F

A Remark: Unsafe Queries  syntactically correct calculus queries that have an infinite number of answers! Unsafe queries. –e.g., –Solution???? Don’t do that!

Your turn … Schema: Movie(title, year, studioName) ActsIn(movieTitle, starName) Star(name, gender, birthdate, salary) Queries to write in Relational Calculus: 1.Find all movies by Paramount studio 2.… movies whose stars are all women 3.… movies starring Kevin Bacon 4.Find stars who have been in a film w/Kevin Bacon 5.Stars within six degrees of Kevin Bacon* 6.Stars connected to K. Bacon via any number of films** * Try two degrees for starters ** Good luck with this one!

Answers … 1.Find all movies by Paramount studio {M | M  Movie  M.studioName = ‘Paramount’}

Answers … 2.Movies whose stars are all women {M | M  Movie   A  ActsIn((A.movieTitle = M.title)   S  Star(S.name = A.starName  S.gender = ‘F’))}

Answers … 3.Movies starring Kevin Bacon {M | M  Movie   A  ActsIn(A.movieTitle = M.title  A.starName = ‘Bacon’))}

Answers … 4.Stars who have been in a film w/Kevin Bacon {S | S  Star   A  ActsIn(A.starName = S.name   A2  ActsIn(A2.movieTitle = A.movieTitle  A2.starName = ‘Bacon’))} moviestar A2: S: name… ‘Bacon’ moviestar A:

Answers … 5.Stars within six degrees of Kevin Bacon {S | S  Star   A  ActsIn(A.starName = S.name   A2  ActsIn(A2.movieTitle = A.movieTitle   A3  ActsIn(A3.starName = A2.starName   A4  ActsIn(A4.movieTitle = A3.movieTitle  A4.starName = ‘Bacon’))} two

Two degrees: S: name… ‘Bacon’ moviestar A2: moviestar A: moviestar A4: moviestar A3:

Answers … 6.Stars connected to K. Bacon via any number of films Sorry … that was a trick question –Not expressible in relational calculus!! What about in relational algebra? –We will be able to answer this question shortly …

Expressive Power Expressive Power (Theorem due to Codd): –Every query that can be expressed in relational algebra can be expressed as a safe query in relational calculus; the converse is also true. Relational Completeness: Query language (e.g., SQL) can express every query that is expressible in relational algebra/calculus. (actually, SQL is more powerful, as we will see…)

Question: Can we express query #6 in relational algebra? A: If we could, then by Codd’s theorem we could also express it in relational calculus. However, we know the latter is not possible, so the answer is no.

Summary Formal query languages — simple and powerful. –Relational algebra is operational used as internal representation for query evaluation plans. –Relational calculus is “declarative” query = “what you want”, not “how to compute it” –Same expressive power --> relational completeness. Several ways of expressing a given query –a query optimizer should choose the most efficient version.