CS589 Principles of DB Systems Fall 2008 Lecture 4d: Recursive Datalog with Negation – What is the query answer defined to be? Lois Delcambre lmd@cs.pdx.edu.

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

Relational Calculus and Datalog
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.
Query Folding Xiaolei Qian Presented by Ram Kumar Vangala.
Yinghui Wu, LFCS DB talk Database Group Meeting Talk Yinghui Wu 10/11/ Simulation Revised for Graph Pattern Matching.
Answer Set Programming Overview Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma de Guadalajara
1 Recursive SQL, Deductive Databases, Query Evaluation Book Chapter of Ramankrishnan and Gehrke DBMS Systems, 3 rd ed.
1 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke Deductive Databases Chapter 25.
Cs774 (Prasad)L7Negation1 Negation by Failure
1 9. Evaluation of Queries Query evaluation – Quantifier Elimination and Satisfiability Example: Logical Level: r   y 1,…y n  r’ Constraint.
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.
Conjunctive Queries, Datalog, and Recursion Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 23, 2003 Some slide.
CSE 636 Data Integration Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman.
2005conjunctive1 Query languages, equivalence & containment  conjunctive queries – CQ’s  More expressive languages.
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.
Cs5611 Recursive SQL, Deductive Databases, Query Evaluation Slides based on book chapter, By Ramankrishnan and Gehrke DBMS Systems, 3 rd ed.
1 Datalog Logical Rules Recursion. 2 Logic As a Query Language uIf-then logical rules have been used in many systems. wMost important today: EII (Enterprise.
Credit: Slides are an adaptation of slides from Jeffrey D. Ullman 1.
Deductive Databases Chapter 25
CS 286, UC Berkeley, Spring 2007, R. Ramakrishnan 1 Introduction to Logic and Databases R. Ramakrishnan Database Management Systems, Gehrke- Ramakrishnan,
Databases 1 8th lecture. Topics of the lecture Multivalued Dependencies Fourth Normal Form Datalog 2.
Recursive query plans for Data Integration Oliver Michael By Rajesh Kanisetti.
Logical Query Languages Motivation: 1.Logical rules extend more naturally to recursive queries than does relational algebra. u Used in SQL recursion. 2.Logical.
Steffen Staab Advanced Data Modeling 1 of 32 WeST Häufungspunkte Bifurkation: x n+1 = r x n (1-x n ) Startwert x 0 = 0,25.
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.
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,
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.
Database Management Systems Course Faculty of Computer Science Technion – Israel Institute of Technology Lecture 5: Queries in Logic.
1 Reasoning with Infinite stable models Piero A. Bonatti presented by Axel Polleres (IJCAI 2001,
Raluca Paiu1 Semantic Web Search By Raluca PAIU
CS589 Principles of DB Systems Fall 2008 Lecture 4d: Recursive Datalog with Negation – What is the query answer defined to be? Lois Delcambre
Extensions of Datalog Wednesday, February 13, 2001.
1 Datalog with negation Adapted from slides by Jeff Ullman.
CS589 Principles of DB Systems Fall 2008 Lecture 4c: Query Language Equivalence Lois Delcambre
CS589 Principles of DB Systems Fall 2008 Lecture 4b: Domain Independence and Safety Lois Delcambre
1 11. Certification Certification – algorithms/methods to verify that a program is safe. Used when restriction does not work because we use a combination.
Rule-based Reasoning in Semantic Text Analysis
CS589 Principles of DB Systems Spring 2014 Unit 2: Recursive Query Processing Lecture 2-1 – Naïve algorithm for recursive queries Lois Delcambre (slides.
Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman
Lois Delcambre (slides from Dave Maier)
Great Theoretical Ideas In Computer Science
Goal for this lecture Demonstrate how we can prove that one query language is more expressive than (i.e., “contained in” as described in the book) another.
+ Notes on Aggregates and Stratification in DeALS
Graph-Based Operational Semantics
Computing Full Disjunctions
Introduction to MS Access: creating tables, keys, and relationships
Management of XML and Semistructured Data
Semantics of Datalog With Negation
Cse 344 May 7th – Exam Review.
CSE 344: Section 5 Datalog February 1st, 2018.
February 7th – Exam Review
Graphs All tree structures are hierarchical. This means that each node can only have one parent node. Trees can be used to store data which has a definite.
Managing XML and Semistructured Data
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Logic Based Query Languages
Logic Programming & LPMLN
Brief Introduction to Computational Logic
Datalog Inspired by the impedance mismatch in relational databases.
Conjunctive Queries, Views, Datalog Monday, 4/29/2002
CSE 544: Lecture 11 Theory Monday, May 3, 2004.
Representations & Reasoning Systems (RRS) (2.2)
CS589 Principles of DB Systems Fall 2008 Lecture 4a: Introduction to Datalog Lois Delcambre
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:

CS589 Principles of DB Systems Fall 2008 Lecture 4d: Recursive Datalog with Negation – What is the query answer defined to be? Lois Delcambre lmd@cs.pdx.edu 503 725-2405

Goals for today Introduce the problem with recursion and negation in Datalog. Introduce stratification – a syntactic restriction that avoids the problem. Mention several ways to define the semantics of a Datalog program.

Several Datalog languages This one is often referred to as “Datalog” or “Datalog-neg” Datalog – one rule, no negation, no recursion. (conjunctive queries) Datalog – multiple rules, no negation, no recursion. Datalog – multiple rules, no negation, with recursion. Recursion but not relationally complete. Datalog – multiple rules, with negation, no recursion. Relationally complete but no recursion. Datalog – multiple rules, with negation, with recursion. Relationally complete with recursion but some queries are ambiguous! This one is often referred to as “Datalog”; it was defined first. Our focus for QL equiv. Our focus now

Datalog program and it’s dependency graph Given a DB with two relations: Topics(Topic) and Interests(Person,Topic) What is this query computing? Result(a):-Interests(a,b,), DIFF(a). Diff(a) :- Prod(a,b), Interests(a,b). Prod(a,b) :- Interests(a,c), Topics(b). Create one node for each body predicate. Draw an arrow from body predicate to corresponding head predicate. Acyclic dependency graph ≡ not recursive. Topics Interests Prod Diff Result

Another example Anc(x,y) :- Parent-of(x,y). Anc(x,z) :- Anc(x,y), Parent-of(y,z). Recursive Datalog program has a cycle in the dependency graph. Parent-of Anc

Now consider Datalog with recursion & negation Person(Dan). (one tuple in base relation) Student(x) :- Person(x), Employee(x). Employee(x) :- Person(x), Student(x). What is the query answer?

What does the dependency graph look like? Person(Dan). (one tuple in base relation) Student(x) :- Person(x), Employee(x). Employee(x) :- Person(x), Student(x). This is a recursive program. Person Student Employee

More about this dependency graph Person(Dan). (one tuple in base relation) Student(x) :- Person(x), Employee(x). Employee(x) :- Person(x), Student(x). Cycle in dependency graph → recursion. Label negative predicates in dependency graph. Person  Student Employee 

Now consider recursion & negation Person(Dan). (one tuple in base relation) Student(x) :- Person(x), Employee(x). Employee(x) :- Person(x), Student(x). We have a problem when a cycle in a dependency graph includes (at least) one negative edge. Person  Student Employee 

Another example with negation & recursion Node(a). Node(b). Node(c). Node(d). Arc(a,b). Arc(c,d). Reachable(a). Reachable(y) :- Reachable(x), Arc(x,y). Unreachable(x) :- Node(x), Reachable(x). These are facts from the database.

Stratification – for Datalog with negation and recursion A stratification of a Datalog program P is a partition of P into strata or layers where, for every rule, H :- A1, …, Am, B1, …, Bq The rules that define the predicate H are all in the same strata. For all positive predicates in this rule, their strata is less than or equal to the strata of this rule. Strata(Ai) ≤ Strata(H). For all negative predicates in this rule, their strata is strictly less than the strata of this rule. Strata(Bi) < Strata(H).

Exercise: Define a stratification for this datalog program. Node(a). Node(b). Node(c). Node(d). Arc(a,b). Arc(c,d). Reachable(a). Reachable(y) :- Reachable(x), Arc(x,y). Unreachable(x) :- Node(x), Reachable(x). Compute all Reachable facts (positively) in Strata 1. Then, use Reachable negatively in Strata 2. Strata 1 Strata 2

Can you define a stratification for this program? Person(Dan). (one tuple in base relation) Student(x) :- Person(x), Employee(x). Employee(x) :- Person(x), Student(x).

Comments Stratified Datalog programs have a unique answer. Not all Datalog programs can be stratified.

Semantics of a Datalog Program The fixed point of the “immediate consequence” operator, applied to the Datalog program. The minimal model for the Datalog program. Plus others, particularly for Datalog with negation.

Comments For Datalog with recursion, but NO negation, then: The minimal model is unique. The minimal model is always the intersection of all the models. The minimal model is the same as the fixed point of the immediate consequence operator. This language is monotonic (rules only add facts) For Datalog with recursion & negation: There may not be a unique minimal model.

Questions If a predicate appears in the head of one rule and in the body of another, is the Datalog program necessarily recursive? If a datalog program is not recursive, how many times to we have to fire the rules?