Rock Hymas Database Systems Final 1.a create table User( uid int primary key, uname varchar(50), ); create table Group( gid int primary key, gname varchar(50), ); create table Member( uid int references User(uid), gid int references Group(gid), primary key (uid, gid) ); create table Object( oid int primary key, oname varchar(50), ); create table AccessGranted( gid int references Group(gid), oid int references Object(oid), primary key (gid, oid) ); create table AccessDenied( uid int references User(uid), oid int references Object(oid), primary key (uid, oid) ); create table AccessLog( uid int references User(uid), oid int references Object(oid), t int, primary key (uid, oid, t) ); 1.b select timestamps.t as timestamp, count(distinct l.oid) as accessedobjects from (select distinct t from AccessLog) as timestamps, AccessLog l where l.t >= timestamps.t and l.t < (timestamps.t + 10) group by timestamps.t 1.c select l.uid, l.oid, l.t from AccessLog l, AccessDenied d, Member m where (l.uid = d.uid and l.oid = d.oid) or (l.uid = m.uid and m.gid NOT IN (select g.gid from AccessGranted g where g.oid = l.oid)) 1.d select g.gid, g.gname from Group g where NOT EXISTS (select m.uid from Member m, AccessGranted ag where m.gid = g.gid and ag.gid = g.gid and m.uid NOT IN (select ad.uid from AccessDenied ad where ad.oid = ag.oid)) 2.a V_1(A,B,C,D,E) A->BC; B->D; D->BE V_2(D,E,F,G,H) D->E; F->GH, E->G V_3(F,G,H) F->GH V_4(A,B) A->B V_5(H,K) H->K 2.b R(ABCDEF) Choose X=BC X=BC, X+=ABC, Y=A, Z=DEF Decompose into R1(ABC) and R2(BCDEF) Choose X=EF in R2 X=EF, X+=EFB, Y=B, Z=CD Decompose into R3(EFB) and R4(EFCD) The decomposition of R into R1, R3, and R4 is in BCNF 2.c Option 1: Migrate the data to a new database schema with a Customer table (customerID, customerName, customerAddress) and an Orders table (orderID, customerId, milkQuantity, date). The immediate costs include migration of the data. All existing rows in the database would need a unique identifier to indicate the order number. Then the customers table could be created by using the latest name and address associated with a customer id. Some manual work might be needed to resolve errors in the data that might have creeped in due to the lack of constraints on the old database (e.g. a single customer may have multiple ids, names, or addresses). Once that is done the Orders table would be fairly simple to construct. Option 2: Migrate the data to a new database schema with a Customer table (customerID, customerName), and Address table (addressID, customerID, customerAddress), and an Order table (orderID, customerID, addressID, milkQuantity, date). This would take car of the most likely discrepancy in the data, that of a customer having multiple addresses, e.g. they moved. The upfront work would be roughly the same, though addresses would need to be assigned IDs also. This would allow greater flexibility in the web app, such as allowing a customer to change their address. 3.a.1 It is conflict serializable, but not recoverable. If transaction 1 aborted instead of commiting, we would need to abort transaction 2, because it read A, which transaction 1 wrote, but we can't do that because it has already commited. 3.a.2 It is conflict serializable, recoverable, but does not avoid cascading aborts. If transaction 1 were to abort instead of commiting, then we need to abort transaction 2 because it reads A, which transaction 1 wrote. Then we also need to abort transaction 3 because it reads B, which transaction 2 wrote. 3.a.3 Not conflict serializable, precedence graph has the following edges: T1-A-T2-BT3-D-T1 3.a.4 Conflict serializable 3.b.i Conflict serializable but not necessarily recoverable 3.b.ii Conflict serializable, recoverable, and avoids cascading aborts 3.b.iii Conflict serializable, recoverable, and avoids cascading aborts 3.b.vi Conflict serializable, recoverable, does not necessarily avoid cascading aborts 3.c.i False, it may contain pages that were not dirty at the moment of the crash 3.c.ii During the REDO phase 4.a B(R) = 1000 4.b 2 + B(R) / V(R,A) = 52 4.c T(R) / 250 = 40 5.a 5.b.i 5.b.ii 5.b.iii 5.b.vi COST(s1j1) COST(s2j1) COST(s1j2) COST(s2j2) = = = = B(R) B(R) B(R) B(R) + + + + B(S) = 105 B(S) + T(R)/V(R,A) = 125 T(R)B(S)/V(S,C) = 405 T(R)B(S)/V(S,C) + T(R)/V(R,A) = 425 5.c P1 is equivalent to P P2 is not equivalent to P P3 is equivalent to P 5.d.i 5.d.ii 4 6.a /doc/movie[actor/name = "Bacon"]/title 6.b /doc/movie[actor/name="Subrahmanian" and actor/gender][1]/actor[name="Subrahmanian"]/gender 6.c <doc> { for $d in /doc/ let $actors := distinct-values($d/movie/actor/name/text()) return { for $actor in $actors return <actor> <name>$actor</name> {$d/movie[actor/name=$actor and actor/gender][1]/actor[name=$actor]/gender} { for $m in /doc/movie[actor/name = $a] let $title := $m/title, $year := $m/year return <movie> $title $year </movie> } </actor> } } </doc>