CS 480: Database Systems Lecture 15 February 18, 2013.

Slides:



Advertisements
Similar presentations
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
Advertisements

Relational Algebra Chapter 4, Part A
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C6.
Chapter 3 Tuple and Domain Relational Calculus. Tuple Relational Calculus.
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.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
1 Relational Calculus Chapter 4 – Part II. 2 Formal Relational Query Languages  Two mathematical Query Languages form the basis for “real” languages.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Relational Calculus. Another Theoretical QL-Relational Calculus n Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus.
Chapter Predicate Calculus Formal language –True/False statements –Supports reasoning Usage –Integrity constraints –Non-procedural query languages.
1 Lecture 5: Relational calculus
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Introduction to Database Systems 1 Relational Calculus Relational Model : Topic 2.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C6.
Rutgers University Relational Calculus 198:541 Rutgers University.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
Lecture 3 [Self Study] Relational Calculus
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
1 CS 430 Database Theory Winter 2005 Lecture 6: Relational Calculus.
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.
Relational Calculus. Non Procedural or Declarative Calculus has variables, constants, comparison ops, logical connectives and quantifiers. There are TWO.
Relational Calculus R&G, Chapter 4. Relational Calculus Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus (DRC). Calculus.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1 Relational Algebra and Calculas Chapter 4, Part A.
Relational Algebra.
The Relational Calculus (Based on Chapter 9 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
IST 210 The Relational Language Todd S. Bacastow January 2004.
Copyright © Curt Hill The Relational Calculus Another way to do queries.
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, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 16 A First Course in Database Systems.
1 Relational Algebra & SQL Query Formulation Exercise.
CS589 Principles of DB Systems Fall 2008 Lecture 4b: Domain Independence and Safety Lois Delcambre
1 Relational Algebra. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational model supports.
Relational Algebra. CENG 3512 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.
Chapter 8 Relational Calculus.
Relational Algebra & Calculus
A First Course in Database Systems
Slides are reused by the approval of Jeffrey Ullman’s
CS 480: Database Systems Lecture 16 February 20,2013.
CS 480: Database Systems Lecture 17 February 22, 2013.
CS 480: Database Systems Lecture 13 February 13,2013.
Relational Algebra and SQL
CS 480: Database Systems Lecture 9 February 4, 2013.
Relational Calculus Chapter 4, Part B
Chapter 6: Formal Relational Query Languages
CS 480: Database Systems Lecture 8 February 1, 2013.
Relational Algebra And Calculus
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
Logics for Data and Knowledge Representation
Relational Calculus.
Relational Calculus and QBE
CS 186, Fall 2002, Lecture 8 R&G, Chapter 4
Relational Calculus and QBE
Chapter 6: Formal Relational Query Languages
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Relational Algebra & Calculus
Chapter 27: Formal-Relational Query Languages
Relational Calculus Chapter 4, Part B 7/1/2019.
Instructor: Zhe He Department of Computer Science
CSE544 Wednesday, March 29, 2006.
CS589 Principles of DB Systems Fall 2008 Lecture 4b: Domain Independence and Safety Lois Delcambre
Relational Calculus Chapter 4 – Part II.
Relational Calculus Chapter 4, Part B
Presentation transcript:

CS 480: Database Systems Lecture 15 February 18, 2013

Example { x |  y  order ((y[buyer_name] = ‘Jewel’)   z  supplies ORDER(order_id,buyer_name,item,quantity), SUPPLIES(supp_name,item) Query: Retrieve names of all the suppliers that supply all the items that ‘Jewel’ ordered. { x |  y  order ((y[buyer_name] = ‘Jewel’)   z  supplies (z[supp_name] = x[supp_name]  y[item] = z[item] )) }

Example { x |  y  order ((y[buyer_name] = ‘Jewel’)   z  supplies ORDER(order_id,buyer_name,item,quantity), SUPPLIES(supp_name,item) Query: Retrieve names of all the suppliers that supply all the items that ‘Jewel’ ordered. { x |  y  order ((y[buyer_name] = ‘Jewel’)   z  supplies (z[supp_name] = x[supp_name]  y[item] = z[item] )) }

Beer Drinking Example #3 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent every bar that serves ‘Bud’? { t |  d  drinker ( d[d_name] = t[d_name]   s  serves ( s[be_name] = ‘Bud’   f  frequents ( f [ba_name] = s[ba_name]  f [d_name] = t[d_name])))}

Beer Drinking Example #3 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent every bar that serves ‘Bud’? { t |  d  drinker ( d[d_name] = t[d_name]   s  serves ( s[be_name] = ‘Bud’   f  frequents ( f [ba_name] = s[ba_name]  f [d_name] = t[d_name])))} If the bolded formula is untrue, it doesn’t matter. That’s exactly what we want.

Domain Relational Calculus (DRC) Similar to tuple relational calculus, except that each variable is defined on an attribute, rather than a tuple. An expression in the DRC is of the form: { < x1,x2,…,xn > | P(x1,x2,…,xn) } x1,x2,…,xn are domain variables. P is a formula composed of atoms (as in TRC).

Example #1 student1(STUDENT) student2(STUDENT) STUDENT = {id,name,major,GPA} RA Query: student1  student2 Domain Relational Calculus: { < i,n,m,g > | < i,n,m,g >  student1  < i,n,m,g >  student2 }

Example #2 student(STUDENT) STUDENT = {id,name,major,GPA} RA Query: Πid(student) Domain Relational Calculus: “ n,m,g” is shorthand for  n ( m ( g (…))) { < i > |  n,m,g ( < i,n,m,g >  student )}

Example #3 student(STUDENT), enrol(ENROL) STUDENT = {id,name,major,GPA} ENROL = {id,course,grade} RA Query: Πname,grade(student enrol) Domain Relational Calculus: { < n,g2 > |  i,m,g1,c (< i,n,m,g1 >  student  < i,c,g2 >  enrol }

{ < x1,x2,…,xn > | P(x1,x2,…,xn) } Formal Definition A domain-relational-calculus expression is of the form: { < x1,x2,…,xn > | P(x1,x2,…,xn) } Where P(x1,x2,…,xn) is a formula (predicate) in which x1,x2,…,xn are free (unbound) domain variables. A free variable will be one that is not quantified by  or  . Go back one slide to show which are the free variables and which are the bound variables in the previous example.

Formal Definition Let x1,x2,…,xn be domain variables, r a relation. Then, the following are atoms: < x1,x2,…,xn >  r xi θ xj, where θ is a comparison operator xi θ c, where c is a constant An atom is a formula.

Formal Definition Same as with TRC: If P1 and P2 are formulas, then the following are also formulas: (P1), P1 P1  P2, P1  P2, P1  P2 If P1(s) contains a free domain variable s and r is a relation then the following are also formulas:  s (P1(s))  s (P1(s)) There exists s such that P1 is true For all s, P1 is true.

Beer Drinking Example #1 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which bars serve some beer that ‘John Doe’ likes? { < a > |  d, e ( < a,e >  serves  < d,e >  likes  d = ‘John Doe’ ) }

Beer Drinking Example #1 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which bars serve some beer that ‘John Doe’ likes? { < a > |  d, e ( < a,e >  serves  < d,e >  likes  d = ‘John Doe’ ) }

Beer Drinking Example #1 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which bars serve some beer that ‘John Doe’ likes? { < a > |  d, e ( < a,e >  serves  < d,e >  likes  d = ‘John Doe’ ) }

Beer Drinking Example #1 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which bars serve some beer that ‘John Doe’ likes? { < a > |  d, e ( < a,e >  serves  < d,e >  likes  d = ‘John Doe’ ) }

Beer Drinking Example #1 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which bars serve some beer that ‘John Doe’ likes? { < a > |  d, e ( < a,e >  serves  < d,e >  likes  d = ‘John Doe’ ) }

Beer Drinking Example #2 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent at least one bar that serves some beer they like? { < d > |  a, e ( < a,e >  serves  < d,e >  likes  < d,a >  frequents ) }

Beer Drinking Example #3 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent every bar that serves ‘Bud’? { < d > |  c ( < d,c >  drinker   a,e ( ( < a,e >  serves  e = ‘Bud’ )  < d,a >  frequents ) } I don’t need the  c…

Beer Drinking Example #3 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent every bar that serves ‘Bud’? { < d > |  c ( < d,c >  drinker   a,e ( ( < a,e >  serves  e = ‘Bud’ )  < d,a >  frequents ) ) } We do need the  c because if it wasn’t there then if no bar served Bud then the query would return no drinkers which would be a mistake.

Beer Drinking Example #3 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent every bar that serves ‘Bud’? { < d > |  c ( < d,c >  drinker   a,e ( ( < a,e >  serves  e = ‘Bud’ )  < d,a >  frequents ) ) } I don’t need the  c…

Beer Drinking Example #3 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent every bar that serves ‘Bud’? { < d > |  c ( < d,c >  drinker   a,e ( ( < a,e >  serves  e = ‘Bud’ )  < d,a >  frequents ) ) } I don’t need the  c…

Beer Drinking Example #3 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent every bar that serves ‘Bud’? { < d > |  c ( < d,c >  drinker   a,e ( ( < a,e >  serves  e = ‘Bud’ )  < d,a >  frequents ) ) } I don’t need the  c…

Beer Drinking Example #4 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent only bars that serve some beer they like? { < d > |  c ( < d,c >  drinker   a ( < d,a >  frequents   e ( < d,e >  likes  < a,e >  serves ) ) ) }

Beer Drinking Example #4 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent only bars that serve some beer they like? { < d > |  c ( < d,c >  drinker   a ( < d,a >  frequents   e ( < d,e >  likes  < a,e >  serves ) ) ) }

Beer Drinking Example #4 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent only bars that serve some beer they like? { < d > |  c ( < d,c >  drinker   a ( < d,a >  frequents   e ( < d,e >  likes  < a,e >  serves ) ) ) }

Beer Drinking Example #4 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent only bars that serve some beer they like? { < d > |  c ( < d,c >  drinker   a ( < d,a >  frequents   e ( < d,e >  likes  < a,e >  serves ) ) ) }

Beer Drinking Example #4 Relational Schema: DRINKER(d_name,d_city) BAR(ba_name,ba_city) BEER(be_name,type) FREQUENTS(d_name,ba_name) SERVES(ba_name,be_name) LIKES(d_name,be_name) Query: Which drinkers frequent only bars that serve some beer they like? { < d > |  c ( < d,c >  drinker   a ( < d,a >  frequents   e ( < d,e >  likes  < a,e >  serves ) ) ) }