1 CSE544 Monday April 26, 2004. 2 Announcements Project Milestone –Due today Next paper: On the Unusual Effectiveness of Logic in Computer Science –Need.

Slides:



Advertisements
Similar presentations
Relational Calculus and Datalog
Advertisements

Lecture 11: Datalog Tuesday, February 6, Outline Datalog syntax Examples Semantics: –Minimal model –Least fixpoint –They are equivalent Naive evaluation.
Relational Calculus   Logic, like whiskey, loses its beneficial effect when taken in too large quantities. --Lord Dunsany.
Tallahassee, Florida, 2014 COP4710 Database Systems Relational Algebra Fall 2014.
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.
D ATABASE S YSTEMS I R ELATIONAL A LGEBRA. 22 R ELATIONAL Q UERY L ANGUAGES Query languages (QL): Allow manipulation and retrieval of data from a database.
1 Relational Algebra. Motivation Write a Java program Translate it into a program in assembly language Execute the assembly language program As a rough.
Relational Schemas and Predicate Logic: Notation.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
ODMG Standard: Object Model1 OBJECT-ORIENTED DATABASE SYSTEMS ODMG Standard: Object Model Susan D. Urban and Suzanne W. Dietrich Department of Computer.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
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.
Relational Algebra & Calculus Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 21, 2004 Some slide content.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Introduction to Database Systems 1 Relational Algebra Relational Model: Topic 3.
Cs3431 Relational Algebra : #I Based on Chapter 2.4 & 5.1.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Relational Algebra Wrap-up and Relational Calculus Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 11, 2003.
RIZWAN REHMAN, CCS, DU. Advantages of ORDBMSs  The main advantages of extending the relational data model come from reuse and sharing.  Reuse comes.
Relational Algebra.
Advanced Database CS-426 Week 2 – Logic Query Languages, Object Model.
Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
Relational Algebra Instructor: Mohamed Eltabakh 1.
The Relational Model: Relational Calculus
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
Relational Algebra & Calculus Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 12, 2007 Some slide content.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
1 Relational Algebra. 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science Database Applications Lecture#6: Relational calculus.
CSE 544 Relational Calculus Lecture #2 January 11 th, Dan Suciu , Winter 2011.
Relational Calculus Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 17, 2007 Some slide content courtesy.
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.
CSE 6331 © Leonidas Fegaras OODB1 Object-Oriented Databases and the ODMG Standard.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational model.
IST 210 The Relational Language Todd S. Bacastow January 2004.
Database Systems Relational Calculus. Relational Algebra vs. Relational Calculus Relational algebra queries are relatively easy to implement in.
Database Management Systems, R. Ramakrishnan1 Relational Algebra Module 3, Lecture 1.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 – DB Applications C. Faloutsos & A. Pavlo Lecture#5: Relational calculus.
Lecture 7: Foundations of Query Languages Tuesday, January 23, 2001.
1 Finite Model Theory Lecture 1: Overview and Background.
CSC271 Database Systems Lecture # 7. Summary: Previous Lecture  Relational keys  Integrity constraints  Views.
1 First order theories (Chapter 1, Sections 1.4 – 1.5) From the slides for the book “Decision procedures” by D.Kroening and O.Strichman.
Relational Calculus Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Copyright © 2004 Pearson Education, Inc.. Chapter 6 The Relational Algebra and Relational Calculus.
1 Finite Model Theory Lecture 16 L  1  Summary and 0/1 Laws.
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.
1 Finite Model Theory Lecture 5 Turing Machines and Finite Models.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
Lecture 9: Query Complexity Tuesday, January 30, 2001.
Relational Calculus Chapter 4, Section 4.3.
Relational Algebra & Calculus
CSE202 Database Management Systems
Relational Algebra Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
Lecture#5: Relational calculus
Finite Model Theory Lecture 6
Lecture 10: Query Complexity
CS639: Data Management for Data Science
CSE 544: Lecture 8 Theory.
Relational Algebra & Calculus
CSE544 Wednesday, March 29, 2006.
Presentation transcript:

1 CSE544 Monday April 26, 2004

2 Announcements Project Milestone –Due today Next paper: On the Unusual Effectiveness of Logic in Computer Science –Need to read only up to section 3 –Review due on Wednesday –It’s very short; review should be similar :)

3 XML Storage Shanmugasundaram’s paper: Shred XML data  relations –Easy: use the DTD Translate XML queries  SQL queries –Largely ignored in the paper Tagging –SQL tuple streams  XML –How do we do that ?

4 XML Storage Other ways: Schema independent shredding BLOBs Use an object storage system

5 OO Databases Started late 80’s –The OO Manifesto Main idea: –Toss the relational model ! –Use the OO model – e.g. C++ classes

6 OO Databases Two interpretations: Make a programming language persistent (ObjectStore) –No query language –Niche market –ObjectStore is still around, renamed to Exelon, stores XML objects now Build a new database from scratch (O 2 ) –Elegant extension of SQL –Later adopted by ODMG in the OQL language

7 ODL / OQL interface Student extends Person (extent Students) { attribute string major; relationship Set takes inverse stds;} interface Person (extent People key ssn) { attribute string ssn; attribute string dept; attribute string name;} interface Course (extent Crs key cid) { attribute string cid; attribute string cname; relationship Person instructor; relationship Set stds inverse takes;}

8 Same in E/R isa Student Course Takes Person Instructor

9 ODL / OQL select S.name from Students S, S.takes C where C.instructor.dept = ‘EE’ select C.name from Crs C where C.instructor.dept = ‘EE’ Is this more efficient than joins? Follow pointers instead of joins

10 Object-Relational (OR) Databases Take an incremental approach Keep the relational model, but allow attributes of complex types –Inheritance –Pointers –Methods (a security nightmare) All major commercial databases today are OR Trend: XML datatype

11 Theory Recall: relational databases invented by a theoretician (Codd) Fundamental principle: separate the WHAT from the HOW - data independence WHAT: First Order Logic (FO) HOW: Relational algebra (RA)

12 Given: A vocabulary: R 1, …, R k An arity, ar(R i ), for each i=1,…,k An infinite supply of variables x 1, x 2, x 3, … Constants: c 1, c 2, c 3,... FO Syntax

13 Terms (t) and FO formulas (  ) are: FO Syntax t ::= x | c  ::= R(t 1,..., t ar(R) ) | t i = t j |    ’ |    ’ |  ’ |  x.  |  x.  t ::= x | c  ::= R(t 1,..., t ar(R) ) | t i = t j |    ’ |    ’ |  ’ |  x.  |  x. 

14 FO Examples Most interesting case: Vocabulary = one binary relation R (encodes a graph) R=

15 FO Sentences Does there exists a loop in the graph ? Are there paths of length >2 ? Is there a “sink” node ?    x.R(x,x)    x.  y.  z.  u.(R(x,y)  R(y,z)  R(z,u))    x.  y.R(x,y)

16 FO Queries Find all nodes connected by a path of length 2: Find all nodes without outgoing edges:  (x,y)   u.(R(x,u)  R(u,y))  (x)   u.(R(u,x)   y.  R(x,y) These are open formulas

17 In Class Retrieve all nodes with at least two children A node x is more important than y if every child of y is also a child of x. Retrieve all ‘most important nodes’ in the graph

18 FO in Databases FODatabases Vocabulary: R 1,..., R n Database schema: R 1,..., R n Model: D = (D, R 1 D, …, R k D ) Database instance: D = (D, R 1 D, …, R k D ) Sentences are true or false Formulas compute queries

19 FO Semantics In FO we express WHAT we want Sometimes it’s even unclear HOW to get it See accompanying slides on FO semantics –They explain HOW to get it, but it’s impractical

20 Relational Algebra An algebra over relations Five operators: , -, , ,  Meaning: R 1  R 2 = set union R 1 - R 2 = set difference R 1  R 2 = cartesian product  c (R) = subset of tuples satisfying condition c  a (R) = projection on the attributes in a R 1  R 2 = set union R 1 - R 2 = set difference R 1  R 2 = cartesian product  c (R) = subset of tuples satisfying condition c  a (R) = projection on the attributes in a

21 FO  RA  (x)  R(x,x)  1 (  1=2 (R))  (x,y)   z.  u.(R(x,z)  R(z,u)  R(u,y))  16 (  2=3  4=5 (R  R  R))    (x)   y.R(x,y)  ?  16 ((R join 2=1 R) join 4=1 R)) WHAT  HOW

22 FO v.s. RA Theorem. Every query in RA can be expressed in FO Proof This shows how to go from HOW to WHAT not very interesting What about the converse ?

23 The Drinkers/Beers Example Vocabulary: Find all drinkers that frequent some bar that serve some beer that they like: Likes(drinker,beer), Serves(bar,beer), Frequents(drinker,bar)  (d)   ba.  be.(F(d,ba)  L(d,be))

24 Lots of Fun Examples (in class) Find drinkers that frequent some bar that serves only beer they like Find drinkers that frequent only bars that serve some beer they like Find drinkers that frequent only bars that serve only beer they like

25 Unsafe FO Queries Find all nodes that are not in the graph: what’s wrong ?

26 Unsafe FO Queries Find all nodes that are connected to “everything”: what’s wrong ?

27 Unsafe FO Queries Find all pairs of employees or offices: what’s wrong ? We don’t want such queries !

28 Safe Queries A model D = (D, R 1 D, …, R k D ) In FO: –both D and R 1 D, …, R k D may be infinite In databases: –D may infinite (int, string, etc) –R 1 D, …, R k D are always finite –We call this a finite model

29 Safe Queries  is a finite query if for every finite model D,  (D) is finite  is safe, or domain independent, if for every two models D, D’ having the same relations: D = (D, R 1 D, …, R k D ), D’ = (D’, R 1 D, …, R k D ) we have  (D) =  (D’) If  is safe then it is also finite (why ?) Note: book has different but equivalent definition

30 Safe Queries Definition. Given D = (D, R 1 D, …, R k D ), the active domain is D a = the set of all constants in R 1 D, …, R k D Example. Given a graph D = (D, R) D a = { x |  y.R(x,y)   z.R(z,x)} Property. If a query is safe, it suffices to range quantifiers only over the active domain (why ?) Hence we can compute safe queries

31 Safe Queries The safe relational calculus consists only of safe queries. However: Theorem It is undecidable if a given a FO query is safe. Need to write only safe queries, but how do we know how which queries are safe ? Work around: write them in an obviously safe way –Range restricted queries - formally defined in [AHU]

32 FO v.s. RA Theorem. Every safe query in FO can be expressed in RA Proof From WHAT to HOW this is really interesting and motivated the relational model

33 Limited Expressive Power Vocabulary: binary relation R The following queries cannot be expressed in FO: Transitive closure: –  x.  y. there exists x 1,..., x n s.t. R(x,x 1 )  R(x 1,x 2 ) ...  R(x n-1,x n )  R(x n,y) Parity: the number of edges in R is even