CS240A: Databases and Knowledge Bases From Deductive Rules to Active Rules Carlo Zaniolo Department of Computer Science University of California, Los Angeles Revised: January 2003
From Deductive Rules to Production Rules Deductive rules for recursive views: closure(X,Y) : base(X,Y) closure(X,Y) : closure(X,Z), base(Z,Y) Active rules to materialize recursive views: Initialization step (will start the process) insert into closure (select * from base) Production rule (will call itself recursively, several times) create rule transclosure on base when inserted then insert into closure (select inserted.fr, closure.to from inserted, closure where inserted.to = closure.fr)
Maintenance Every time the database is changed recompute the concrete view, or Perform delta maintenance using techniques similar to the differential fixpoint of deductive databases Things are more complex here because you can have both additions ( + ) an subtractions ( - )
Example of Recursive View Database: Station(city, state). Train(city1, city2). Deductive rules: r1. Route(c1,c2) : Train(c1,c2). r2. Route(c1,c2) : Route(c1,c3), Route(c3,c2). r3. ReachCal(c) : Station(c,s), s = ''California'‘. r4. ReachCal(c) : Route(c,c2), ReachCal(c2).
Insert Rules: r1i. + Route(c1,c2) :- + Train(c1,c2). r2i1. + Route(c1,c2) :- + Route(c1,c3), Route(c3,c2). r2i2. + Route(c1,c2) :- Route(c1,c3), + Route(c3,c2). r3i. + ReachCal(c) :- + Station(c,s), s = ''California'' r4i1. + ReachCal(c) :- + Route(c,c1), ReachCal(c1). r4i2. + ReachCal(c) :- Route(c,c1), + ReachCal(c1).
Delete Rules Eliminate all suspect arcs r1d. - Route(c1,c2) :- - Train(c1,c2) r2d1. - Route(c1,c2) :- - Route(c1,c3), Route(c3,c2) r2d2. - Route(c1,c2) :- Route(c1,c3), - Route(c3,c2) r3d. - ReachCal(c) :- - Station(c,s), s = ''California'' r4d1. - ReachCal(c) :- - Route(c,c1), ReachCal(c1) r4d2. - ReachCal(c) :- Route(c,c1), - ReachCal(c1) NB. Train, Route, Station, ReachCal: before deletion
Reinsert rules (needed after deletion) r1r. + Route(c1,c2) : - Route(c1,c2), Train(c1,c2). r2r. + Route(c1,c2) : - Route(c1,c2), Route(c1,c3), Route(c3,c2). r3r. + ReachCal(c) : - ReachCal(c), Station(c,s), s = ''California'' r4r. + ReachCal(c) : - ReachCal(c), Route(c,c1),ReachCal(c1). Train, Route, Station, ReachCal: after deletion - restricts search in a fashion similar to magic sets.