Datalog-Logic As Database Language-Lecture Slides, Slides of Database Programming

Prof. Gopesh Valsan delivered this lecture at Ambedkar University, Delhi for Logic Language For Database course. Its main points are: Datalog, Rules, Programs, Negation, Semantics, Source, SQL, Recursion, IDB, EDB

Typology: Slides

2011/2012

Uploaded on 07/15/2012

saligrama
saligrama 🇮🇳

1

(1)

36 documents

1 / 47

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Datalog
Rules
Programs
Negation
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f

Partial preview of the text

Download Datalog-Logic As Database Language-Lecture Slides and more Slides Database Programming in PDF only on Docsity!

Datalog

Rules

Programs

Negation

docsity.com

Review of Logical If-Then Rules

h(X,…) :- a(Y,…) & b(Z,…) & …

head

body

subgoals

“The head is true if all the subgoals are true.”

docsity.com

Semantics

Predicates represent relations.

An atom is true for given values of its variables iff the arguments form a tupleof the relation.

Whenever an assignment of values to all variables makes all subgoals true,the rule asserts that the resulting headis also true.

docsity.com

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.

docsity.com

Why Not Just Use SQL?

Recursion is much easier to express inDatalog.

‹

Viz. last rule for

req

.

Rules express things that go on in bothFROM and WHERE clauses, and let usstate some general principles (e.g.,containment of rules) that are almostimpossible to state correctly in SQL.

docsity.com

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 thedatabase is called

IDB

(intesional

database).

Head is always IDB; subgoals may be IDB or EDB.

docsity.com

Extensions

Negated subgoals.

Constants as arguments.

Arithmetic subgoals.

docsity.com

Negated Subgoals

NOT in front of a subgoal means that an assignment of values to variablesmust make it false in order for the bodyto be true.

Example:

cycle(F) :- req(F,F) & NOT source(F)

docsity.com

13

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

B

A

docsity.com

Evaluating Datalog Programs

Nonrecursive programs.

Naïve evaluation of recursiveprograms without IDB negation.

Seminaïve evaluation of recursiveprograms without IDB negation.

‹

Eliminates some redundant computation.

docsity.com

Examples: Nonsafety

p(X)

q(Y)

bachelor(X)

NOT

married(X,Y)

bachelor(X)

person(X)

NOT

married(X,Y)

X is the problem

Both X and Yare problems

Y is still a problem

docsity.com

Nonrecursive Evaluation

If (and only if!) a Datalog program is not recursive, then we can order theIDB predicates so that in any rule for

p

(i.e.,

p

is the head predicate), the only

IDB predicates in the body precede

p.

docsity.com

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 tovariables makes the body true, insert thetuple that the head becomes into the relationfor

p

(no duplicates).

Take the union of the result for each

p-

rule.

docsity.com

Example

p(X,Y)

q(X,Z)

r(Z,Y)

Y<

Q = {(1,2), (3,4)};R = {(2,5), (4,9), (4,10), (6,7)}

Assignments making the body true:

(X,Y,Z) = (1,5,2), (3,9,4)

So P = {(1,5), (3,9)}.

docsity.com