Sie sind auf Seite 1von 6

Question 2

(, , ,, , , ) and its FD set = { , , ,


, , }.

1) Find Minimal Cover

- Firstly split up attributes which contain 2 or more on the RHS

AB->C
AB->D
E->D
ABC->D
ABC->E
E->A
E->B
D->A
D->G
ACD->B
ACD->E

- Check for attributes that contain two or more on the LHS and their closure
- Also check for redundancy

Eg. AB->C we check A Closure and B Closure


{A}+ = A, {B}+ = B
Hence we keep AB->C and AB->D

- Minimal Cover becomes


AB->C
AB->D
E->A
E->B
D->A
D->G
C,D->E

2) Decompose into a set of 3NF relations.

- Find all candidate keys


Attributes not on the RHS (must appear in candidate key) = {H}
(H)+ = {H}
(HA)+ = {H}
(same as part 1)

Continue and whichever relation has a closure which equals R+ makes it a candidate key
{ (H,E), (H,A,B), (H,B,D), (H,C,D), }

Now we see that D->G violates 3NF as its RHS is a set of non key attributes.

R1(D,G)
R2(A,B,C,D,E,H)

New FDs
AB ->E
D->A
CD->E
E->DCB

- Dependency Preserving
Dependency preserving if F+ = F+
Set of FDs we have collected = set of Fds each of which is preserve in at least one table in S

Z = AB
Intersect Z with the first sub schema
(Z UNION R1) = NULL
Therefore it is not preserved.

- Normalize to BCNF
R1(ABH)
R2(DAG)
R3(BCDE)

AB->CD violates BCNF as LHS is not a super key. So split

AB->CD
E->AB
D->AG
CD->E

(not sure how to check for depedency preserving)

- Lossless check
R(ABCDEGH)
AB->CD
E->AB
D->AG
CD->E

See if the union of these yield the original R


R(ABH) & R(DAG) & R(BCDE)

A B C D E G H
x x x
x x x
x x x x

AB -> CD since there is a distinguished AB for R2 we can add 2 as onto

A B C D E G H
R1 x x y y z t x
R2 x x x
R3 x x x x

AB->CD since AB is filled in at R1 and theres CD filled at R3 (added y)


CD->E since CD->E is all filled at R3 we can fill in E at R1 (added z)
D->AG since D->AG is all filled at R2 we can fille G at R1 (added t)

Since one row is filled there is a lossless decomposition

Question 3

Transaction 1 Transaction 2 Transaction 3


Start
Read(X)
Start
Read(Y)
Write(X)
End
Start
Read(X)
A A A
Write (Y)
End
Read(Y)
B B B
Write(Y)
Write(X)
End

1) Recovery of System
If the system crashes at B then a log based recovery should be used. Assuming a system
log is used, a log records everything a transaction does at certain points of time (t0..tx).

SQL maintains a buffer cache to read data pages, and modifications are made to a copy of a
page in the buffer. Modifications arent actually written till a checkpoint occurs. When a
modification is made, the log record is written to a disk.

Using this example:

"
If a crash occurs then we usually redo a transaction before the checkpoint occurs.

2) Crash happens at B

Since transaction 1 already ended before checkpoint A then no need to do anything to it

The crash occurs in the middle of transaction 3. Now we have to ensure the atomicity of the
transaction (ACID), and since the transaction is not completed (doesnt reach its end) we
have to roll it back to checkpoint A.
THis can be done via the log file that should be stored at checkpoint A.

3) Check if transaction is conflict serializable

- Create graph where vertexes are transactions

Cases for creating an edge between transactions (T(i) -> T(j) )


1. T(j) executes a read(X) after T(i) executes a write(X)
2. T(j) executes a write(X) after t(i) executes a read(x)
3. T(j) executes a write(x) after T(i) executes a write(X)

- Going down the table to check for conflicts


T1 Read(x) -> T3 Write(x)
createEdge(T1->T3)

T2 Read(Y) -> T3 Write


createEdge(T2->T3)

T1 Write(X) -> T3 Read(X)


Edge already there so no need to add

T1 Write(X) -> T3 Write(X)


Edge already there

T2 Write(Y) -> T3 Read (Y)


Edges from T2->T3 already there

Since the graph contains no cycles in it it is not conflict serializable.

"

4) Construct a schedule with deadlock using 2PL

Three transactions to manipulate:


T1: Read(X), Write(X)
T2: Read (Y), Write(Y)
T3: Read(X), Read(Y), Write(Y), Write(X)

- Via 2PL, you can lock and unlock operations on a certain element(X)
Transaction 1 Transaction 2 Transaction 3
Write_Lock(X)
Read(X)
Write_Lock(Y)
Read(Y)
Read(X) Write_Lock(Y)
Read(Y)
Write(Y)
Write_Lock(X)

Deadlock occurs because:


T3 locks X
T2 Locks Y
T3 waits for Lock

Das könnte Ihnen auch gefallen