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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Relational Calculus and Datalog
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.
1 Extended Conjunctive Queries Unions Arithmetic Negation.
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.
Databases and Information Systems 1 Prof. Dr. Stefan Böttcher Fakultät EIM, Institut für Informatik Universität Paderborn WS 2009 / 2010 Contents: selectivity.
1 Conjunctions of Queries. 2 Conjunctive Queries A conjunctive query is a single Datalog rule with only non-negated atoms in the body. (Note: No negated.
Conditional statements and Boolean expressions. The if-statement in Java (1) The if-statement is a conditional statement The statement is executed only.
1 Lecture 12: SQL Friday, October 26, Outline Simple Queries in SQL (5.1) Queries with more than one relation (5.2) Subqueries (5.3) Duplicates.
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.
Local-as-View Mediators Priya Gangaraju(Class Id:203)
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.
Mid-term Class Review.
Credit: Slides are an adaptation of slides from Jeffrey D. Ullman 1.
Deductive Databases Chapter 25
SQL By: Toan Nguyen. Download Download the software at During the installation –Skip sign up for fast installation.
CS 255: Database System Principles slides: From Parse Trees to Logical Query Plans By:- Arunesh Joshi Id:
Database Systems Logical Query Languages assoc. prof., dr. Vladimir Dimitrov web: is.fmi.uni-sofia.bg.
Logical Query Languages Motivation: 1.Logical rules extend more naturally to recursive queries than does relational algebra. u Used in SQL recursion. 2.Logical.
CS 255: Database System Principles slides: From Parse Trees to Logical Query Plans By:- Arunesh Joshi Id:
Recursive query plans for Data Integration Oliver Michael By Rajesh Kanisetti.
The Relational Model: Relational Calculus
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Computer Science 210 Computer Organization Introduction to Boolean Algebra.
Logical Query Languages Motivation: 1.Logical rules extend more naturally to recursive queries than does relational algebra. u Used in SQL recursion. 2.Logical.
Relational Algebra (Chapter 7)
Datalog Inspired by the impedance mismatch in relational databases. Main expressive advantage: recursive queries. More convenient for analysis: papers.
INFORMATION INTEGRATION Shengyu Li CS-257 ID-211.
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,
8.4 Use Scientific Notation Algebra. Scientific Notation Numbers such as 1,000,000, 153,000 and are written in standard form. Another way to write.
Row Types in SQL-3 Row types define types for tuples, and they can be nested. CREATE ROW TYPE AddressType{ street CHAR(50), city CHAR(25), zipcode CHAR(10)
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.
Chapter 3: Relational Model III Additional Relational Algebra Operations Additional Relational Algebra Operations Views Views.
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.
1 Database Design: DBS CB, 2 nd Edition Relational Algebra: Basic Operations & Algebra of Bags Ch. 5.
CS589 Principles of DB Systems Fall 2008 Lecture 4d: Recursive Datalog with Negation – What is the query answer defined to be? Lois Delcambre
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 6 th Edition Chapter 8: Relational Algebra.
CS589 Principles of DB Systems Fall 2008 Lecture 4c: Query Language Equivalence 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
Module 2: Intro to Relational Model
Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Modifying the Database
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.
Chapter 3: Relational Model III
Chapter 2: Intro to Relational Model
Cse 344 April 11th – Datalog.
February 7th – Exam Review
Lecture 10: Relational Algebra (continued), Datalog
Cse 344 January 29th – Datalog.
Computer Science 210 Computer Organization
Motivation for Datalog
Lecture 9: Relational Algebra (continued), Datalog
Chapter 2: Intro to Relational Model
Algebraic and Logical Query Languages pp.54 is added
Logic Based Query Languages
Chapter 2: Intro to Relational Model
Example of a Relation attributes (or columns) tuples (or rows)
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 4a: Introduction to Datalog Lois Delcambre
Rules Programs Negation
Presentation transcript:

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 (Datalog) that consists of if-then rules. Datalog is inherently a logic of sets Datalog queries are more powerful than relational algebra; several rules can express recursions that are not expressable in algebra Relations are represented in Datalog as predicates; predicate (R) is followed by its arguments is called an atom Predicate returns a boolean value

3 Datalog: Logic instead of Algebra Rule: head body Head: relational atom : read if Body: one or more atoms called subgoals which may be relational or arithmetic Example: LongMovie(t,y) Movies(t,y,l,s,p) AND l 100 It says: LongMovie(t,y) is true whenever we can find tuple in Movies with: first 2 components as (t,y) and 3 rd component as l that is at least 100, and any values in components 4 and 5 Equivalent to assignment statement in relational algebra: LongMovie := title,year (σ length100 (Movies))

4 Datalog: Logic instead of Algebra Extensional and Intentional Predicates: Extensional Predicates (EDB) are predicates whose relations are stored in a database Intentional Predicates (IDB) are predicates whose relations are computed by applying one or more Datalog rules As long as there is no negated relational subgoals, evaluating rules when relations are sets apply for bags as well Relational Algebra and Datalog: assume R(A,B,C), and S(A,B,C): Boolean: Union: R υ S is equivalent to these 2 rules: U(A,B,C) R(A,B,C) U(A,B,C) S(A,B,C)

5 Datalog: Logic instead of Algebra Intersection: R S is equivalent to the following rule: I(A,B,C) R(A,B,C) AND S(A,B,C) Set Difference: R - S is equivalent to the following rule: D(A,B,C) R(A,B,C) AND NOT S(A,B,C) Projection P(A,B) R(A,B,C) Selection S(A,B,C) R(A,B,C) AND C 100 Product P(A,B,C,D,E.F) R(A,B,C) AND S(D,E,F) Joins J(A,B,C,D) R(A,B) AND (S(B,C,D)

6 Datalog: Logic instead of Algebra Simulating Multiple Operations with Datalog Example: Algebraic Expression Title,year (σ length 100 (Movies) σ StudioName=Fox (Movies)) Translates into this set of rules: W(t,y,l,g,s,p) Movies(t,y,l,g,s,p) AND l 100 X(t,y,l,g,s,p) Movies(t,y,l,g,s,p) AND s = Fox Y(t,y,l,g,s,p) W(t,y,l,g,s,p) AND X(t,y,l,g,s,p) Answer(t,y) Y(t,y,l,g,s,p)

7 END