Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman

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

Interprocedural Analysis. Currently, we only perform data-flow analysis on procedures one at a time. Such analyses are called intraprocedural analyses.
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.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
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.
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.
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.
Logical Rules Recursion
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
Rutgers University Relational Calculus 198:541 Rutgers University.
Logical Query Languages Motivation: 1.Logical rules extend more naturally to recursive queries than does relational algebra. u Used in SQL recursion. 2.Logical.
DEDUCTIVE DATABASE.
Databases 1 8th lecture. Topics of the lecture Multivalued Dependencies Fourth Normal Form Datalog 2.
DECIDABILITY OF PRESBURGER ARITHMETIC USING FINITE AUTOMATA Presented by : Shubha Jain Reference : Paper by Alexandre Boudet and Hubert Comon.
Recursive query plans for Data Integration Oliver Michael By Rajesh Kanisetti.
The Relational Model: Relational Calculus
Logical Query Languages Motivation: 1.Logical rules extend more naturally to recursive queries than does relational algebra. u Used in SQL recursion. 2.Logical.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4.
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.
CSE 636 Data Integration Conjunctive Queries Containment Mappings / Canonical Databases Slides by Jeffrey D. Ullman Fall 2006.
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,
Language: Set of Strings
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.
ICS 321 Fall 2011 Algebraic and Logical Query Languages (ii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
1 Datalog with negation Adapted from slides by Jeff Ullman.
CS589 Principles of DB Systems Fall 2008 Lecture 4c: Query Language Equivalence Lois Delcambre
Relational Calculus Chapter 4, Section 4.3.
CS589 Principles of DB Systems Spring 2014 Unit 2: Recursive Query Processing Lecture 2-1 – Naïve algorithm for recursive queries Lois Delcambre (slides.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Chapter 2 - Introduction to C Programming
Relational Calculus Chapter 4, Part B
Modifying the Database
Chapter 2 - Introduction to C Programming
Containment Mappings Canonical Databases Sariaya’s Algorithm
Semantics of Datalog With Negation
Cse 344 April 11th – Datalog.
CSE 344: Section 5 Datalog February 1st, 2018.
February 7th – Exam Review
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Cse 344 January 29th – Datalog.
Motivation for Datalog
Lecture 9: Relational Algebra (continued), Datalog
Week #2 – 4/6 September 2002 Prof. Marie desJardins
Chapter 2 - Introduction to C Programming
Mathematical Background 1
Horn Clauses and Unification
Logic Based Query Languages
Axiomatic Semantics Will consider axiomatic semantics (A.S.) of IMP:
Brief Introduction to Computational Logic
Datalog Inspired by the impedance mismatch in relational databases.
Chapter 2 - Introduction to C Programming
Conjunctive Queries, Views, Datalog Monday, 4/29/2002
Representations & Reasoning Systems (RRS) (2.2)
CS589 Principles of DB Systems Fall 2008 Lecture 4e: Logic (Model-theoretic view of a DB) Lois Delcambre
Boolean Expressions September 1, 2019 ICS102: The course.
Select-From-Where Statements Multirelation Queries Subqueries
Rules Programs Negation
Relational Calculus Chapter 4, Part B
Presentation transcript:

Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman CSE 636 Data Integration Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman Fall 2006

Review of Logical If-Then Rules body head subgoals h(X,…) :- a(Y,…) & b(Z,…) & … “The head is true if all the subgoals are true.”

Terminology Head and subgoals are atoms. An atom consists of a predicate (lower case) applied to zero or more arguments (upper case letters or constants).

Semantics Predicates represent relations. An atom is true for given values of its variables iff the arguments form a tuple of the relation. Whenever an assignment of values to all variables makes all subgoals true, the rule asserts that the resulting head is also true.

Example We shall develop rules that describe what is necessary to “make” a file. The predicates/relations: source(F) = F is a “source” file. includes(F,G) = F #includes G. create(F,P,G) = F is created by applying process P to file G.

Example - Continued Rules to define “view” req(X,Y) = file Y is required to create file X : req(F,F) :- source(F) req(F,G) :- includes(F,G) req(F,G) :- create(F,P,G) req(F,G) :- req(F,H) & req(H,G) G is required for F if there is some process P that creates F from G. G is required for F if there is some H such that H is required for F and G is required for H.

Why Not Just Use SQL? Recursion is much easier to express in Datalog. Viz. last rule for req. Rules express things that go on in both FROM and WHERE clauses, and let us state some general principles (e.g., containment of rules) that are almost impossible to state correctly in SQL.

IDB/EDB A predicate representing a stored relation is called EDB (extensional database). A predicate representing a “view,” i.e., a defined relation that does not exist in the database is called IDB (intensional database). Head is always IDB; subgoals may be IDB or EDB.

Datalog Programs A collection of rules is a (Datalog) program. Each program has a distinguished IDB predicate that represents the result of the program. E.g., req in our example.

Extensions Negated subgoals. Constants as arguments. Arithmetic subgoals.

Negated Subgoals NOT in front of a subgoal means that an assignment of values to variables must make it false in order for the body to be true. Example: cycle(F) :- req(F,F) & NOT source(F)

Constants as Arguments We use numbers, lower-case letters, or quoted strings to indicate a constant. Example: req(“foo.c”, “stdio.h”) :- Note that empty body is OK. Mixed constants and variables also OK.

Arithmetic Subgoals Comparisons like < may be thought of as infinite, binary relations. Here, the set of all tuples (x,y) such that x<y. Use infix notation for these predicates. Example: composite(A) :- divides(B,A) & B > 1 & B != A

Safety When we apply a rule to finite relations, we need to get a finite result. Simple guarantee: safety = all variables appear in some nonnegated, relational (not arithmetic) subgoal of the body. Start with the join of the nonnegated, relational subgoals and select/delete from there.

Examples: Nonsafety p(X) :- q(Y) bachelor(X) :- NOT married(X,Y) X is the problem p(X) :- q(Y) bachelor(X) :- NOT married(X,Y) bachelor(X) :- person(X) & NOT married(X,Y) Both X and Y are problems Y is still a problem

Applying Rules To evaluate an IDB predicate p : Apply each rule for p to the current relations corresponding to its subgoals. “Apply” = If an assignment of values to variables makes the body true, insert the tuple that the head becomes into the relation for p (no duplicates). Take the union of the result for each p-rule.

Example p(X,Y) :- q(X,Z) & r(Z,Y) & Y<10 Q = {(1,2), (3,4)}; Assignments making the body true: (X,Y,Z) = (1,5,2), (3,9,4) So P = {(1,5), (3,9)}.