60 likes | 178 Views
View Processing & Update. View Processing. create view PresSuite as select * from Room where NrBeds = 2. select * from PresSuite p natural join Reservation s where Cost > 85 and ArrivalDate = “10 May”. = select * from (select * from Room where NrBeds = 2) p natural join Reservation s
E N D
View Processing create view PresSuite as select * from Room where NrBeds = 2 select * from PresSuite p natural join Reservation s where Cost > 85 and ArrivalDate = “10 May” = select * from (select * from Room where NrBeds = 2) p natural join Reservation s where Cost > 85 and ArrivalDate = “10 May”
View Processing & Optimization Create view p: NrBeds = 2 r Query with view: Cost > 85 ArrivalDate = “10 May” (p |×| s) Substitute view: Cost > 85 ArrivalDate = “10 May” ((NrBeds = 2 r) |×| s) Optimize: NrBeds = 2 Cost > 85 r |×| ArrivalDate = “10 May” s
The View-Update Problem • Q is the query that defines view V based on database D. • U is the update specification. • V is the updated view. • T is the translator for U, i.e., the actual update applied to D. • D is the updated database. T D D Q Q U V V Problem: there may be more than one translator T for a given update specification U.
View-Update Problem – Example Base Relations: r = Guest Room s = Room RmView G1 R1 R1 Sea R2 City View: create view WindowView as select Guest, RmView from r natural join s Guest RmView G1 Sea View Update: update WindowView set RmView = ‘City’ where Guest = ‘G1’ Two Translations (ambiguous): update r set Room = “R2” where Guest = “G1” update s set View = “City” where Room = “R1”
Updatable Views When appropriately restricted, view updates work. Often overly restricted: typically to just and on a single table. create view PresSuite as select * from Room where NrBeds = 2 Then: update PresSuite set Name = “Clinton” where Name = “Nixon” delete from PresSuite where Name = “Kennedy” insert into PresSuite values (6, “Bush”, 2, 100)