Stratified Negation, Recursive Negation, Strata, SQL3 Recursion | CS 610, Study notes of Deductive Database Systems

Material Type: Notes; Class: Database Systems I; Subject: Computer Science; University: University of Alabama - Birmingham; Term: Fall 2001;

Typology: Study notes

Pre 2010

Uploaded on 04/12/2010

koofers-user-wpq-1
koofers-user-wpq-1 🇺🇸

4

(1)

10 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Stratied Negation
Negation wrapped inside a recursion makes no
sense.
Even when negation and recursion are
separated, there can be ambiguity about what
the rules mean, and some one meaning must
be selected.
Stratiednegation
is an additional restrainton
recursive rules (like safety) that solves both
problems:
1. It rules out negation wrapped in
recursion.
2. When negation is separate from recursion,
it yields the intuitively correct meaning of
rules (the
stratiedmodel
).
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Stratified Negation, Recursive Negation, Strata, SQL3 Recursion | CS 610 and more Study notes Deductive Database Systems in PDF only on Docsity!

Strati ed Negation

 Negation wrapp ed inside a recursion makes no sense.

 Even when negation and recursion are separated, there can b e ambiguity ab out what the rules mean, and some one meaning must b e selected.

 Strati ed negation is an additional restraint on recursive rules (like safety) that solves b oth problems:

  1. It rules out negation wrapp ed in recursion.
  2. When negation is separate from recursion, it yields the intuitivel y correct meaning of rules (the strati ed model).

Problem with Recursive Negation

Consider:

P(x) <- Q(x) AND NOT P(x)

 Q = EDB = f 1 ; 2 g.

 Compute IDB P iterativel y?

F Initial ly, P = ;. F Round 1: P = f 1 ; 2 g. F Round 2: P = ;, etc., etc.

Example

Reach(x) <- Source(x) Reach(x) <- Reach(y) AND Arc(y,x) NoReach(x) <- Target(x) AND NOT Reach(x)

Reach

NoReach

Computing Strata

Stratum of an IDB predicate A = maximum numb er of arcs on any path from A in the stratum graph.

Examples

 For rst example, stratum of P is 1.

 For second example, stratum of Reach is 0; stratum of NoReach is 1.

Strati ed Negation

A Datalog program with recursion and negation is strati ed if every IDB predicate has a nite stratum.

Strati ed Mo del

If a Datalog program is strati ed, we can compute the relations for the IDB predicates lowest- stratum- rst.

Is the Strati ed Solution \Obvious"?

Not really.

 There is another mo del that makes the rules true no matter what values we substitute for the variables. F Reach = f 1 ; 2 ; 3 ; 4 g. F NoReach = ;.

 Rememb er: the only way to make a Datalog rule false is to nd values for the variables that make the b o dy true and the head false. F For this mo del, the heads of the rules for Reach are true for all values, and in the rule for NoReach the subgoal NOT Reach(x) assures that the b o dy cannot b e true.

SQL3 Recursion

WITH stu that lo oks like Datalog rules an SQL query ab out EDB, IDB

 Rule =

[RECURSIVE] R () AS SQL query

Plan for Describing Legal SQL3 recursion

  1. De ne \monotonicity," a prop erty that generalizes \strati cati on."
  2. Generalize stratum graph to apply to SQL queries instead of Datalog rules. F (Non)monotonicity replaces NOT in subgoals.
  3. De ne semantically correct SQL3 recursions in terms of stratum graph.

Monotonicity

If relation P is a function of relation Q (and p erhaps other things), we say P is monotone in Q if adding tuples to Q cannot cause any tuple of P to b e deleted.

Monotonicity Example

In addition to certain negations, an aggregation can cause nonmonotonicity.

Sells(bar , beer , price)

SELECT AVG(price) FROM Sells WHERE bar = 'Joe''s Bar';

 Adding to Sells a tuple that gives a new b eer Jo e sells will usually change the average price of b eer at Jo e's.

 Thus, the former result, which might b e a single tuple like (2:78) b ecomes another single tuple like (2:81), and the old tuple is lost.

Example

For the Sib/Cousin example, there are three no des: Sib, Cousin, and S Q (the second term of the union in the rule for Cousin).

Sib Cousin

S Q

 No nonmonotonicity, hence legal.

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 )

 Now, adding to the result of the sub query can delete Cousin facts; i.e., Cousin is nonmonotone in S Q.

Sib Cousin

S Q

 In nite numb er of 's in cycle, so illegal in SQL3.