I have R(A,B,C,D) and functional dependencies AB->CD and A->B I want to know or A->C is correct?
I try found F closure by amstrong axioms:
AB->C (decomposition from AB->CD)
AB->D (decomposition from AB->CD)
AB->AB (reflexivity)
AB->A (decomposition from AB->AB)
AB->B (decomposition from AB->AB)
A->A
B->B
AB->ABCD (Union) <- candidate key
I feel it is not all what I missing? Also I feel that A->C is correct because AB->C but I am not sure.
You have two different ways to see if A → C can be derived by AB → CD and A → B: either you can try to calculate the closure of the attribute A, with the algorithm used to compute the closure of a set of attributes, and see if it contains C (easy way), or you can derive a proof of it by applying the Armstrong axioms (more difficult way).
Let’s first do it the easy way:
A+ = A (starting point)
A+ = AB (by using A → B)
A+ = ABCD (by using AB → CD)
So, since A+ contains C, we have shown that A → C belongs to F+, which is equivalent to say that A → C is implied by AB → CD and A → B.
Now let’s try the second way:
1. A → B (given)
2. AB → CD (given)
3. A → AB (by 1. for enrichment, adding A both to left and right side of the dependency)
4. A → CD (by 3. and 2. for transitivity)
5. A → C (by 4. for decomposition)
What you will probably do not want to do, on the other hand, is to compute the closure of F, since this would be quite a lengthy and tedious task... (it is an exponential task!).
AB->CD (given)
thus,
AB->C, and
AB->D
(by decomposition)
A->B (given)
So, A->AB, by augmentation
thus, by transitivity, A->C & A->D!
Related
According to the Curry-Howard correspondence the sum-type aka tagged-union is the equivalent of disjunction, logical OR
Why is this the case? Is it not closer to XOR? (a or b) implies that it could be a or b or both, whereas Either a b must be a or b but never both.
Curry-Howard correspondence says that an element of Either a b represents a proof of a or b. To prove a disjunction it's enough to prove (provide an element of) a or b. You do this by constructing Either a b using either Left a or Right b.
It seems to me that Bernstein's synthesis / 3NF synthesis always yields BCNF subrelations, but that's apparently not true.
When one uses 3NF synthesis, one will have subrelations as a result, and they will each consist of either:
just one functional dependency along with all attributes of the schema, so the left side of the lone functional dependency will be a superkey, and that subrelation will therefore be in BCNF.
multiple functional dependencies each of which have the same left side, so they're each superkeys, and that subrelation will therefore be in BCNF.
no functional dependency where the schema includes the attributes making up the primary key of the original / non-decomposed relation, which would satisfy BCNF vacuously because of there being no functional dependencies.
What is an example of the 3NF synthesis algorithm yielding a non-BCNF decomposition and why it is so?
Bernstein's algorithm returns (one or more) components in EKNF, which lies between 3NF & BCNF.
Your claims of "that subrelation will therefore be in BCNF" are wrong. The FDs that hold in a component are all the ones in the closure of the original relation whose attributes are all in the component. So FDs could hold in a component that are not out of its superkeys. (Which by definition of BCNF is just another way of saying a component could be not in BCNF. Obviously--since we are told that the algorithm doesn't always give BCNF.)
Since your reasoning is unsound, finding a counterexample seems moot. But just about any presentation of BCNF gives an example non-BCNF 3NF relation, which it then decomposes to BCNF. You can join the non-BCNF 3NF relation with a projection on attributes of one of its CKs extended by a fresh non-prime attribute, and Bernstein's algorithm can decompose back to the 2 tables.
Chris Date's classic An Introduction to Database Systems has a non-BCNF 3NF schema R(S, J, T) with minimal/irreducible cover
{S, J} -> T
{T} -> J
CKs are {S, J} & {T, J}. Berstein gives component (S, J, T)--non-BCNF 3NF input R--in which both given FDs hold--plus redundant component (T, J).
For an example with an additional non-redundant component, extend the cover by {T} -> X. CKs are the same. {S, J} -> T again gives (S, J, T)--non-BCNF--plus component (T, J, X).
So, could someone please give me an example of the 3NF synthesis algorithm yielding a non-BCNF decomposition and tell why it is so?
A better "So, [...]" would be, So, what is wrong with my reasoning? You would do well to examine the assumptions you made about what FDs could hold in a component. (That article happens to point out (with reference) that "A 3NF table that does not have multiple overlapping candidate keys is guaranteed to be in BCNF.")
There is no "why" in mathematics. We assume things ("assumptions", "axioms", "premises") & other things follow. We can ask for a proof of something, but the proof does not say "why" the something is so, it's a demonstration that it is so. "Why" might be used trying to ask for a proof or for steps that you got wrong in or are missing from whatever almost-proof you have in mind.
PS Such a ubiquitous non-BCNF 3NF relation is Today's Court Bookings in the Wikipedia article on BCNF as I write. But beware that that particular example has perhaps unintuitive FDs. Indeed beware that almost every relational model Wikipedia page--including that one--has errors & misconceptions. So do many, many textbooks, especially re normalization.
The answer of philipxy is correct. Since you are asking for an example, here there are a couple of them.
The relation (with a cover of the functional dependencies):
R (A B C D)
A B → C
C → D
D → B
through the synthesis algorithm is decomposed in:
R1 (A B C)
R2 (C D)
R3 (B D)
and R1 is not in BCNF for the dependency C → B (the candidate key is AB). Note that C → B is not present in the original cover, but is a dependency implied from it.
Here is another (classical) example:
Phones (AreaCode, PhoneNumber, Subscriber, Town, Street)
AreaCode, PhoneNumber → Town
AreaCode, PhoneNumber → Subscriber
AreaCode, PhoneNumber → Street
Town → AreaCode
The Bernsteins’s synthesis algorithm produces two subschemas:
R1 (AreaCode, PhoneNumber, Subscriber, Town, Street)
AreaCode, PhoneNumber → Town
AreaCode, PhoneNumber → Subscriber
AreaCode, PhoneNumber → Street
and:
R2 (Town, AreaCode)
Town → AreaCode
since R2 is included in R1, the algorithm eliminates the second relation. The resulting relation is in 3NF but not in BCNF, since the relation has two candidate keys, (AreaCode, PhoneNumber) and (PhoneNumber, Town) and the functional dependency Town → AreaCode violates the BCNF.
R (A B C)
AB -> C,
C -> A
AB is the minimal super key which is a candidate key.
AB -> C is good.
But C -> A doesn't hold good since prime attribute depends on Non Prime attribute. I know how to decompose till 3 NF. I also know why relation is not in BCNF.
But I don't know how to break this relation into BCNF. How can I do that?
This relation can be decomposed in BCNF using for instance the analysis algorithm, which produces the following decomposition:
R1(A, C) (with non trivial dependency C → A and candidate key C)
R2(B, C) (without non trivial dependencies and so with candidate key (B, C))
But this decomposition does not preserve the dependencies: in fact, the dependency A B → C is lost. So, with such decomposition, the constraint due to this dependency cannot be simply enforced on the decomposed relations. And no other decomposition in BCNF can be produced such that the dependencies are maintained. We can note also that the relation is already in 3NF.
I am struggling with Carnonical Cover, Dependency Preservation and Lossless Decomposition.
Are the approach and thoughts here correct?
R(ABCDEFG)
Provided is the following set of dependencies after a canonical cover has been made. I did not do the canonical cover myself but the assignment said I had to assume it had been done.
Fc:
A -> C
E -> A
C -> ABF
F -> CDG
A+ = ABCDFG
E+ = ABCDEFG
C+ = ABCDFG
F+ = ABCDFG
E = Candidate Key.
This list of functional dependencies is in 2NF since there are no partial dependencies. It is however not in 3NF since there are transitive dependencies.
However decomposing into the following 4 relations will result in it being not only in 3NF but also BCNF
R1 = {E,A}
E -> A
R2 = {A, C}
A -> C
R3 = {CABF}
C -> ABF
R4 = {FCDG}
F -> CDG
I use A in R1 as a foreign key to R2 and C in R2 as a foreign key to R3 etc.
There are no transitive dependencies and since all left hand sides are candidate keys in their respective relations it is in BCNF.
Is also lossless and dependency preserving?
What is decomposed
In the title you say:
What is the correct approach when decomposing dependencies
but one does not decompose dependencies, but relation schemas. So, in this case, here there is a relation schema R(ABCDEFG) with a set of functional dependencies and one must decompose that schema.
What is a decomposition
A decomposition produces a set of relation schemas with the following properties: a) every attribute of the original schema is present in some (possibly more than one) subschema; b) no other attributes are present. Moreover, a decomposition is redundant when a relation subschema is contained in another. In your case, this is true for R2, which is contained in R3: there is no need to have both relations, since it would imply unuseful data redundancy.
What is a good decomposition
To be really useful, a decomposition should satisfy two important properties: preserve functional dependencies and preserve data (lossless decomposition). But another property characterizes a good decomposition: it should be as small as possible: there is no point in decomposing a schema in too many subschemas, since this would produce a non natural and complex database.
Actually your decomposition is lossless and preserves the dependencies.
How to decompose
The final objective of all this stuff is to produce a decomposisition (lossless and dependency preserving) in which the subschemas are in BCNF or 3NF. The simple solution of decomposing by using the attributes of the functional dependencies is not, however, a good solution. For this, there are algorithms, described in textbooks, that produces decompositions either for BCNF or for 3NF (the so-called “analysis” algorithm for BCNF, and “synthesis” algorithm for 3NF), trying to produce not too many subschemas. For instance, the “analysis” algorithm in this case produce the following decomposition in BCNF, with only two subschemas:
R1 < (A B C D F G) ,
{ F → C
F → D
F → G
C → A
C → B
C → F
A → C } >
R2 < (A E) ,
{ E → A } >
This decomposition is lossless and preserves the dependencies (which is not always true for the analysis algorithm).
I have a problem breaking this into BCNF:
Relation: R[A E P M N S T L]
FD's:
A -> EM,
A -> L,
M -> ST,
M -> N,
S -> T,
E -> P,
P -> E,
L -> A
This one was on one of my past exams, and I don't really know how to solve it.
I learned this on coursera by the woman (Jennifer Widom) who wrote our course literature:
-------------- BCNF ALGORITHM ------------
1. Take a FD that violates BCNF.
2. Decompose the FD to two other relations
3. First relation: The whole FD
4. Second relation: The rest of the Relation + the left hand side of the chosen FD
5. Iterate until all the new relations have key on its left hand side
-------------- BCNF ALGORITHM ------------
And I also tried another one that is basically the same, but written in a different way:
X->Y: R1({X}+), R2(R - {X}+ ; X) (Relation minus {X}+ (XY in this case), plus X.
So far, I'm here:
Obviously, A is key, so its FDs are already in BCNF. Question is, can I erase any redundant FDs maybe? If so, what is the thumb rule?
R1(MST) <-- BCNF.
R2(A E P M N L)
R3()
And have no idea where to go.
1. Take a FD that violates BCNF.
5. Iterate until all the new relations have key on its left hand side
Step 1 in mentioning BCNF violation can only make sense if it means you should identify the keys and non-key-implied FDs of each original and generated relation. Also, step 5 termination cannot be merely when there is a key on the left hand side, because a non-key determiner could be present. Clearly it is necessary and sufficient to stop when all relations are in BCNF. A particular full description of an algorithm may describe equivalent reorganizations and/or tests without explicitly mentioning BCNF.
If A is a key then so is L since L->A.
MSTNAELP keys A and L plus M->ST, S->T, E<->P
Those FDs are from non-keys. You picked M->ST. We get:
MST key M plus S->T
MNAELP keys A and L plus E<->P
Both have determiners not from keys, hence are not in BCNF. Pick S->T and E->P. We get:
ST key S in BCNF
SM key M in BCNF
EP keys P and E in BCNF
EMNAL keys A and L in BCNF