Consider a relation schema R(A,B,C,D,E) and the set of functional dependencies
F={A→BC,CD→E,B→D,E→A}
Find all candidate keys (minimal keys) of relation R. Show all the steps you took to derive each key, and clearly state which of Armstrong’s axioms are used in each step.
Closure of A
A→BC means A+={A,B,C}(Decomposition)
B→D means A+={A,B,C,D}(Transitivity)
CD→E means A+={A,B,C,D,E}(Transitivity) (CD∈A)
A is a candidate key
Closure of B
B+={B}
B→D means B+={B,D}
No other closure can be applied thus B is not a key
Closure of C
We can’t derive all attributes, thus C is not a key
Closure of D
No applicable dependencies, thus D is not a key
Closure of E
E→A means E+={E,A}(FD)
A→BC means E+={E,A,B,C}Decomposition and Transitivity
B→D means E+={E,A,B,C,D}Transitivity
E is a candidate key
Closure of CD
Initial CD gives (CD)+={C,D}
CD→E gives (CD)+={C,D,E}FD
E→A gives (CD)+={C,D,E,A}Transitivity
A→BC gives (CD)+={C,D,E,A,B,C}Transitivity and Decomposition
CD is a candidate key
Closure of BC
Initial BC gives (BC)+={B,C}
B→D gives (BC)+={B,C,D}FD
CD→E gives (BC)+={B,C,D,E}Transitivity
E→A gives (BC)+={B,C,D,E,A}Transitivity
BC is a candidate key
conclusion
Final candidate keys are A,E,CD,BC
b
Is the FD AB→C entailed by F? Show your work that supports your answer
We will find closure of AB under F
(AB)+={A,B}
A→BC entails A→B and A→C (Decomposition)
with augmentation on A→C we have AB→CB
Decomposition to AB→CB gets AB→C
Therefore AB→C is entailed by F
Minimal Cover
Question
Given the relational schema T(A,B,C,D) and the FDs: F{ABC→D,CD→A,CA→B,AD→C,CD→B}, compute the minimal cover F′ of F. Show all your work (derivation) to compute F′
We have the following FD
ABCCDCAADCD→D→A→B→C→B
RHS of FDs into single attributes
Already in this form
minimize LHS by removing extraneous
FD1: ABC→D
B is extraneous given that AC→D holds:
(AC)+={A,C}
CA→B then add B to closure
ABC→D then add D to closure
Update FD1: AC→D
FD2: CD→A
no FD is applied is either C or D is assume extraneous, therefore remained unchanged
FD3: CA→B
can’t reduce CA→B given that neither C→B and A→B holds
FD4: AD→C
can’t reduce AD→C given that neither A→C and D→C holds
FD5: CD→B
can’t reduce CD→B given that neither C→B and D→B holds
Remove redudant FDs
FD5: CD→B
Can be calculated from CD→A and CA→B:
Closure of CD is (CD)+={C,D}, CD→A gives {C,D,A} and CD→B gives {C,D,A,B}
thus this is redudant
Final minimal cover is
F′={AC→D,CD→A,CA→B,AD→C}
Armstrong’s Axioms
a
Given the relational schema R(A,B,C,D,E,F) and FDs F1:{AB→C,A→D,CD→EF}. Show that AB→F
AABABABABAB→D→DB→D∪AB→B→CD→EF→F∵(Given)(Augmentation w/B)Decomposition)(Union with 2 and AB→C)(Transitivity with 3 and CD→EF)(Decomposition)
b
Given the relational schema R(A,B,C,D,E,F) and FDs F1:{C→D,BE→A,BEF→C}. Show that BEF is a key
Proof: BEF+={A,B,C,D,E,F} and BEF is minimal
Proving closure of BEF
We have BEF+={B,E,F}
BEF→C and BEF∈BEF+ by reflexivity, we add C to the closure BEF+={B,E,F,C}
C→D and with Transitivity of BEF→C gives BEF→D. Add D to closure BEF+={B,E,F,C,D}
BE→A thus add A to the closure BEF+={B,E,F,C,D,A}
Therefore by union we have prove closure of BEF
minimal of BEF
Case 1: Remove B from BEF:
Compute EF+, and there is no FD to prove this transition, therefore EF does not determine all attributes
Case 2: Remove E from BEF:
Compute BF+, and there is no FD to prove this transition, therefore EF does not determine all attributes
Case 3. remove F from BEF:
Closure of BE is BE+={B,E}
BE→A means BE+={B,E,A}
No further can be added
Therefore BEF is minimal
BEF is a key
3NF, BCNF
1
List all functional dependencies and keys that can be inferred from this information
Note that for both Company and City tables, it satisifies BCNF. however, for Department table:
For FD3, deptID is a candidate key, thus satisfies BCNF
For FD4, companyID, depthName is a candidate key, thus satisfies BCNF
But for FD5 given that deptMgrID is not a candidate key, thus violate BCNF
Improvement
Create a new table DeptManager deptMgrID, deptID with decomposition
remove deptMgrID from the original table (now deptName, companyID, cityName, country)
Thus should satisfy BCNF
Transactions and Concurrency
Schedules
Consider schedules S1,S2,S3 State which of the following properties holds (or not) for each schedule: strict, avoid cascading aborts, recoverability. Provide brief justification for each answer
strict: no, because T2 writes to Y after it has been modified by uncommitted T3
avoid cascading aborts: yes, because all reads are from initial state, not from uncommitted transaction
recoverability: yes, because T2 is committed after T3
Serialisability
Which of the following schedules is (conflict) serializable? For each serializable schedule, find the equivalent serial schedules.
a
r1(X); r3(X); w1(X); r2(X); w3(X)
r1(X)→w3(X)r3(X)→w1(X)w1(X)→r2(X)w1(X)→w3(X)r2(X)→w3(X):T1 reads X before T3 writes it⟹T1→T3:T3 reads X before T1 writes it⟹T3→T1:T1 writes X before T2 reads it⟹T1→T2:T1 writes X before T3 writes it⟹T1→T3:T2 reads X before T3 writes it⟹T2→T3
The precedence graph contains a cycle between T1 and T3, thus this is not conflict serializable
b
r3(X); r2(X); w3(X); r1(X); w1(X)
Note that there are no conflict between T2 and other nodes given that it only read
This is conflict serializable with the following equivalent serial schedules:
T3→T1→T2T3→T2→T1
Locking
Question
Consider the following locking protocol:
Before a transaction T writes a data object A, T has to obtain an exclusive lock on A.
For a transaction T, we hold these exclusive locks until the end of the transaction.
If a transaction T reads a data object A, no lock on A is obtained.
State which of the following properties are ensured by this locking protocol: serializability, conflict-serializability, recoverability, avoids cascading aborts, avoids deadlock.
Explain and justify your answer for each property.
serializability
Not ensured given that reads aren’t controlled by locks, therefore two transaction can read the same data item and write to in different order (example: r1(X); r2(X); w2(X); w1(X))
conflict-serializability
Not ensured, same reason as above
recoverability
not ensured given that if a transaction Tj reads data written by Ti, then Tj should commit only after Ti commit. however, in this protocol, transaction can read uncommitted data, given that read is not locked (dirty read.)
avoid cascading aborts
not ensured given that dirty read can happen (example: w1(X); r2(X). In this case if T1 aborts, T2 will need to aboart, causing cascade aborts)
avoid deadlock
ensured, given that each transaction have to obtain exclusive lock on A, as transactions can’t wait for each other in a scycle since reads don’t require locks.