Chapter 8 Relational Calculus.

Slides:



Advertisements
Similar presentations
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Part B.
Advertisements

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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Rutgers University Relational Calculus 198:541 Rutgers University.
Chapter 6 Relations. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Topics in this Chapter Tuples Relation Types Relation Values Relation.
Predicates and Quantifiers
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
A Brief Summary for Exam 1 Subject Topics Propositional Logic (sections 1.1, 1.2) –Propositions Statement, Truth value, Proposition, Propositional symbol,
Lecture 3 [Self Study] Relational Calculus
Chapter 9 Integrity. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.9-2 Topics in this Chapter Predicates and Propositions Internal vs.
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.
Chapter 8 Relational Calculus. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
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.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Chapter 7 Relational Algebra. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.7-2 Topics in this Chapter Closure Revisited The Original Algebra:
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.
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.
Albert Gatt LIN3021 Formal Semantics Lecture 3. Aims This lecture is divided into two parts: 1. We make our first attempts at formalising the notion of.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
Integrity Prof. Yin-Fu Huang CSIE, NYUST Chapter 9.
Relational Algebra. CENG 3512 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports.
Chapter 4 An Introduction to SQL.
Relational Calculus Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Relational Calculus Chapter 4, Section 4.3.
Relational Algebra & Calculus
CSE202 Database Management Systems
STRUCTURE OF PRESENTATION :
Chapter 10 Views.
Relational Calculus Chapter 4, Part B
The Relational Algebra and Relational Calculus
STRUCTURE OF PRESENTATION :
Chapter 8 Relational Calculus.
Chapter 1 The Foundations: Logic and Proofs
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Chapter 17 Linked Lists.
Chapter 4 Inheritance.
Chapter 14 Graphs and Paths.
Relational Database Models
Advanced Database System
Relational Calculus and QBE
Chapter 20 Hash Tables.
A Brief Summary for Exam 1
Unit 7 Normalization (表格正規化).
CS 186, Fall 2002, Lecture 8 R&G, Chapter 4
Chapter 5 Algorithm Analysis.
Relational Calculus and QBE
Chapter 6: Formal Relational Query Languages
The Facts to Be Explained
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Introduction: Some Representative Problems
Relational Algebra & Calculus
Relational Calculus Chapter 4, Part B 7/1/2019.
Chapter 2 Reference Types.
CS589 Principles of DB Systems Fall 2008 Lecture 4e: Logic (Model-theoretic view of a DB) Lois Delcambre
Chapter 4 Greedy Algorithms.
Relational Calculus Chapter 4 – Part II.
Relational Calculus Chapter 4, Part B
Presentation transcript:

Chapter 8 Relational Calculus

Computational Capabilities SQL Facilities Domain Calculus Topics in this Chapter Tuple Calculus Calculus vs. Algebra Computational Capabilities SQL Facilities Domain Calculus Query-By-Example Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

Relational calculus and algebra are logically equivalent Based on predicate calculus, the relational calculus is a more natural language expression of the relational algebra Instead of operators used by the system to construct a result relation, the calculus offers a notation to express the result relation in terms of the source relations Relational calculus and algebra are logically equivalent Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

Relational Calculus Implementations Codd proposed a language called ALPHA to implement the relational calculus QUEL, an early competitor to SQL, was based on ALPHA Relational calculus came to be called tuple calculus, in distinction from domain calculus Domain calculus has been implemented by Query By Example (QBE) Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

Tuple Calculus - Syntax <relation expression> := RELATION {<tuple expression commalist>} | <relvar name> | <relation op inv> -- “relation operator invoked” | <with exp> -- “with expression” | <introduced name> | ( <relation exp>) Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

Tuple Calculus - Syntax Identical to the syntax of the algebra Relation operator invoked now is interpreted to mean relation definition In addition, <range var def> -- “range variable definition” ::= RANGEVAR <range var name> RANGES OVER <relation exp commalist> ; Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

<bool exp>s are called well-formed formulas, WFFs, or “weffs” Tuple Calculus - WFFs <bool exp>s are called well-formed formulas, WFFs, or “weffs” Every reference to a range variable is either free or bound, within a context, and in particular, within a WFF Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

RANGEVAR SX RANGES OVER S; RANGEVAR SY RANGES OVER S; Range Variables RANGEVAR SX RANGES OVER S; RANGEVAR SY RANGES OVER S; RANGEVAR SPX RANGES OVER SP; RANGEVAR SPY RANGES OVER SP; RANGEVAR PX RANGES OVER P; Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

RANGEVAR SU RANGES OVER ( SX WHERE SX.CITY = ‘London’ ) Range Variables RANGEVAR SU RANGES OVER ( SX WHERE SX.CITY = ‘London’ ) ( SX WHERE EXISTS SPX (SPX.S# = SX.S# AND SPX.P# = P# (‘P1’) ) ) ; In this example, SU ranges over the union of the set of supplier tuples for suppliers located in London, and those that supply P1 Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

Free and Bound Variables Every reference to a range variable is either free or bound A bound reference can be replaced by a reference to some other variable without changing the meaning of the expression A free reference is not so free Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

EXISTS is the existential quantifier Quantifiers - EXISTS EXISTS is the existential quantifier EXISTS V ( p ) -- There exists at least one value of V that makes p true Formally this is an iterated OR FALSE OR p (t1) OR … OR p (tm) -- will evaluate to false if m = 0 Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

FORALL is the universal quantifier Quantifiers - FORALL FORALL is the universal quantifier FORALL V ( p ) -- for all values of v, p is true Formally this is an iterated AND TRUE AND p (t1) AND … AND p (tm) -- will evaluate to true as long as all are true This will evaluate to TRUE when the set is empty Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

Relational Operations <relation op inv> in the calculus context is more a definition than an operator invocation <relation op inv> ::= <proto tuple> [WHERE <bool exp>] For example: SX.S# WHERE SX.CITY = ‘London’ -- Get supplier numbers for suppliers in London Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

And the same can be said of the algebra Calculus vs. Algebra Codd’s reduction algorithm reduces expressions of the calculus to algebra A language is said to be relationally complete if it is at least as powerful as the calculus And the same can be said of the algebra QUEL, based on the calculus, can be implemented by applying the algorithm to it, and then implementing the underlying algebra Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

S.STATUS < (SELECT MAX (S.STATUS) FROM S) ; SQL Facilities Because the calculus statements can be translated into algebra, they map equally well to SQL Example: Get supplier numbers for suppliers with status less than the current maximum status in the supplier table: SELECT S.S# FROM S WHERE S.STATUS < (SELECT MAX (S.STATUS) FROM S) ; Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

SP { S#, S#(‘S1’), P# P#(‘P1’) } Domain Calculus Its range variables range over domains (i.e. types) instead of relations Based on checking values in the attribute domain, a bool membership condition SP { S#, S#(‘S1’), P# P#(‘P1’) } -- evaluates to true iff the shipment contains part P1 shipped by supplier S1 Copyright © 2004 Pearson Addison-Wesley. All rights reserved.

Query-By-Example (QBE) Language based on the domain calculus Notation which is intuitive and easy to use By making entries in blank tables, the user specifies the conditions needed in the result A condition box is used to allow more complex conditions Easy to express comparisons, uniqueness, AND and OR, and EXISTS Doesn’t express NOT EXISTS well, and so is not relationally complete Copyright © 2004 Pearson Addison-Wesley. All rights reserved.