Say I have a relation ABCD with FD's (A->D and AB -> ABCD)
Will a decomposed relation ABC be in BCNF? According to the second FD, AB form a key and is therefore in BCNF, but if you only look at the FD A -> D, is the relation no longer in BCNF then?
If you decompose a given relation schema (to which given dependencies apply), the next task is to determine, for each individual dependency in the original set :
(a) which (if any) of the new, decomposed, schemas does it apply to ?
(b) how has the decomposition affected the very definition of the FD ?
Question (a) applies to your original A->D dependency.
Question (b) applies, sort of, to your original AB->ABCD dependency. I say "sort of" because that version is quite "overstated". Given that A->D was already a given, it could just as well just say AB->C.
Related
Assume that the relation is obtained through decomposition from a relation with attributes ABCDEFGHI and that dependencies over ABCDEFGHI are listed below.
R(A,B,F)
B->E
A->F
We need to convert this relation into BCNF
What i have done till now is
R1(AB)
R2(AF)
R3(BE)
Is there anything more I should do? Is this proper BCNF or am I missing something?
This answer follows from the edited question, under the following hypotheses:
the original relation is R(ABCDEFGHI)
a cover of the functional dependencies holding on it is {B->E, A->F}
Of course if my hypotheses are wrong the answer is wrong!
In this case:
the only candidate key of the original relation is ABCDGHI;
in the decomposed relation R1(ABF) the only non-trivial dependency that holds is A -> F, so the relation has the only candidate key AB;
the relation is not in BCNF, and a decomposition in BCNF is {R2(AF), R3(AB)}
Note that you cannot decompose a relation adding an extraneous attribute, like E in your decomposition.
The entire question is:
The relation R(A, B, C, D, E) with F = {A→B ; A→C ; B,D→A} is decomposed considering the functional dependency A→B from the beginning.
What is the functional dependency that cannot be preserved by such a decomposition?
It seems to me that I have insufficient data to answer this question. Firstly, doesn't knowing which FD cannot be preserved depend on the normal form we are using? Secondly, the decomposition is unfinished; doesn't the preservation depend on which decomposition we use?
The question is certainly poorly phrased. Presumably F is supposed to be a cover for the FDs that hold in R--ie the FDs that hold in R are the ones implied by the ones in F. It's not clear what is meant by "decomposed considering the functional dependency A → B from the beginning". We would reasonably say that "decomposing considering a FD" means decomposing introducing a component with the FD's attributes. I suspect that they are trying to say, if you binary decompose to component AB plus some other component(s) then what FD "cannot be preserved by such a decomposition"?
When we losslessly decompose we really mean we are only interested in decompositions where all the components are smaller than the original & no component is a subset of another. So in a decomposition having component AB the other components would join to either ACDE or BCDE.
Look at the remaining given FDs: A → C & B, D → A. For each of those projections/components, if it were losslessly joinable with AB then the FDs that are implied by those per Armstrong's axioms & that have all their attributes in it will hold in it. (And no others will hold in it.) But there's one of those two FDs that can't hold in either of the two projections. So that's the one that "cannot be preserved by such a decomposition".
Firstly, doesn't knowing which FD cannot be preserved depend on the normal form we are using?
They seem to be trying to ask about a decomposition of a certain nature, so the resulting NFs don't matter.
Secondly, the decomposition is unfinished; doesn't the preservation depend on which decomposition we use?
They are telling you that a certain FD "cannot be preserved by such a decomposition". So we can expect that as long as we have "such a decomposition" the answer doesn't further "depend on which decomposition we use".
(Note that a decomposition to 2NF or 3NF can fail to preserve FDs. But there's always a decomposition that doesn't fail.)
So I have this set of relation
AB->CDEF
G->H,I
ABJ->K
C->L
How should I decompose this? I am so confused. Am I supposed to find the set of super key first?
We can first convert the relation R to 3NF and then to BCNF.
To convert a relation R and a set of functional dependencies(FD's) into 3NF you can use Bernstein's Synthesis. To apply Bernstein's Synthesis -
First we make sure the given set of FD's is a minimal cover
Second we take each FD and make it its own sub-schema.
Third we try to combine those sub-schemas
For example in your case:
R = {A,B,C,D,E,F,G,H,I,J,K,L}
FD's = {AB->CDEF,G->HI,ABJ->K,C->L}
First we check whether the FD's is a minimal cover (singleton right-hand side , no extraneous left-hand side attribute, no redundant FD)
Singleton RHS: We write the FD's with singleton RHS. So now we have FD's as {AB->C, AB->D, AB->E, AB->F, G->H, G->I, ABJ->K, C->L}
No extraneous LHS attribute: We remove the extraneous LHS attribute if any. There are no extraneous LHS attributes here.
No redundant FD's: We remove the redundant dependencies if any. Now FD's are {AB->C, AB->D, AB->E, AB->F, G->H, G->I, ABJ->K, C->L}
Second we make each FD its own sub-schema. So now we have - (the keys for each relation are in bold)
R1={A,B,C}
R2={A,B,D}
R3={A,B,E}
R4={A,B,F}
R5={G,H}
R6={G,I}
R7={A,B,J,K}
R8={C,L}
Third we combine all sub-schemas with the same LHS. So now we have -
S1 = {A,B,C,D,E,F}
S2 = {G,H,I}
S3 = {A,B,J,K}
S4 = {C,L}
Since none of the above decomposed relations contain contain a key of R, we need to create an additional relation schema that contains attributes that form of a key of R. This is to ensure lossless join decomposition that preserves dependencies. So we add -
S5 = {A,B,G,J}
ABGJ is the key of the original relation R
This is in 3NF. Now to check for BCNF we check if any of these relations (S1,S2,S3,S4,S5) violate the conditions of BCNF (i.e. for every functional dependency X->Y the left hand side (X) has to be a superkey) . In this case none of these violate BCNF and hence it is also decomposed to BCNF.
Note - The importance of some of these steps may not be clear in this example. Have a look at other examples here and here.
Hey all I have an assignment that says:
Let R(ABCD) be a relation with functional dependencies
A → B, C → D, AD → C, BC → A
Which of the following is a lossless-join decomposition of R into Boyce-Codd Normal Form (BCNF)?
I have been researching and watching videos on youtube and I cannot seem to find how to start this. I think I'm supposed to break it down to subschemas and then fill out a table to find which one is lossless, but I'm having trouble getting started with that. Any help would be appreciated!
Your question
Which of the following is a lossless-join decomposition of R into
Boyce-Codd Normal Form (BCNF)?
suggests that you have a set of options and you have to choose which one of those is a lossless decomposition but since you have not mentioned the options I would first (PART A) decompose the relation into BCNF ( first to 3NF then BCNF ) and then (PART B) illustrate how to check whether this given decomposition is a lossless-join decomposition or not. If you are just interested in knowing how to check whether a given BCNF decomposition is lossless or not jump directly to PART B of my answer.
PART A
To convert a relation R and a set of functional dependencies(FD's) into 3NF you can use Bernstein's Synthesis. To apply Bernstein's Synthesis -
First we make sure the given set of FD's is a minimal cover
Second we take each FD and make it its own sub-schema.
Third we try to combine those sub-schemas
For example in your case:
R = {A,B,C,D}
FD's = {A->B,C->D,AD->C,BC->A}
First we check whether the FD's is a minimal cover (singleton right-hand side , no extraneous left-hand side attribute, no redundant FD)
Singleton RHS: All the given FD's already have singleton RHS.
No extraneous LHS attribute: None of the FD's have extraneous LHS attribute that needs to e removed.
No redundant FD's: There is no redundant FD.
Hence the given set of FD's is already a minimal cover.
Second we make each FD its own sub-schema. So now we have - (the keys for each relation are in bold)
R1={A,D,C}
R2={B,C,A}
R3={C,D}
R4={A,B}
Third we see if any of the sub-schemas can be combined. We see that R1 and R2 already have all the attributes of R and hence R3 and R4 can be omitted. So now we have -
S1 = {A,D,C}
S2 = {B,C,A}
This is in 3NF. Now to check for BCNF we check if any of these relations (S1,S2) violate the conditions of BCNF (i.e. for every functional dependency X->Y the left hand side (X) has to be a superkey) . In this case none of these violate BCNF and hence it is also decomposed to BCNF.
PART B
When you apply Bernstein Synthesis as above to decompose R the decomposition is always dependency preserving. Now the question is, is the decomposition lossless? To check that we can follow the following method :
Create a table as shown in figure 1, with number of rows equal to the number of decomposed relations and number of column equal to the number of attributes in our original given R.
We put a in all the attributes that our present in the respective decomposed relation as in figure 1. Now we go through all the FD's {C->D,A->B,AD->C,BC->A} one by one and add a whenever possible. For example, first FD is C->D. Since both the rows in column C has a and there is an empty slot in second row of column D we put a a there as shown in the right part of the image. We stop as soon as one of the rows is completely filled with a which indicates that it is a lossless decomposition. If we go through all the FD's and none of the rows of our table get completely filled with a then it is a lossy decomposition.
Also, note if it is a lossy decomposition we can always make it lossless by adding one more relation to our set of decomposed relations consisting of all attributes of the primary key.
I suggest you see this video for more examples of this method. Also other way to check for lossless join decomposition which involves relational algebra.
I'm trying to produce a 3NF and BCNF decomposition of a schema. I have been looking at the algorithms but I am very confused at how to do this.
If I have my minimal cover say: F' = {A->F, A->G, CF->A, BG->C) and I have identified one candidate key for the relation, say it is A. Then what exactly do I do?
I have been looking at examples, one which has the following:
F = {A → AB,A → AC,A → B,A → C,B → BC}
Minimal cover: F′ = {A → B,B → C}
And the final result was: (AB,A → B), (BC,B → C). How did they get to this?
If I have my minimal cover say: F' = {A->F, A->G, CF->A, BG->C) and I
have identified one candidate key for the relation, say it is A. Then
what exactly do I do?
F' is not a minimal cover: you have to combine A->F and A->G to A->FG
Even worth A cannot be a candidate key given F' since B does not belong yo the closure of A. A possible candidate key would be AB.
For 3NF you start with creating tables for each one of the dependencies in F', i.e.,
R1(A,F,G) R2(A,C,F) R3(B,C,G)
Next you check whether one of the tables contains a candidate key. Since B appears only on the left side of the dependencies, B should always be a part of a candidate key. The only table with B is R3 and it does not contain candidate keys (check it!). Hence, we add a new table R4 with a candidate key as attributes
R4(A,B)
Finally, we check whether the set of attributes of one of the tables is contained in the set of attributes of another table. This is not the case for our running example.
Hence, our 3NF decomposition is
R1(A,F,G) R2(A,C,F) R3(B,C,G) R4(A,B)
For BCNF you start with R(A,B,C,F,G) and look for BCNF violations.
For instance A->FG is a violation of BCNF because this dependency is not trivial and A is not a superkey. Hence we split R into
R1(A,F,G) and R2(A,B,C)
None of the relations obtained contains BCNF violations, so the process stops here.