Stratied Negation Negation wrapp ed inside a recursion mak - - PDF document

strati ed negation negation wrapp ed inside a recursion
SMART_READER_LITE
LIVE PREVIEW

Stratied Negation Negation wrapp ed inside a recursion mak - - PDF document

Stratied Negation Negation wrapp ed inside a recursion mak es no sense. Ev en when negation and recursion are separated, there can b e am biguit y ab out what the rules mean, and some one meaning m


slide-1
SLIDE 1 Stratied Negation
  • Negation
wrapp ed inside a recursion mak es no sense.
  • Ev
en when negation and recursion are separated, there can b e am biguit y ab
  • ut
what the rules mean, and some
  • ne
meaning m ust b e selected.
  • Str
atie d ne gation is an additional restrain t
  • n
recursiv e rules (lik e safet y) that solv es b
  • th
problems: 1. It rules
  • ut
negation wrapp ed in recursion. 2. When negation is separate from recursion, it yields the in tuitiv el y correct meaning
  • f
rules.
  • Stratication
recen tly adopted in the SQL3 standard for recursiv e SQL. 1
slide-2
SLIDE 2 Problem with Recursiv e Negation Consider: P(x) <- Q(x) AND NOT P(x)
  • Q
= EDB = f1; 2g.
  • Compute
IDB P iterativ el y?

Initial ly , P = ;.

Round 1: P = f1; 2g.

Round 2: P = ;, etc., etc. 2
slide-3
SLIDE 3 Strata In tuitiv ely : stratum
  • f
an IDB predicate = maxim um n um b er
  • f
negations y
  • u
can pass through
  • n
the w a y to an EDB predicate.
  • Must
not b e 1 in \stratied" rules.
  • Dene
str atum gr aph:

No des = IDB predicates.

Arc P ! Q if Q app ears in the b
  • dy
  • f
a rule with head P .

Lab el that arc
  • if
Q is in a negated subgoal. Example P(x) <- Q(x) AND NOT P(x) P
  • 3
slide-4
SLIDE 4 Example Reach(x) <- Source(x) Reach(x) <- Reach(y) AND Arc(y,x) NoReach(x) <- Target(x) AND NOT Reach(x) Reach NoReach
  • 4
slide-5
SLIDE 5 Computing Strata Str atum
  • f
an IDB predicate A = maxim um n um b er
  • f
  • arcs
  • n
an y path from A in the stratum graph. Examples
  • F
  • r
rst example, stratum
  • f
P is 1.
  • F
  • r
second example, stratum
  • f
Reach is 0; stratum
  • f
NoReach is 1. Stratied Negation A Datalog program with recursion and negation is str atie d if ev ery IDB predicate has a nite stratum. Stratied Mo del If a Datalog program is stratied, w e can compute the relations for the IDB predicates lo w est- stratum-rst. 5
slide-6
SLIDE 6 Example Reach(x) <- Source(x) Reach(x) <- Reach(y) AND Arc(y,x) NoReach(x) <- Target(x) AND NOT Reach(x)
  • EDB:

Source = f1g.

Arc = f(1; 2); (3; 4); (4; 3)g.

Target = f2; 3g. 1 2 3 4 source target target
  • First
compute Reach = f1; 2g (stratum 0).
  • Next
compute NoReach = f3g. 6
slide-7
SLIDE 7 Is the Stratied Solution \Ob vious"? Not really .
  • There
is another mo del that mak es the rules true no matter what v alues w e substitute for the v ariables.

Reach = f1; 2; 3; 4g.

NoReach = ;.
  • Remem
b er: the
  • nly
w a y to mak e a Datalog rule false is to nd v alues for the v ariables that mak e the b
  • dy
true and the head false.

F
  • r
this mo del, the heads
  • f
the rules for Reach are true for all v alues, and in the rule for NoReach the subgoal NOT Reach(x) assures that the b
  • dy
cannot b e true. 7
slide-8
SLIDE 8 SQL3 Recursion WITH stu that lo
  • ks
lik e Datalog rules an SQL query ab
  • ut
EDB, IDB
  • Rule
= [RECURSIVE] R (<argumen ts>) AS SQL query 8
slide-9
SLIDE 9 Example Find Sally's cousins, using EDB Par(child, parent). WITH Sib(x,y) AS SELECT p1.child, p2,child FROM Par p1, Par p2 WHERE p1.parent = p2.parent AND p1.child <> p2.child, RECURSIVE Cousin(x,y) AS Sib UNION (SELECT p1.child, p2.child FROM Par p1, Par p2, Cousin WHERE p1.parent = Cousin.x AND p2.parent = Cousin.y ) SELECT y FROM Cousin WHERE x = 'Sally'; 9
slide-10
SLIDE 10 Plan for Describing Legal SQL3 recursion 1. Dene \monotonicit y ," a prop ert y that generalizes \straticati
  • n."
2. Generalize stratum graph to apply to SQL queries instead
  • f
Datalog rules.

(Non)monotonicit y replaces NOT in subgoals. 3. Dene seman tically correct SQL3 recursions in terms
  • f
stratum graph. Monotonicit y If relation P is a function
  • f
relation Q (and p erhaps
  • ther
things), w e sa y P is monotone in Q if adding tuples to Q cannot cause an y tuple
  • f
P to b e deleted. 10
slide-11
SLIDE 11 Monotonicit y Example In addition to certain negations, an aggregation can cause nonmonotonicit y . Sells(bar , beer , price) SELECT AVG(price) FROM Sells WHERE bar = 'Joe''s Bar';
  • Adding
to Sells a tuple that giv es a new b eer Jo e sells will usually c hange the a v erage price
  • f
b eer at Jo e's.
  • Th
us, the former result, whic h migh t b e a single tuple lik e (2:78) b ecomes another single tuple lik e (2:81), and the
  • ld
tuple is lost. 11
slide-12
SLIDE 12 Generalizing Stratum Graph to SQL
  • No
de for eac h relation dened b y a \rule."
  • No
de for eac h sub query in the \b
  • dy"
  • f
a rule.
  • Arc
P ! Q if a) P is \head"
  • f
a rule, and Q is a relation app earing in the FROM list
  • f
the rule (not in the FROM list
  • f
a sub query). b) P is head
  • f
a rule, and Q is a sub query directly used in that rule (not nested within some larger sub query). c) P is a sub query , and Q is a relation
  • r
sub query used directly within P .
  • Lab
el the arc
  • if
P is not monotone in Q.
  • Requiremen
t for legal SQL3 recursion: nite strata
  • nly
. 12
slide-13
SLIDE 13 Example F
  • r
the Sib/Cousin example, there are three no des: Sib, Cousin, and S Q (the second term
  • f
the union in the rule for Cousin. Sib Cousin S Q
  • No
nonmonotonicit y , hence legal. 13
slide-14
SLIDE 14 A Nonmonotonic Example Change the UNION to EXCEPT in the rule for Cousin. RECURSIVE Cousin(x,y) AS Sib EXCEPT (SELECT p1.child, p2.child FROM Par p1, Par p2, Cousin WHERE p1.parent = Cousin.x AND p2.parent = Cousin.y )
  • No
w, Adding to the result
  • f
the sub query can delete Cousin facts; i.e., Cousin is nonmonotone in S G. Sib Cousin S Q
  • Innite
n um b er
  • f
's in cycle, so illegal in SQL3. 14
slide-15
SLIDE 15 Another Example: NOT Do esn't Mean Nonmonotone Lea v e Cousin as it w as, but negate
  • ne
  • f
the conditions in the where-clause. RECURSIVE Cousin(x,y) AS Sib UNION (SELECT p1.child, p2.child FROM Par p1, Par p2, Cousin WHERE p1.parent = Cousin.x AND NOT (p2.parent = Cousin.y) )
  • Y
  • u
migh t think that S G dep ends negativ ely
  • n
Cousin, but it do esn't.

If I add a new tuple to Cousin, all the
  • ld
tuples still exist and yield whatev er tuples in S G they used to yield.

In addition, the new Cousin tuple migh t com bine with
  • ld
p1 and p2 tuples to yield something new. 15