Dr. Alexandra I. Cristea CS 319: Theory of Databases: C6.

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

Dr. Alexandra I. Cristea CS 319: Theory of Databases.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C3.
Dr. A.I. Cristea CS 319: Theory of Databases: FDs.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C6.
CS 319: Theory of Databases: C4
Relational Calculus and Datalog
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Part B.
The Relational Calculus
Chapter 3 Tuple and Domain Relational Calculus. Tuple Relational Calculus.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
1 CHAPTER 4 RELATIONAL ALGEBRA AND CALCULUS. 2 Introduction - We discuss here two mathematical formalisms which can be used as the basis for stating and.
Ver 1,12/09/2012Kode :CCs 111,Sistem basis DataFASILKOM Chapter 5: Other Relational Languages Database System Concepts, 5th Ed. ©Silberschatz, Korth and.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
RELATIONAL CALCULUS Rohit Khokher. INTRODUCTION Relational calculus is a formal query language where the queries are expressed as variables and formulas.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Domain Relational Calculus and Query-by-Example CS157a John Eagle.
Relational Calculus Ameetinder Singh CS 157A. Tuple Relational Calculus  non-procedural query language as compared to relational algebra that is procedural.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Ordering the Display of Tuples List in alphabetic order the names of all customers having.
Relational Calculus. Another Theoretical QL-Relational Calculus n Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Query by example (based on notes by Silberchatz,Korth, and Sudarshan.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C7.
Chapter 5 Other Relational Languages By Cui, Can B.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C3.
©Silberschatz, Korth and Sudarshan1Database System Concepts Tuple and Domain Calculus Tuple Relational Calculus Domain Relational Calculus.
Relational Algebra. Relational Query Languages n Query = “retrieval program” n Language examples: ù Theoretical : 1. Relational Algebra 2. Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Calculus Objectives  Tuple Calculus  Domain Calculus  QBE & SQL  Related Examples.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C6.
Rutgers University Relational Calculus 198:541 Rutgers University.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Review “Query Languages” Algebra, Calculus, and SQL.
Relational Algebra Instructor: Mohamed Eltabakh 1.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model III (based on notes by Silberchatz,Korth, and.
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 System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Chapter 8 Relational Calculus. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Computing & Information Sciences Kansas State University Thursday, 08 Feb 2007CIS 560: Database System Concepts Lecture 11 of 42 Thursday, 08 February.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Query Languages Tuple Relational Calculus Domain Relational Calculus.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
Dr. Alexandra I. Cristea CS 319: Theory of Databases: Exam preparation.
Database System Concepts, 5th Ed. Bin Mu at Tongji University Chapter 5: Other Relational Languages.
Computing & Information Sciences Kansas State University Wednesday, 17 Sep 2008CIS 560: Database System Concepts Lecture 9 of 42 Wednesday, 18 September.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L5_Relational Calculus 1 Relational Calculus Chapter 4 – Part B.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Relational Algebra Instructor: Mohamed Eltabakh 1.
Relational Calculus Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Relational Calculus Chapter 4, Section 4.3.
Session 3 Welcome: To session 3-the fourth learning sequence
CS 480: Database Systems Lecture 16 February 20,2013.
CS 480: Database Systems Lecture 17 February 22, 2013.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Relational Calculus Chapter 4, Part B
Goal for this lecture Demonstrate how we can prove that one query language is more expressive than (i.e., “contained in” as described in the book) another.
Chapter 5: Other Relational Languages
Session 3 Welcome: To session 3-the second learning sequence
Relational Calculus.
Instructor: Mohamed Eltabakh
Introduction to SQL Holliday - COEN 178.
Relational Calculus and QBE
Schedule Today: Next And then Relational Algebra.
Relational Calculus and QBE
Relational Calculus Chapter 4, Part B 7/1/2019.
Relational Calculus Chapter 4, Part B
CS 405G: Introduction to Database Systems
Presentation transcript:

Dr. Alexandra I. Cristea CS 319: Theory of Databases: C6

2 … previous RA

3 Content 1.Generalities DB 2.Integrity constraints (FD revisited) 3.Relational Algebra (revisited) 4.Query optimisation 5.Tuple calculus 6.Domain calculus 7.Query equivalence 8.Temporal Data 9.No Nulls 10.The Askew Wall

4 Tuple Calculus non-procedural query language A query in TC is expressed as: {t|P(t)} where: t – set of tuples (also called free or range variable) P – predicate that is true for t (also called formula) Also: t[A] – value of tuple t on attribute A t  r – means the tuple t is in relation r

5 Example TC language QUEL (used by INGRES DBMS) SQL (to some extent)

6 Examples TC 1.{t | t  loan ^ t[amount] > 1200} 2.{t |  s  loan (t[loan-number] = s[loan-number] ^ s[amount] > 1200)}

7 Satefy of expressions: Tuple Calculus (& DC) A TC expression {t | P(t)} may give an infinite relation, e.g., { t |  (t  loan) } Define dom(P) as the set of all values referenced by P (e.g. literals or relations) A TC expression {t | P(t)} is safe when all values appearing in the result are values from dom(P).

8 Queries in TC & DC Translate the following questions (for the bank database) to the tuple & domain calculus: 1.Give the name of customers that have a loan with a branch where they also have an account. 2.Give the name of customers who have a loan at a branch where they do not have an account. 3.Give the name of customers who have a loan at every branch where they have an account. 4.Give the name of customers who have loans only at branches where they have an account.

9 1. Give the name of customers that have a loan with a branch where they also have an account. TC: {t|  b  borrower(t[c_n]=b[c_n] ^  l  loan(l[l_n]=b[l_n] ^  a  account(a[b_n]=l[b_n] ^  d  depositor(a[a_n]=d[a_n] ^ d[c_n]=b[c_n] ))))}

10 2. Give the name of customers who have a loan at a branch where they do not have an account. TC: {t|  b  borrower(t[c_n]=b[c_n] ^  l  loan(l[l_n]=b[l_n] ^  a  account(a[b_n]=l[b_n] ^  d  depositor(a[a_n]=d[a_n] ^ d[c_n]=b[c_n] ))))}

11 3. Give the name of customers who have a loan at every branch where they have an account. TC: {t|  d  depositor(t[c_n]=d[c_n] ^  d2  depositor((d2[c_n]=d[c_n] ^  a  account(a[a_n]=d2[a_n])) => (  l  loan(l[b_n]=a[b_n] ^  b  borrow(b[l_n]=l[l_n] ^ b[c_n]=d2[c_n])))))} This is necessary for the safety of the expression, to reduce the search space

12 4. Give the name of customers who have loans only at branches where they have an account. TC: {t|  d  borrow(t[c_n]=d[c_n] ^  d2  borrow((d2[c_n]=d[c_n] ^  a  loan(a[l_n]=d2[l_n]) => (  l  account(l[b_n]=a[b_n] ^  b  depositor(b[a_n]=l[a_n] ^ b[c_n]=d2[c_n]))))))}

13 4. Give the name of customers who have loans only at branches where they have an account. TC: {t|  b  borrow(t[c_n]=b[c_n] ^  b2  borrow((b2[c_n]=b[c_n] ^  l  loan(l[l_n]=b2[l_n])) => (  a  account(a[b_n]=l[b_n] ^  d  depositor(d[a_n]=a[a_n] ^ d[c_n]=n2[c_n])))))} With more intuitive attrs naming.

14 Library TC/DC questions 1.Give the name and department of borrowers, and the ISBN-number of the books of which they were the first borrower. 2.Give the name and department of borrowers who have never borrowed the most recently purchased copy of a book. 3.Give the title of books that are “present” in the library, reserved by someone, but not yet borrowed (by anyone).

15 1. Give the name and department of borrowers, and the ISBN-number of the books of which they were the first borrower. TC: {t |  b  borrow( t[name]=b[name] ^ t[department]=b[department] ^  c  copy(b[barcode]=c[barcode] ^ t[ISBN]=c[ISBN] ^  c2  copy(c2[ISBN]=c[ISBN] ^  b2  borrow(b2[barcode]=c2[barcode] ^ b2[from]<b[from])))) }

16 2. Give the name and department of borrowers who have never borrowed the most recently purchased copy of a book. TC {t |  b  borrow( t[name]=b[name] ^ t[department]=b[department] ^  b2  borrow((b2[name]=b[name] ^ b2[department]=b[department] ^  c2  copy (c2[barcode]=b2[barcode])) => (  c3  copy(c3[ISBN]=c2[ISBN] ^ c3[cpYear]>c2[cpYear] ^ b2[from]  c3[cpYear])))}

17 3. Give the title of books that are “present” in the library, reserved by someone, but not yet borrowed (by anyone). TC: {t|  b  book(t[title]=b[title] ^  r  reservation(r[ISBN]=b[ISBN] ^  c  copy(c[ISBN]=b[ISBN] ^ c[present] = “true” ^  c2  copy(c2[ISBN]=c[ISBN] ^  b  borrow(b[barcode]=c2[barcode])))))}

18 Beer Database visits(drinker, bar) serves(bar, beer) likes(drinker, beer).

19 Beer questions with a difference 1.Give all drinkers that visit bars that don’t serve any beer they like 2.Give all drinkers that only visit bars that serve a beer they like 3.Give all drinkers that only visit bars that serve no beer they like 4.Give all drinkers that only visit bars that serve all beers they like (and maybe other beers as well) 5.Give all drinkers that only visit bars that only serve beers they like (and thus serve nothing else)

20 Content 1.Generalities DB 2.Integrity constraints (FD revisited) 3.Relational Algebra (revisited) 4.Query optimisation 5.Tuple calculus 6.Domain calculus 7.Query equivalence 8.Temporal Data 9.No Nulls 10.The Askew Wall

21 Domain calculus Uses domain variables to take values from an attributes domain, instead of tuple values is related to QBE language An expression in DC is of the form: { | P(x1,x2,…,xn)} where: x1,…xn are domain variables P is a formula

22 Example DC language QBE Others: ILL, FQL, DEDUCE

23 Example DC 1.{ |  loan ^ a > 1200} 2.{ |  b,a (  loan ^ a > 1200)}

24 Queries in TC & DC Translate the following questions (for the bank database) to the tuple & domain calculus: 1.Give the name of customers that have a loan with a branch where they also have an account. 2.Give the name of customers who have a loan at a branch where they do not have an account. 3.Give the name of customers who have a loan at every branch where they have an account. 4.Give the name of customers who have loans only at branches where they have an account.

25 1. Give the name of customers that have a loan with a branch where they also have an account. TC: {t|  b  borrower(t[c_n]=b[c_n] ^  l  loan(l[l_n]=b[l_n] ^  a  account(a[b_n]=l[b_n] ^  d  depositor(a[a_n]=d[a_n] ^ d[c_n]=b[c_n] ))))} DC: { |  ln (  borrower ^  bn,a(  loan ^  an,b(  account ^  depositor)))}

26 2. Give the name of customers who have a loan at a branch where they do not have an account. TC: {t|  b  borrower(t[c_n]=b[c_n] ^  l  loan(l[l_n]=b[l_n] ^  a  account(a[b_n]=l[b_n] ^  d  depositor(a[a_n]=d[a_n] ^ d[c_n]=b[c_n] ))))} DC: { |  ln (  borrower ^  bn,a(  loan ^  an,b(  account ^  depositor)))}

27 3. Give the name of customers who have a loan at every branch where they have an account. TC: {t|  d  depositor(t[c_n]=d[c_n] ^  d2  depositor((d2[c_n]=d[c_n] ^  a  account(a[a_n]=d2[a_n]) => (  l  loan(l[b_n]=a[b_n] ^  b  borrow(b[l_n]=l[l_n] ^ b[c_n]=d2[c_n]))))))} DC: { |  an(  depositor ^  an2 ((  depositor ^  bn,b(  account) => (  ln,a(  loan ^  borrow)))))} This is necessary for the safety of the expression, to reduce the search space

28 4. Give the name of customers who have loans only at branches where they have an account. TC: {t|  d  borrow(t[c_n]=d[c_n] ^  d2  borrow((d2[c_n]=d[c_n] ^  a  loan(a[l_n]=d2[l_n]) => (  l  account(l[b_n]=a[b_n] ^  b  depositor(b[a_n]=l[a_n] ^ b[c_n]=d2[c_n]))))))} DC: { |  an(  borrow ^  an2 ((  borrow ^  bn,b(  loan) => (  ln,a(  account ^  depositor)))))}

29 4. Give the name of customers who have loans only at branches where they have an account. TC: {t|  b  borrow(t[c_n]=b[c_n] ^  b2  borrow((b2[c_n]=b[c_n] ^  l  loan(l[l_n]=b2[l_n]) => (  a  account(a[b_n]=l[b_n] ^  d  depositor(d[a_n]=a[a_n] ^ d[c_n]=n2[c_n]))))))} DC: { |  ln(  borrow ^  ln2 ((  borrow ^  bn,a(  loan) => (  an,b(  account ^  depositor)))))} With more intuitive attrs naming.

30 Library TC/DC questions 1.Give the name and department of borrowers, and the ISBN-number of the books of which they were the first borrower. 2.Give the name and department of borrowers who have never borrowed the most recently purchased copy of a book. 3.Give the title of books that are “present” in the library, reserved by someone, but not yet borrowed (by anyone).

31 1. Give the name and department of borrowers, and the ISBN-number of the books of which they were the first borrower. TC: {t |  b  borrow( t[name]=b[name] ^ t[department]=b[department] ^  c  copy(b[barcode]=c[barcode] ^ t[ISBN]=c[ISBN] ^  c2  copy(c2[ISBN]=c[ISBN] ^  b2  borrow(b2[barcode]=c2[barcode] ^ b2[from]<b[from])))) } DC: { |  b,f,t(  borrow ^  Y,p,d1(  copy ^  b2,d2,Y2,p2(  copy ^  n2,f2,t2,d3(  borrow ^ f2<f)))) }

32 2. Give the name and department of borrowers who have never borrowed the most recently purchased copy of a book. TC {t |  b  borrow( t[name]=b[name] ^ t[department]=b[department] ^  b2  borrow((b2[name]=b[name] ^ b2[department]=b[department] ^  c2  copy (c2[barcode]=b2[barcode])) => (  c3  copy(c3[ISBN]=c2[ISBN] ^ c3[cpYear]>c2[cpYear] ^ b2[from]  c3[cpYear])))} DC { |  b,f,t (  borrow ^  b2,f2,t2((  borrow ^  ISBN,d2,Y2,p2(  copy]) => (  b3,d3,Y3,p3(  copy ^ Y3>Y2 ^ f2  Y3)))))}

33 3. Give the title of books that are “present” in the library, reserved by someone, but not yet borrowed (by anyone). TC: {t|  b  book(t[title]=b[title] ^  r  reservation(r[ISBN]=b[ISBN] ^  c  copy(c[ISBN]=b[ISBN] ^ c[present] = “true” ^  c2  copy(c2[ISBN]=c[ISBN] ^  b  borrow(b[barcode]=c2[barcode])))))} DC: { |  ISBN,p,y(  book ^  n,d,date,c(  reservation ^  b2,d2,Y2,p2(  copy ^ p2 = “true” ^  b3,d3,Y3,p3(  copy ^  n4,d4,f4,t4(  borrow)))))}

34 Summary We have learned TC & DC We have learned to perform simple and more complex queries in TC & DC

35 … to follow Query equivalence