Presentation is loading. Please wait.

Presentation is loading. Please wait.

603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 26 A First Course in Database Systems.

Similar presentations


Presentation on theme: "603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 26 A First Course in Database Systems."— Presentation transcript:

1 603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 26 A First Course in Database Systems

2 Deductive Databases Datalog Rules: Movie( Title: string Year: integer length: integer inColor: boolean studioName: string producerC#: integer Rule: LongMovie(t,y)  Movie(t,y,l,c,s,p) AND l  100

3 Deductive Databases LongMovie(t,y)  Movie(t,y,l,c,s,p) AND l  100 Predicate head  body Movie(t,y,l,c,s,p) AND l  100 (subgoal 1) (subgoal 2)

4 Deductive Databases Movie(t,y,l,c,s,p) has value true whenever the six variables have values that are the six components of some one Movie tuple. l  100 has value true whenever the length component of a Movie tuple is at least 100 minutes.

5 Deductive Databases Datalog Rule LongMovie(t,y)  Movie(t,y,l,c,s,p) AND l  100 Relational Algebra LongMovie =  title, year (  length  100 (Movie) )

6 Deductive Databases Anonymous Variables: *Frequently, Datalog Rules have variables that appear only once *The names used for these variables are thus irrelevant *For instance: LongMovie(t,y)  Movie(t,y,l,c,s,p) AND l  100 Variables c, s, and p can be replaced with underscores LongMovie(t,y)  Movie(t,y,l,_,_,_) AND l  100 We can’t replace any of the other variables since each appears twice in the rule.

7 Deductive Databases Datalog Queries: A query typically involves : 1)a predicate symbol 2)some variable arguments and its meaning (or “answer”) to deduce all the different constant combinations that when bound (assign) to the variables can make the predicate true superior (franklin, Y)? superior (james, Y)?

8 Deductive Databases Query Types: Type 1: superior(james, Y)? Requests the names of all subordinates of “james” at any level Type 2: superior (james, joyce)? Has only constant symbols as arguments, returns either a true or false

9 Deductive Databases Datalog Notation: In Datalog a program is built from objects called atomic formulas Atomic formulas are literals of the form p(a 1, a 2,….., a n ) predicate name n= number of arguments for p n = arity or degree of p

10 The Deductive Databases Datalog programs are a subset of predicate calculus In Datalog, atomic formulas are converted into what is called clausal forms (only the Horn clauses for Datalog and Prolog) Alfred Horn - Mathematician

11 Deductive Databases Disjunction of literals:   If  Then   =>  ~  #  Clause 1 or literal 1 Clause 2 or literal 2 Disjunction of literals

12 Deductive Databases HORN Clause: A Horn clause can contain at most one positive literal - NOT (P 1 ) OR NOT (P 2 ) OR….OR NOT(P n ) OR Q P 1 AND P 2 AND….AND P n => Q Q :- P 1, P 2, …., P n => Datalog Rule!

13 Deductive Databases Datalog Program: RULES 1. superior(X,Y):- supervise (X,Y). 2. superior(X,Y):- supervise(X,Y),superior(Z,Y). KNOWN FACTS(AXIOMS) = TRUE 3. supervise(franklin,john). 4. Supervise(franklin, ramesh). 5.supervise(franklin, joyce). 6.supervise(jennifer, alicia). 7.Supervise(jennifer, ahmad). Etc.

14 Deductive Databases DERIVED(INFERED) FACTS FROM RULES APPLICATION superior(X,Y) :- supervise (franklin, john) X=franklin and Y=john superior (franklin, john) = NewFact1 (Applied Rule 1 on 3) superior(X,Y) :- supervise(franklin, ramesh) X=franklin and Y=ramesh superior (franklin, ramesh) = NewFact2 (Applied Rule 1 on 4) etc.

15 Deductive Databases From Relational Algebra to Datalog: Each of the relational-algebra operators of Section 5.2 can be mimicked by one of several Datalog rules. We will combine Datalog rules to mimic complex algebraic expressions.

16 Deductive Databases Intersection: Relation R: nameaddressgenderbirthdate Carrie Fisher 123 Maple St., Holl. F 9/9/99 Mark Hamill 456 Oak Rd., Brent. M 8/8/88

17 Deductive Databases Intersection: Relation S: nameaddressgenderbirthdate Carrie Fisher 123 Maple St., Holl. F 9/9/99 Harrison Ford 789 Palm Dr., B. H. M 7/7/77

18 Deductive Databases Intersection: We can compute the intersection of R and S by the Datalog rule I(n,a,g,b)  R(n,a,g,b) AND S(n,a,g,b) Both subgoals true => tuple is in both R and S, hence the intersection

19 Deductive Databases Intersection: I(n,a,g,b)  R(n,a,g,b) AND S(n,a,g,b) Carrie Fishser 123 Maple St., Holl. F 9/9/99

20 Deductive Databases UNION: To take the UNION of R and S use the two rules: 1.U(n,a,g,b)  R(n,a,g,b) 2.U(n,a,g,b)  S(n,a,g,b) Rules 1 and 2 together => every tuple in R  S is in U.

21 Deductive Databases Simulating Multiple Operations with Datalog:  title, year (  length  100 (Movie)   studioName=‘Fox’ (Movie) )  title, year   length  100  studioName=‘Fox’ Movie Movie

22 Deductive Databases Simulating Multiple Operations with Datalog: 1. W(t,y,l,c,s,p)  Movie(t,y,l,c,s,p) AND l  100 2. X (t,y,l,c,s,p)  Movie(t,y,l,c,s,p) AND s=‘Fox’ 3. Y(t,y,l,c,s,p)  W(t,y,l,c,s,p) AND X (t,y,l,c,s,p) 4. Z(t,y)  Y(t,y,l,c,s,p) Z(t,y)  Movie(t,y,l,c,s,p) AND l  100 AND s=‘Fox’

23 Deductive Databases Next Lecture MORE Deductive Databases (Recursive Programming)


Download ppt "603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 26 A First Course in Database Systems."

Similar presentations


Ads by Google