Apply each rule for p to the current relations corresponding to its subgoals.
“ Apply” = If an assignment of values to variables makes the body true, insert the tuple that the head becomes into the relation for p (no duplicates).
As long as there is no negation of IDB subgoals, then each IDB relation “grows,” i.e., on each round it contains at least what it used to contain.
Since relations are finite, the loop must eventually terminate.
Result is the least fixed point ( minimal model ) of rules.
make all IDB relations empty; REPEAT FOR (each IDB predicate p) DO evaluate p using current values of all relations; UNTIL (no IDB relation is changed)
parent ( X , Y ) father ( X , Y ) parent ( X , Y ) mother ( X , Y ) grandfather ( X , Y ) father ( X , Z ) parent ( Z , Y ) ancestor ( X , Y ) parent ( X , Y ) ancestor ( X , Y ) parent ( X , Z ) ancestor ( Z , Y ) father (john, tony) mother (mary, bob) father (peter, mary) FACTS DEDUCTIVE RULES
Wen using Logic as a Database language, we don’t take care of:
NULL values
Bag semantics
Strong typing
So, why use Logic instead of SQL?
Deductive rules express things that go on in both FROM and WHERE clauses, and let us state some general principles and properties (e.g., containment of rules) that are almost impossible to state correctly in SQL.
We can take advantage of results, approaches, algorithms, … from Logic, Logic Programming and AI
A query Q 1 is contained in another query Q 2 , Q 1 ⊑ Q 2 , when the answer that a query Q 1 obtains is a subset of the answer obtained by another Q 2 , for every database state.
Q 1 is contained in Q 2 : Q 1 ⊑ Q 2 { q (a 1 ,…, a n ) | q (a 1 ,…, a n ) ( Q 1 DR )( EDB ) } { q (b 1 ,…, b n ) | q (b 1 ,…, b n ) ( Q 2 DR )( EDB ) } for any EDB
When considering the integrity constraints defined in a database, the containment relationship between two queries does not need to hold for any state (content) of the database but only for the consistent ones, i.e. those that satisfy the integrity constraints
Q 1 is contained in Q 2 wrt. IC : Q 1 ⊑ IC Q 2 { q (a 1 ,…, a n ) | q (a 1 ,…, a n ) ( Q 1 DR )( EDB ) } { q (b 1 ,…, b n ) | q (b 1 ,…, b n ) ( Q 2 DR )( EDB ) } for any EDB that does not violate IC
... without accessing to the database contents in any case.
23.
Uses of QC: Example emp (joan, sales) emp (pere, sales) dept (sales) manager (pere, sales) em ( E , M ) emp ( E,D ) manager ( M , D ) Ic 1 : emp ( E , D ) ¬ dept ( D ) Ic 2 : manager ( M , D ) ¬ emp ( M , D ) Ic 3 : manager ( M , D ) ¬ dept ( D ) Q 1 : q ( E , M ) em ( E , M ) emp ( E , D ) Q 2 : q ( M , D ) manager ( M , D ) ¬ emp ( M , D ) U 1 : { Insert dept (accounting)}
Be the first to comment