Download presentation
Presentation is loading. Please wait.
1
CS240A: Databases and Knowledge Bases From Deductive Rules to Active Rules Carlo Zaniolo Department of Computer Science University of California, Los Angeles WINTER 2002
2
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 ( - )
3
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).
4
Insert Rules: r1i. + Route(c1,c2) :- + Train(c1,c2). r2i1. + Route(c1,c2) :- + Route(c1,c3), Route(c3,c1). 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).
5
Delete Rules Eliminate all suspect arcs r1d. - Route(c1,c2) :- - Train(c1,c2) r2d1. - Route(c1,c2) :- - Route(c1,c3), OLD_Route(c3,c2) r2d2. - Route(c1,c2) :- OLD_Route(c1,c3), - Route(c3,c2) r3d. - ReachCal(c) :- - Station(c,s), s = ''California'' r4d1. - ReachCal(c) :- - Route(c,c1), OLD_ReachCal(c1) r4d2. - ReachCal(c) :- OLD_Route(c,c1), - ReachCal(c1)
6
Reinsert rules 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).
7
From Deductive Rules to Production Rules-- Revisited Deductive rules for transitive closure of base(fr, to): closure(X,Y) : base(X,Y) closure(X,Y) : closure(X,Z), base(Z,Y). + closure(X,Y) : + base(X,Y). + closure(X,Y) : + closure(X,Z), base(Z,Y). + closure(X,Y) : closure(X,Z), + base(Z,Y). Can we turn these into production rules? insert into closure (select * from base) Production rule create rule transclosure on closure when inserted then insert into closure (select inserted.fr, closure.to from inserted, closure where inserted.to = closure.fr) There is a problem with this rule—what is it?
8
Computing Transitive Closure with the Delta Rules Deductive rules for transitive closure of base(fr, to): closure(X,Y) : base(X,Y) closure(X,Y) : closure(X,Z), closure(Z,Y). + closure(X,Y) : + base(X,Y) + closure(X,Y) : + closure(X,Z), closure(Z,Y). + closure(X,Y) : closure(X,Z), + closure(Z,Y). We can emulate the first rule by taking each tuple in base and adding to closure(fr, to): insert into closure (select * from base) Production rule create rule transclosure on closurewhen inserted then insert into closure (select inserted.fr, closure.to from inserted, closure where inserted.to = closure.fr) UNION (select closure.fr, inserted.to where closure.to = inserted.fr)
9
Positive Delta Maintenance We now need a rule to perform to start the updating of closure every time we add to base: create rule deltaplus on base when inserted then insert into closure select * from inserted More problems: you must also check that the tuple is not already in closure.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.