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

Slides:



Advertisements
Similar presentations
Dr. Alexandra I. Cristea CS 319: Theory of Databases.
Advertisements

Dr. Alexandra I. Cristea CS 319: Theory of Databases: C3.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C6.
CS 319: Theory of Databases: C4
From the Calculus to the Structured Query Language Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 22, 2005.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C6.
1 Relational Algebra* and Tuple Calculus * The slides in this lecture are adapted from slides used in Standford's CS145 course.
Relational Algebra Ch. 7.4 – 7.6 John Ortiz. Lecture 4Relational Algebra2 Relational Query Languages  Query languages: allow manipulation and retrieval.
CS4432: Database Systems II Query Operator & Algebraic Expressions 1.
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.
SQL and Relational Algebra Zaki Malik September 02, 2008.
Relational Algebra 1 Chapter 5.1 V3.0 Napier University Dr Gordon Russell.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Chapter Predicate Calculus Formal language –True/False statements –Supports reasoning Usage –Integrity constraints –Non-procedural query languages.
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.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C3.
Cs3431 Relational Algebra : #I Based on Chapter 2.4 & 5.1.
Instructor: Mohamed Eltabakh
Rutgers University Relational Algebra 198:541 Rutgers University.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C6.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Relational Algebra, R. Ramakrishnan and J. Gehrke (with additions by Ch. Eick) 1 Relational Algebra.
Query Optimization CS 157B Ch. 14 Mien Siao. Outline Introduction Steps in Cost-based query optimization- Query Flow Projection Example Query Interaction.
Relational Algebra 2 Chapter 5.2 V3.0 Napier University Dr Gordon Russell.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
The Relational Model: 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 Algebra (Chapter 7)
Relational Calculus Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 17, 2007 Some slide content courtesy.
RELATIONAL ALGEBRA CHAPTER 6 1. LECTURE OUTLINE  Unary Relational Operations: SELECT and PROJECT  Relational Algebra Operations from Set Theory  Binary.
ICS 321 Fall 2011 The Relational Model of Data (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 8/29/20111Lipyeow.
Chapter 5 Notes. P. 189: Sets, Bags, and Lists To understand the distinction between sets, bags, and lists, remember that a set has unordered elements,
1 Section Relational Algebras A relational algebra consists of a set of relations together with operations to construct new relations. We’ll describe.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: Exam preparation.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
Advanced Relational Algebra & SQL (Part1 )
CSCD34-Data Management Systems - A. Vaisman1 Relational Algebra.
Operations in the Relational Model COP 4720 Lecture 8 Lecture Notes.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module A: Formal Relational.
1 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
CMPT 258 Database Systems Relational Algebra (Chapter 4)
Web Science & Technologies University of Koblenz ▪ Landau, Germany Relational Data Model.
1 CSE544 Monday April 26, Announcements Project Milestone –Due today Next paper: On the Unusual Effectiveness of Logic in Computer Science –Need.
Relational Algebra Instructor: Mohamed Eltabakh 1.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
2/16/2016Lecture 31 CS 222 Database Management System Spring Lecture 3 b Korra Sathya Babu Department of Computer Science NIT Rourkela.
Copyright © 2004 Pearson Education, Inc.. Chapter 6 The Relational Algebra and Relational Calculus.
Transaction Management Exercises I/O and CPU activities can be and are overlapped to minimize (disk and processor) idle time and to maximize throughput.
1 Introduction to Database Systems, CS420 SQL Constraints.
1 Relational Algebra & SQL Query Formulation Exercise.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 6 th Edition Chapter 8: Relational Algebra.
Module 2: Intro to Relational Model
COP4710 Database Systems Relational Algebra.
Fundamental of Database Systems
Relational Algebra and SQL
CS 480: Database Systems Lecture 15 February 18, 2013.
Chapter 2: Intro to Relational Model
Relational Algebra : #I
Lecture 21: ML Optimizers
Instructor: Mohamed Eltabakh
Query Optimization CS 157B Ch. 14 Mien Siao.
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
Unit Relational Algebra 2
Presentation transcript:

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

… previous TC, DC

Equivalence of queries RA TC DC Datalog SQL

Equivalence of TC and RA For every relational algebra (RA) query there is an equivalent tupel calculus (TC) query (and v.v.). Translation RA  TC is fairly straightforward and can be used to obtain TC queries from RA queries. Translation TC  RA is very artificial and does not result in readable RA queries. We will show the RA to TC translation.

Translation of RA to TC Step 1: Reduce the algebra expression E to the basic operators Step 2: If E is a single relation r then E translates to { t | t  r }. If r has attributes B 1,...,B n then it can also be written as {t |  s  r ( t[B 1 ]=s[B 1 ] ...  t[B n ]=s[B n ] ) }.

Translation of RA to TC Step 3: Apply the following substeps recursively (if the algebra expressions are base relations an  may need to be added): –Renaming: let { t | f(t) } be a TC expression equivalent to an RA expression E that uses attributes B 1,...,B n : Let E 1 =  x(A1,...,An) (E), then the translation to TC is { s |  t  r (f(t)  s[A 1 ]=t[B 1 ] ...  s[A n ]=t[B n ]) }

Translation of RA to TC –Cartesian Product: if E 1 (over A 1,...,A n ) translates to { t | f(t) } and E 2 over B 1,...,B m translates to { s | g(s) } then E 1  E 2 translates to { r | f(t)  g(s)  t[A 1 ]=r[A 1 ]  t[A n ]=r[A n ]  s[B 1 ]=r[B 1 ]  s[B m ]=r[B m ] )) } (attribute names must be unique in t)

Translation of RA to TC –Selection: let { t | f(t) } be a TC expression equivalent to E, then E 1 =  A  B (E) or E 1 =  A  c (E) (where  is , , ,...) is translated to { t | f(t)  t[A]  t[B] } and { t | f(t)  t[A]  c } resp. (replace t[.] with basis tuples from quantificators) –Projection: if E translates to { t | f(t) } then  B1,...,Bn (E) translates to { t | f'(t) } where f' is f with references to t[B 1 ]... t[B n ] only (no other attributes of t are used in f).

Translation of RA to TC –Union: let { t | f(t) } be a TC expression equivalent to E 1 and { t | g(t) } be a TC expression equivalent to E 2 then E 1  E 2 is translated to { t | f(t)  g(t) } –Difference: let { t | f(t) } be a TC expression equivalent to E 1 and { t | g(t) } be a TC expression equivalent to E 2 then E 1  E 2 is translated to { t | f(t)  g(t) }

Example List all drinkers who visit a bar that serves a beer they like. RA:  V.d (V  S  L) –Step 1:  V.d (  V.d, V.k, S.b (  V.k=S.k  S.b=L.b  V.d=L.d (V  S  L))) –Step 2: The relations are translated to { v | v  V } { s | s  S } { l | l  L } –Step 3: We first translate the product, then the selection and then the projection.

Example (cont.) –Cartesian product: { t |  v  V (  s  S (  l  L (  t[vd]=v[d]  t[vk]=v[k]  t[sk]=s[k]  t[sb]=s[b]  t[ld]=l[d]  t[lb]=l[b] ))) } (attribute names must be unique) –Selection: { t |  v  V (  s  S (  l  L (  t[vd]=v[d]  t[vk]= v[k]  t[sk]=s[k]  t[sb]=s[b]  t[ld]=l[d]  t[lb]=l[b]  v[k]=s[k]  s[b]=l[b]  v[d]=l[d] ))) }

Example (cont.) –Projection: { t |  v  V (  s  S (  l  L (  t[vd]=v[d]  v[k]=s[k]  s[b]=l[b]  v[d]=l[d] ) ) ) }

Summary We have learned query equivalence

… to follow Exam discussion

Beer question n (tupel calculus) Give all beers that are served in bars where none of the visitors like any other beer (than the ones served in that bar). Is this a correct answer?

A faulty answer Consider Or after a rewrite Suppose there are 2 beers a, b, 1 bar k, 2 drinkers x, y; everyone serves/visits/likes everything Then the correct answer should result in {a, b}. The tupel calculus expression does not contain a, because every visitor of k also likes b.

Beer question n (RA) Give all beers that are served in bars where none of the visitors like any other beer (than the ones served in that bar).  b (S  (  k (S) -  k ( V  L - V  L  S))) This is not so easy to translate to the earlier TC expression

Common tupel calculus mistakes Explain what is wrong in the following queries: Translate L&V quantor as and not as