ICS 321 Fall 2011 Algebraic and Logical Query Languages (ii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at.

Slides:



Advertisements
Similar presentations
1 Datalog: Logic Instead of Algebra. 2 Datalog: Logic instead of Algebra Each relational-algebra operator can be mimicked by one or several Database Logic.
Advertisements

First Order Logic Logic is a mathematical attempt to formalize the way we think. First-order predicate calculus was created in an attempt to mechanize.
CSE 636 Data Integration Conjunctive Queries Containment Mappings / Canonical Databases Slides by Jeffrey D. Ullman.
Lecture 11: Datalog Tuesday, February 6, Outline Datalog syntax Examples Semantics: –Minimal model –Least fixpoint –They are equivalent Naive evaluation.
CPSC 504: Data Management Discussion on Chandra&Merlin 1977 Laks V.S. Lakshmanan Dept. of CS UBC.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
Answer Set Programming Overview Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma de Guadalajara
SECTION 21.5 Eilbroun Benjamin CS 257 – Dr. TY Lin INFORMATION INTEGRATION.
Virtual Data Integration Helena Galhardas DEI IST (based on the slides of the course: CIS 550 – Database & Information Systems, Univ. Pennsylvania, Zachary.
Deductive Database. Relation Database TitleYearLengthType Harry Porter Color Gone with the wind Black and White Snow White195090Color.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
Computability and Complexity 8-1 Computability and Complexity Andrei Bulatov Logic Reminder.
ICS 321 Fall 2009 Project Presentation Template Team Name Team Members 11/19/20091Lipyeow Lim -- University of Hawaii at Manoa.
ICS 624 Spring 2011 Entity Resolution with Evolving Rules Preface to Steven Whang’s slides Asst. Prof. Lipyeow Lim Information & Computer Science Department.
ICS 421 Spring 2010 Transactions & Concurrency Control (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa.
ICS 421 Spring 2010 Data Mining 1 Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 4/6/20101Lipyeow Lim.
1 9. Evaluation of Queries Query evaluation – Quantifier Elimination and Satisfiability Example: Logical Level: r   y 1,…y n  r’ Constraint.
1 2. Constraint Databases Next level of data abstraction: Constraint level – finitely represents by constraints the logical level.
Winter 2002Arthur Keller – CS 18014–1 Schedule Today: Feb. 26 (T) u Datalog. u Read Sections Assignment 6 due. Feb. 28 (TH) u Datalog and SQL.
CSE 636 Data Integration Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge Notes for Ch.3 of Poole et al. CSCE 580 Marco Valtorta.
1 Datalog Rules Programs Negation. 2 Review of Logical If-Then Rules h(X,…) :- a(Y,…) & b(Z,…) & … head body subgoals “The head is true if all the subgoals.
Chapter 5 Other Relational Languages By Cui, Can B.
Embedded SQL Direct SQL is rarely used: usually, SQL is embedded in some application code. We need some method to reference SQL statements. But: there.
Credit: Slides are an adaptation of slides from Jeffrey D. Ullman 1.
Logical Query Languages Motivation: 1.Logical rules extend more naturally to recursive queries than does relational algebra. u Used in SQL recursion. 2.Logical.
Computer Science 101 Boolean Algebra. What’s next? A new type of algebra – Helps us A new type of algebra – Helps us With logical reasoningWith logical.
DEDUCTIVE DATABASE.
Formal Models of Computation Part II The Logic Model
Computer Science 101 The Boolean System. George Boole British mathematician ( ) Boolean algebra –Logic –Set theory –Circuits –Conditions in if.
Recursive query plans for Data Integration Oliver Michael By Rajesh Kanisetti.
(CSC 102) Lecture 7 Discrete Structures. Previous Lectures Summary Predicates Set Notation Universal and Existential Statement Translating between formal.
Computer Science 210 Computer Organization Introduction to Boolean Algebra.
ICS 321 Spring 2011 High Level Database Models Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 2/7/20111Lipyeow.
Logical Query Languages Motivation: 1.Logical rules extend more naturally to recursive queries than does relational algebra. u Used in SQL recursion. 2.Logical.
ICS 321 Fall 2009 SQL: Queries, Constraints, Triggers Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/8/20091Lipyeow.
CSE 544 Relational Calculus Lecture #2 January 11 th, Dan Suciu , Winter 2011.
Computing & Information Sciences Kansas State University Thursday, 08 Feb 2007CIS 560: Database System Concepts Lecture 11 of 42 Thursday, 08 February.
Datalog Inspired by the impedance mismatch in relational databases. Main expressive advantage: recursive queries. More convenient for analysis: papers.
ICS 321 Fall 2009 The Relational Model (ii) Asst. Prof. Lipyeow Lim Information and Computer Science Department University of Hawaii at Manoa 9/10/20091Lipyeow.
CSE 636 Data Integration Conjunctive Queries Containment Mappings / Canonical Databases Slides by Jeffrey D. Ullman Fall 2006.
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.
ICS 321 Fall 2010 SQL in a Server Environment (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 11/1/20101Lipyeow.
Datalog –Another query language –cleaner – closer to a “logic” notation, prolog – more convenient for analysis – can express queries that are not expressible.
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,
ICS 321 Fall 2011 The Database Language SQL (iv) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 10/26/20111Lipyeow.
ICS 321 Spring 2011 The Database Language SQL (iii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 3/14/20111Lipyeow.
Computing & Information Sciences Kansas State University Wednesday, 17 Sep 2008CIS 560: Database System Concepts Lecture 9 of 42 Wednesday, 18 September.
Lu Chaojun, SJTU 1 Extended Relational Algebra. Bag Semantics A relation (in SQL, at least) is really a bag (or multiset). –It may contain the same tuple.
Datalog Another formalism for expressing queries: - cleaner - closer to a “logic” notation - more convenient for analysis - equivalent in power to relational.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 26 A First Course in Database Systems.
Chapter Eight Predicate Logic Semantics. 1. Interpretations in Predicate Logic An argument is valid in predicate logic iff there is no valuation on which.
1 Database Design: DBS CB, 2 nd Edition Relational Algebra: Basic Operations & Algebra of Bags Ch. 5.
Extensions of Datalog Wednesday, February 13, 2001.
CS589 Principles of DB Systems Fall 2008 Lecture 4b: Domain Independence and Safety Lois Delcambre
CS589 Principles of DB Systems Spring 2014 Unit 2: Recursive Query Processing Lecture 2-1 – Naïve algorithm for recursive queries Lois Delcambre (slides.
Computer Science 210 Computer Organization
Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman
Modifying the Database
Semantics In propositional logic, we associate atoms with propositions about the world. We specify the semantics of our logic, giving it a “meaning”. Such.
Computers & Programming Languages
Computer Science 210 Computer Organization
Week #2 – 4/6 September 2002 Prof. Marie desJardins
Logic Based Query Languages
Datalog Inspired by the impedance mismatch in relational databases.
CS589 Principles of DB Systems Fall 2008 Lecture 4a: Introduction to Datalog Lois Delcambre
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
Rules Programs Negation
Presentation transcript:

ICS 321 Fall 2011 Algebraic and Logical Query Languages (ii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 10/3/20111Lipyeow Lim -- University of Hawaii at Manoa

Datalog : Database Logic A (relational) atom – Consists of a predicate and a list of arguments – Arguments can be constants or variables – Takes on Boolean value (true or false) A relation R can be represented as a predicate R – A tuple is in R iff the atom R(a,b,c,d,e,f,g) is true. 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa2 R(a,b,c,d,e,f,g) ArgumentsPredicate Atom

Example: tables in datalog 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa3 AB R R(1,2) R(3,4) Datalog R(1,4) would be false True by default.

Arithmetic Atoms 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa4 x < y x+1 >= y+4*z Can contain both constants and variables.

Datalog Rules 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa5 LongMovie(t,y) :- Movies(t,y,l,g,s,p), l >=100 (t,y) is a tuple of LongMovie IF (t,y,l,g,s,p) is a tuple of Movies and length of movie is at least 100 headbody “if” or  Shorthand for AND These two “t,y” have to match These two “l” have to match Aka “subgoal” Can be preceded by negation operator “NOT” or “~” LongMovie(t,y) :- Movies(t,y,l,_,_,_), l >=100 Anonymous variables

Safety Condition for Datalog Rules Without the safety condition, rules may be underspecified, resulting in an infinite relation (not allowed). Examples – LongMovie(t,y) :- Movies(t,y,l,_,_,_), l >=100 – P(x,y) :- Q(x,z), NOT R(w,x,z), x<y 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa6 Every variable that appears anywhere in the rule must appear in some nonnegated, relational subgoal of the body

Alternative Interpretation: Consistency For each consistent assignment of nonnegated, relational subgoal, Check the negated, relational subgoals and the arithmetic subgoals for consistency 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa7 Q(1,2) Q(1,3) R(2,3) R(3,1) P(x,y) :- Q(x,z), R(z,y), NOT Q(x,y) Datalog Q(x,z)R(z,y)Consistent?NOT Q(x,y)Head (1,2)(2,3) (1,2)(3,1) (1,3)(2,3) (1,3)(3,1) Yesfalse No, z=2,3 Yes true P(1,1)

Intensional vs Extensional Extensional predicates – relations stored in a database Intensional predicates – computed by applying one or more datalog rules 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa8 Q(1,2) Q(1,3) R(2,3) R(3,1) P(x,y) :- Q(x,z), R(z,y), NOT Q(x,y) Datalog extensional intensional

What about bag semantics ? Datalog still works if there are no negated, relational subgoals. Treat duplicates like non-duplicates 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa9 R(1,2) S(2,3) S(4,5) H(x,z) :- R(x,y), S(y,z) Datalog R(x,y)S(y,z)Consistent?Head (1,2)(2,3) (1,2)(4,5) (1,2)(4,5)... Yes No, y=2,4 H(1,3)

Example 1 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa10 Answer(x,y) :- A(x,y) Answer(x,y) :- B(x,y) Datalog

Example 2 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa11 Answer(x,y) :- A(x,y), B(x,y) Datalog

Example 3 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa12 Answer(x,y) :- A(x,y), NOT B(x,y) Datalog

Example 4 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa13 Answer(x,y) :- A(x,y), x > 10, y = 200 Datalog

Example 5 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa14 Answer(x) :- A(x,y) Datalog

Example 6 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa15 Answer(w,x,y,z) :- A(w,x), B(y,z) Datalog

Example 7 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa16 Answer(w,x,y) :- A(w,x), B(x,y) Datalog

Example 8 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa17 Answer(w,x,z) :- A(w,x), B(y,z), x>y Datalog

Example 9 10/3/2011Lipyeow Lim -- University of Hawaii at Manoa18 Path(x,y) :- Edge(x,y) Path(x,z) :- Edge(x,y), Edge(y,z) Datalog