CSE544 Wednesday, March 29, 2006.

Slides:



Advertisements
Similar presentations
Completeness and Expressiveness
Advertisements

Relational Calculus and Datalog
Lecture 11: Datalog Tuesday, February 6, Outline Datalog syntax Examples Semantics: –Minimal model –Least fixpoint –They are equivalent Naive evaluation.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
Predicate Calculus Formal Methods in Verification of Computer Systems Jeremy Johnson.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Computability and Complexity 10-1 Computability and Complexity Andrei Bulatov Gödel’s Incompleteness Theorem.
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.
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.
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.
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.
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.
1 CSE544 Monday April 26, Announcements Project Milestone –Due today Next paper: On the Unusual Effectiveness of Logic in Computer Science –Need.
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.
1 Finite Model Theory Lecture 5 Turing Machines and Finite Models.
Lecture 9: Query Complexity Tuesday, January 30, 2001.
Predicate Calculus CS 270 Math Foundations of Computer Science Jeremy Johnson Presentation uses material from Huth and Ryan, Logic in Computer Science:
CS589 Principles of DB Systems Fall 2008 Lecture 4b: Domain Independence and Safety Lois Delcambre
Relational Calculus Chapter 4, Section 4.3.
Relational Algebra & Calculus
CSE202 Database Management Systems
Introduction to the Theory of Computation
Finite Model Theory Lecture 8
Formal Modeling Concepts
CS 480: Database Systems Lecture 15 February 18, 2013.
Relational Calculus Chapter 4, Part B
Chapter 6: Formal Relational Query Languages
The Relational Algebra and Relational Calculus
Elmasri/Navathe, Fundamentals of Database Systems, 4th Edition
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Relational Calculus Zachary G. Ives November 15, 2018
Relational Algebra & Calculus
Logics for Data and Knowledge Representation
Lecture#5: Relational calculus
DATABASE SYSTEM.
Chapter 6: Formal Relational Query Languages
1st-order Predicate Logic (FOL)
Finite Model Theory Lecture 6
Lecture 10: Query Complexity
Semantics of FO Formulas
CS 186, Fall 2002, Lecture 8 R&G, Chapter 4
Chapter 6: Formal Relational Query Languages
CSE 544: Lecture 8 Theory.
Herbrand Logic Semantics
Conjunctive Queries, Views, Datalog Monday, 4/29/2002
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
CSE 544: Lecture 11 Theory Monday, May 3, 2004.
Relational Algebra & Calculus
Properties of Relational Logic
Relational Calculus Chapter 4, Part B 7/1/2019.
CS589 Principles of DB Systems Fall 2008 Lecture 4e: Logic (Model-theoretic view of a DB) Lois Delcambre
CS589 Principles of DB Systems Fall 2008 Lecture 4b: Domain Independence and Safety Lois Delcambre
Relational Calculus Chapter 4 – Part II.
1st-order Predicate Logic (FOL)
Relational Calculus Chapter 4, Part B
Presentation transcript:

CSE544 Wednesday, March 29, 2006

Theory 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)

FO Syntax Given: A vocabulary: R1, …, Rk An arity, ar(Ri), for each i=1,…,k An infinite supply of variables x1, x2, x3, … Constants: c1, c2, c3, ...

FO Syntax Terms (t) and FO formulas () are: t ::= x | c ::= R(t1, ..., tar(R)) | ti = tj |   ’ |   ’ | ’ | x. | x.

FO Examples Most interesting case: Vocabulary = one binary relation R (encodes a graph) 1 4 2 3 1 2 3 4 R=

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)

Semantics Given a vocabulary R1, …, Rk A model is D = (D, R1D, …, RkD) D = a set, called domain, or universe RiD  D  D  ...  D, (ar(Ri) times) i = 1,...,k

Semantics Given: A model D = (D, R1D, ..., RkD) A formula  A substitution s : {x1, x2, ...}  D We define next the relation: meaning “D satisfies with s” D |= [s]

Semantics D |= (R(t1, ..., tn)) [s] D |= (t= t’) [s] If (s(t1), ..., s(tn))  RD D |= (t= t’) [s] If s(t) = s(t’)

Semantics D |= (  ’) [s] D |= (  ’) [s] D |= (’) [s] If D |= ()[s] and D |= (’) [s] D |= (  ’) [s] If D |= ()[s] or D |= (’) [s] D |= (’) [s] If not D |= ()[s]

First Order Logic: Semantics D |= (x.) [s] If for all s’ s.t. s(y) = s’(y) for all variables y other than x, D |= ()[s’] D |= (x.) [s] If for some s’ s.t. s(y) = s’(y) for all variables y other than x, D |= ()[s’]

FO and Databases FO: a sentence  is true in D if D |=  Databases: a formula  with free variables x1, ..., xn defines the query: (D) = {(s(x1), ..., s(xn)) | D |= [s]}

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

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

FO in Databases FO Databases Vocabulary: R1, ..., Rn Database schema: Model: D = (D, R1D, …, RkD) Database instance: D = (D, R1D, …, RkD) Sentences are true or false Formulas compute queries

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

Relational Algebra An algebra over relations Five operators: Meaning: , -, , s, P Meaning: R1  R2 = set union R1 - R2 = set difference R1  R2 = cartesian product sc(R) = subset of tuples satisfying condition c Pa(R) = projection on the attributes in a

FO  RA (x)  R(x,x)  P1(s1=2(R)) (x,y)  z.u.(R(x,z)  R(z,u)  R(u,y))  P16(s2=34=5 (R  R  R)) P16 ((R join2=1 R) join4=1 R)) ? (x)  y.R(x,y)  WHAT  HOW

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 ?

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))

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

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

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

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

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

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, R1D, …, RkD), D’ = (D’, R1D, …, RkD) we have (D) = (D’) If  is safe then it is also finite (why ?) Note: book has different but equivalent definition

Safe Queries Definition. Given D = (D, R1D, …, RkD), the active domain is Da = the set of all constants in R1D, …, RkD Example. Given a graph D = (D, R) Da = { 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

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]

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

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