









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
Material Type: Notes; Class: Database Systems I; Subject: Computer Science; University: University of Alabama - Birmingham; Term: Fall 2001;
Typology: Study notes
1 / 15
This page cannot be seen from the preview
Don't miss anything!










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:
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 (
Plan for Describing Legal SQL3 recursion
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.