Database Applications (15-415) Relational Calculus Lecture 6, September 6, 2016 Mohammad Hammoud.

Slides:



Advertisements
Similar presentations
CMU SCS Carnegie Mellon Univ. School of Computer Science /615 - DB Applications C. Faloutsos & A. Pavlo Lecture #4: Relational Algebra.
Advertisements

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Part B.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos & A. Pavlo Lecture#6: Rel. model - SQL part1 (R&G, chapter.
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.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
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 Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
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.  Introduction  Relational Algebra Operations  Projection and Selection  Set Operations  Joins  Division  Tuple Relational Calculus.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
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.
Lecture 05 Structured Query Language. 2 Father of Relational Model Edgar F. Codd ( ) PhD from U. of Michigan, Ann Arbor Received Turing Award.
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.
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.
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.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational model.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model I (based on notes by Silberchatz,Korth, and Sudarshan.
CSCD34-Data Management Systems - A. Vaisman1 Relational Algebra.
IST 210 The Relational Language Todd S. Bacastow January 2004.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational domain calculus.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 – DB Applications C. Faloutsos & A. Pavlo Lecture#5: Relational calculus.
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.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational tuple calculus.
CS589 Principles of DB Systems Fall 2008 Lecture 4c: Query Language Equivalence Lois Delcambre
1 Relational Algebra. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational model supports.
Relational Calculus Chapter 4, Section 4.3.
Relational Algebra & Calculus
CSE202 Database Management Systems
Temple University – CIS Dept. CIS661– Principles of Database Systems
Relational Algebra Chapter 4 1.
Relational Calculus Chapter 4, Part B
The Relational Algebra and Relational Calculus
Relational Algebra Chapter 4, Part A
Lecture #4: Relational Algebra
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
Database Applications (15-415) SQL-Part II Lecture 9, February 04, 2018 Mohammad Hammoud.
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Data Base System Lecture 9: Rational Algebra and Relational Calculus
Relational Algebra 1.
LECTURE 3: Relational Algebra
Relational Algebra Chapter 4 1.
Lecture#5: Relational calculus
DATABASE SYSTEM.
Relational Algebra Chapter 4 - part I.
Relational Algebra Chapter 4, Sections 4.1 – 4.2
Chapter 2: Intro to Relational Model
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.
CS589 Principles of DB Systems Fall 2008 Lecture 4b: Domain Independence and Safety Lois Delcambre
Relational Calculus Chapter 4, Part B
Presentation transcript:

Database Applications (15-415) Relational Calculus Lecture 6, September 6, 2016 Mohammad Hammoud

Today… Last Session: Today’s Session: Announcements: Relational Algebra Today’s Session: Relational calculus Relational tuple calculus Announcements: PS2 is now posted. Due on Sep 25, 2016 by midnight PS1 grades will be out tomorrow In the next recitation we will practice on relational algebra and calculus

Outline Relational Tuple Calculus (RTC) Why? Details Examples Equivalence with relational algebra ‘Safety’ of expressions

Motivation Question: What is the main “weakness” of relational algebra? Answer: Procedural It describes the steps (i.e., ‘how’) Still useful, especially for query optimization

Relational Calculus (in General) It describes what we want (not how) It has two equivalent flavors, ‘tuple’ and ‘domain’ calculus We will only focus on relational ‘tuple’ calculus It is the basis for SQL and Query By Example (QBE) It is useful for proofs (see query optimization, later)

Relational Tuple Calculus (RTC) RTC is a subset of ‘first order logic’: Examples: A “formula” that describes t Give me tuples ‘t’, satisfying predicate ‘P’ Find all students: Find all sailors with a rating above 7:

Syntax of RTC Queries The allowed symbols: Quantifiers:

Syntax of RTC Queries Atomic “formulas”: Where op is an operator in the set {<, >, =, ≤, ≥, ≠}

Syntax of RTC Queries A “formula” is: Any atomic formula If P1 and P2 are formulas, so are If P(s) is a formula, so are

Basic Rules Reminders: De Morgan: Implication: Double Negation: - The negation of a conjunction is the disjunction of the negations. - The negation of a disjunction is the conjunction of the negations. ‘every human is mortal : no human is immortal’

A Mini University Database

Examples Find all student records output tuple of type ‘STUDENT’

Examples Find the student record with ssn=123

This is equivalent to the ‘Selection’ operator in Relational Algebra! Examples Find the student record with ssn=123 This is equivalent to the ‘Selection’ operator in Relational Algebra!

Examples Find the name of the student with ssn=123 Will this work?

This is equivalent to the ‘Projection’ operator in Relational Algebra! Examples Find the name of the student with ssn=123 ‘t’ has only one column This is equivalent to the ‘Projection’ operator in Relational Algebra!

This is equivalent to the ‘Union’ operator in Relational Algebra! Examples Get records of both part time and full time students* This is equivalent to the ‘Union’ operator in Relational Algebra! * Assume we maintain tables for PT_STUDENT and FT_STUDENT in our Mini University DB

This is equivalent to the ‘Difference’ operator in Relational Algebra! Examples Find students that are not staff* This is equivalent to the ‘Difference’ operator in Relational Algebra! * Assume we maintain a table for STAFF in our Mini University DB and that STUDENT and STAFF are union-compatible

Cartesian Product: A Reminder Assume MALE and FEMALE dog tables as follows: M.Name F.Name spike lassie shiba spot = x This gives all possible couples!

Examples (Cont’d) Find all the pairs of (male, female) dogs This is equivalent to the ‘Cartesian Product’ operator in Relational Algebra!

More Examples Find the names of students taking 15-415 2-way Join!

More Examples Find the names of students taking 15-415

More Examples Find the names of students taking 15-415 join projection selection

More Examples Find the names of students taking a 2-unit course 3-way Join!

What is the equivalence of this in Relational Algebra? More Examples Find the names of students taking a 2-unit course join projection selection What is the equivalence of this in Relational Algebra?

More on Joins Assume a Parent-Children (PC) table instance as follows: Who are Tom’s grandparent(s)? (this is a self-join)

What is the equivalence of this in Relational Algebra? More Join Examples Find Tom’s grandparent(s) What is the equivalence of this in Relational Algebra?

Harder Examples: DIVISION Find suppliers that shipped all the bad parts

Harder Examples: DIVISION Find suppliers that shipped all the bad parts

General Patterns There are three equivalent versions: If it is bad, he shipped it Either it was good, or he shipped it There is no bad shipment that he missed

One way to think about this: More on Division Find (SSNs of) students who are taking all the courses that ssn=123 is (and maybe even more) One way to think about this: Find students ‘s’ so that if 123 takes a course => so does ‘s’

More on Division Find (SSNs of) students who are taking all the courses that ssn=123 is (and maybe even more)

‘Proof’ of Equivalence Relational Algebra <-> RTC But…

Safety of Expressions FORBIDDEN: It has infinite output!! Instead, always use:

Faloutsos CMU - 15-415/615 Summary The relational model has rigorously defined query languages — simple and powerful Relational algebra is more operational/procedural Useful as internal representation for query evaluation plans Relational calculus is declarative Users define queries in terms of what they want, not in terms of how to compute them

Summary Several ways of expressing a given query Faloutsos CMU - 15-415/615 Summary Several ways of expressing a given query A query optimizer should choose the most efficient version Algebra and “safe” calculus have the same expressive power This leads to the notion of relational completeness

Next Class SQL- Part I