







































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 47
This page cannot be seen from the preview
Don't miss anything!








































Rules
Programs
Negation
docsity.com
h(X,…) :- a(Y,…) & b(Z,…) & …
head
body
subgoals
“The head is true if all the subgoals are true.”
docsity.com
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
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
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
A predicate representing a stored relation is called
(extensional database).
A predicate representing a “view,” i.e., a defined relation that does not exist in thedatabase is called
(intesional
database).
Head is always IDB; subgoals may be IDB or EDB.
docsity.com
Negated subgoals.
Constants as arguments.
Arithmetic subgoals.
docsity.com
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
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)
docsity.com
Nonrecursive programs.
Naïve evaluation of recursiveprograms without IDB negation.
Seminaïve evaluation of recursiveprograms without IDB negation.
Eliminates some redundant computation.
docsity.com
p(X)
q(Y)
bachelor(X)
married(X,Y)
bachelor(X)
person(X)
married(X,Y)
X is the problem
Both X and Yare problems
Y is still a problem
docsity.com
If (and only if!) a Datalog program is not recursive, then we can order theIDB predicates so that in any rule for
(i.e.,
is the head predicate), the only
IDB predicates in the body precede
docsity.com
To evaluate an IDB predicate
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
p(X,Y)
q(X,Z)
r(Z,Y)
Assignments making the body true:
So P = {(1,5), (3,9)}.
docsity.com