Multivalued dependency confusion - database

I am struggling with the concepts of 4NF and Multivalued Dependencies (MVDs).
I am looking at a supplementary book for the course I am currently taking and one of the examples is below.
The book states the asterisks refer to a unique key or a composite attribute key.
Given: R(A*,B,C*) and the set {(A,B):R,(B,C):R} satisfies the
lossless decomposition property.
Does the multivalued dependency B->>C hold?
Is B definitely a unique key?
Is R in 4NF?
I understand lossless decomposition - if you take the natural join of the two sets above - you are given the original dataset i.e in this case A,B,C.
But I just cannot grasp how to take the given information and prove/confirm that B->>C holds or if it does not.
I emailed my professor about my confusion and he just told me to look over his notes (which I've obviously done numerous times) and it's gotten me nowhere.

Does the multivalued dependency B->>C hold?
You have been told some things about MVDs. One of them is probably:
A decomposition of R into (X, Y) and (X, R − Y) is a lossless-join
decomposition if and only if X ->> Y holds in R.
In your case R is {A,B,C}, X is {B}, Y is {A} and R - Y = {A,B,C} - {A} = {B,C}. So a decomposition of R into (B,A) and (B,C) is a lossless-join decomposition if and only if {B,A} ->> {B,C} holds in R. But we are given that decomposition of R into (B,A) and (B,C) is a lossless-join decomposition. So {B,A} ->> {B,C} holds in R.
Is B definitely a unique key?
I can't make sense of that.
Maybe you are trying to say that we are given that {A,C} is a CK (candidate key) of R but that there might be other CKs and you are trying to ask whether the decompositionality means that {B} must also be a CK of R. Let's look for a counterexample. Pick a simplest example. Suppose R is {(a,b,c1),(a,b,c2)} = {(a,b)} JOIN {(b,c1),(b,c2)}. This agrees with R CK {A,C} & R MVD {B,A} ->> {B,C}. But b appears with c1 and c2 so {B} does not functionally determine all other attributes so {B} is not a CK of R. So that CK and that MVD do not force that {B} is a CK.
Is R in 4NF?
You have been told some things about 4NF. One is probably that:
A Table is in 4NF if and only if, for every one of its non-trivial
multivalued dependencies X ->> Y, X is a superkey
The MVD {B,A} ->> {B,C} is non-trivial. But to show whether R must be in 4NF or must not be in 4NF or that we can't tell, you are going to have to address possible sets of non-trivial MVDs that could hold in R and CKs that R could have.

Related

Is the following decomposition lossless and dependency preserving?

In R(A,B,C, D),
let the dependencies be
A->B
B->C
C->D
D-> B
the decomposition of R into (A,B), (B,C) and (B,D) is lossless or dependency preserving?
My attempt : (A,B) and (B,C) can be combined lossless-ly because of B->C. However, for (A,B,C) and (B,D), B does not form a key for either. Hence the decomposition in lossy.
Also for dependency preserving, the relation (C-D) can't be gotten from any of the decomposed relations and hence the decomposition is not dependency preserving.
However the answer given is that the decomposition is both lossless and dependency preserving. So where am I wrong?
Also the key for relation R is only {A} isn't it?
You say:
However, for (A,B,C) and (B,D), B does not form a key for either. Hence the decomposition in lossy.
This is wrong, since B is a key for (B, D). We can see this by computing B+ from the original dependencies, assuming that they form a cover of the relation.
B+ = B
B+ = BC (for the dependency B->C)
B+ = BCD (for the dependency C->D)
so, since D is included in B+, we have that B->D can be derived from the original set of dependencies, and in the decomposition (B, D) B is a key (as it is D).
To be dependency preserving we must check that the union of all the projected dependencies of the decomposition is a cover of the original set of dependencies. Since three covers of the decomposed relations are, respectively, {A->B}, {C->B, B->C} and {D->B, B->D}, by uniting those three sets you can easily derive also D->C as well as C->D, so the dependencies are preserved.
Finally, yes {A} is the unique candidate key of the original relation.

Is this in BCNF, 3NF or neither?

My doubt is for a given set of funtional dependencies F = { AE -> BCD, B -> E
}. Is this in BCNF or 3NF? It's a question from a test I have recently done and I would say that it is 3NF, but my teacher said it's neither 3NF nor BCNF. (I believe it is an error).
I have obtained as candidate keys AE and AB, and as in the first functional dependency the left side is a candidate key and in B -> E, E is contained in a candidate key, so it is in 3NF.
Is this in BCNF, 3NF or neither?
Assuming that all the attributes of the relations are A B C D and E, and that the only dependencies given are the two described (F), you are correct. Since the (only) candidate keys are correctly A E and A B, and since the functional dependency B → E has a determinant which is not a superkey, the relation is not in BCNF. Given one of the definitions of BNCF: “for all the non-trivial dependencies X → Y of F+, X is a superkey”, there is a theorem that shows that a necessary and sufficient condition for this is that the property of being a superkey holds for all the dependencies in F.
On the other hand, since E is a prime attribute, i.e. an attribute of a candidate key, the dependency B → E does not violate the 3NF, so that the relation is in 3NF. This, again, given one of the definitions of 3NF: “for all the non-trivial dependencies X → A in F+, then X is a superkey or A is a prime attribute”, is due to a theorem that says that this condition is equivalent to check, “for each functional dependency X → A1,...,An in F, and for each i in {1..n}, either Ai belongs to X, or X is a superkey or Ai is prime”. And this is satified by the two dependencies of F.
You need to use a definition of a NF when you claim/show that a relation is in it.
You don't actually say what all the attributes are. I'll assume the attributes are A through E. Otherwise, the CKs (candidate keys) are not what you say.
You are right in your argument against BCNF. You are using the definition that all determinants of FDs (functional dependencies) are out of superkeys. You found a counterexample FD B → E.
If it were an either-or question re BCNF vs 3NF you could stop there.
in the first functional dependency the left side is a candidate key and in B -> E, E is contained in a candidate key
You don't show that the table meets the conditions of either of the following definitions (from Wikipedia that happen to be correct) that a table is in 3NF if and only if:
both of the following conditions hold:
The relation is in 2NF
Every non-prime attribute is non-transitively dependent on every [candidate] key
for each of its functional dependencies X → A, at least one of the following conditions holds:
X contains A
X is a superkey
each attribute in A-X is prime
You seem to using definition 2 (but not saying so). You show bullet 2 holds for AE → BCD. Pointing out that E is prime in B → E seems to be part of showing that E-B is all prime. But you need to show every FD satisfies a bullet. Note that more FDs hold than the given ones. Armstrong's axioms tell you what all the FDs are.
In practice it can be easier to show a schema is in 3NF by applying a 3NF algorithm.

When will it be in 3NF?

I am having a hard time understanding the 3 Normal form.
3 NF: 2 NF + No transitions
So, for eg: If I have,
A -> B
B -> C
Then the above is sort of a transition relation and hence won't be in 3 NF?
Am I understanding it correctly?
But in this answer What exactly does database normalization do? , by paxdiablo, it says,
Third normal form (3NF) - 2NF and every non-key column in a table depends on nothing but the key.According to this, it will be in 3 NF. Where am I going wrong?
A relation is in 3NF if it is in 2NF and:
either each attribute depends on a key,
or, if an attribute depends on a non-key, then it is prime.
(being prime means that it belongs to a key).
See for instance Wikipedia.
A relation is in Boyce-Codd normal form if only the first condition hold, that is:
each attribute depends on a key
So, in your example, if the relation has only three attributes A, B and C and the two dependencies, it is not in 3NF, since C is not prime, and depends on B, which is a not a key. On the other hand, if there are other attributes, and C is a key or part of a key, then it could be in 3NF (but this depends on the other functional dependencies, that should satisfy the above conditions).
The 2NF says that each non-prime attribute depends on each whole candidate key, and not by part of it. For instance, if a relation has attributes A, B and C, the only key is AB, and B -> C, then this relation is not in 2NF.
The 2-part 3nf definition you are trying for is:
2NF holds and every non-prime attribute of R is non-transitively dependent on every superkey. (X transitively determines Z when there's a Y where X → Y and Y → Z and not Y → X.)
The other definition of 3NF is:
For every non-trivial FD X → Y, either X is a superkey or the attributes in Y but not in X are prime. (X → Y is trivial when X contains Y.)
Then BCNF is:
For every non-trivial FD X → Y, X is a superkey
See this answer.
If your example's only columns are A, B and C and your two FDs form a minimal cover then the only candidate key is A and C is dependent on a non-superkey so it is not in 3NF (or BCNF).
You are (mis)using terms so sloppily that your sentences don't mean anything. Learn the terms and how they are used in their definitions to refer to various things and use them that way in reference to appropriate things. And get your definitions from a (reputable) textbook.

4NF, Multivalued Dependencies without Functional Dependencies

Sorry for asking a question one might consider a basic one)
Suppose we have a relation R(A,B,C,D,E) with multivalued dependencies:
A->>B
B->>D.
Relation R doesn't have any functional dependencies.
Next, suppose we decompose R into 4NF.
My considerations:
Since we don't have any functional dependencies, the only key is all attributes (A,B,C,D,E). There are two ways we can decompose our relation R:
R1(A,B) R2(A,C,D,E)
R3(B,D) R4(A,B,C,E)
My question is - are these 2 decompositions final? Looks like they are since there are no nontrivial multivalued dependencies left. Or am I missing something?
Relation R doesn't have any functional dependencies.
You mean, non-trivial FDs (functional dependencies). (There must always be trivial FDs.)
Assuming that the MVDs (multivalued dependencies) holding in R are those in the transitive closure of {A ↠ B, B ↠ D}:
In 1 R1(A,B) R2(A,C,D,E), we can reconstruct R as R1 JOIN R2 and both R1 & R2 are in 4NF and their join will satisfy A ↠ B. If some component contained all the attributes of the other MVD then we could further decompose it per that MVD. And we would know that, given some alleged values for all components, their alleged reconstruction of R by joining would satisfy both MVDs. But here there is no such component. So we can't further decompose. And we know that an alleged reconstruction of R by joining satisfies A ↠ B but we would still have to check whether B ↠ D. We say that the MVD B ↠ D is "not preserved" and the decomposition to R1 & R2 "does not preserve MVDs".
In 2 R3(B,D) R4(A,B,C,E), we can reconstruct R as R3 JOIN R4 and both R3 & R4 are in 4NF and the join will satisfy B ↠ D. Now some component contains all the attributes of the other MVD so we can further decompose it per that MVD. And we know that, given some alleged values for all components, their alleged reconstruction of R by joining satisfies both MVDs. That component is R4, which we can further decompose, reconstructing as AB JOIN ACE. And we know that an alleged reconstruction of R by joining satisfies both A ↠ B & B ↠ D. Because the MVDs in the original appear in a component, we say these decompositions "preserve MVDs".
PS 1 The 4NF decomposition must be to three components
MVDs always come in pairs. Suppose MVD X ↠ Y holds in a relation with attributes S, normalized to components XY & X(S-Y). Notice that S-XY is the set of non-X non-Y attributes, and X(S-Y) = X(S-XY). Then there is also an MVD X ↠ S-XY, normalized to components X(S-XY) & X(S-(S-XY)), ie X(S-XY) & XY, ie X(S-Y) & XY. Why? Notice that both MVDs give the same component pair. Ie both MVDs describe the same condition, that S = XY JOIN X(S-XY). So when an MVD holds, that partner holds too. We can write the condition expressed by each of the MVDs using the special explicit & symmetrical notation X ↠ Y | S-XY.
We say a JD (join dependency) of some components of S holds if and only if they join to S. So if S = XY JOIN X(S-Y) = XY JOIN X(S-XY) then the JD *{XY, X(S-XY)} holds. Ie the condition that both MVDs describe is that JD. So a certain MVD and a certain binary JD correspond. That's one way of seeing why normalizing an MVD away involves a 2-way join and why MVDs come in pairs. The JDs that cause a 4NF relation to not be in 5NF are those that do not correspond to MVDs.
Your example involves two MVDs that aren't partners & neither otherwise holds as a consequence of the other, so you know that the final form of a lossless decomposition will involve two joins, one for each MVD pair.
PS 2 Ambiguity of "Suppose we have a relation with these multi-valued dependencies"
When decomposing per FDs (functional dependencies) we are usually given a canonical/minimal cover for the relation, ie a set in a certain form whose transitive closure under Armstrong's axioms (set of FDs that must consequently hold) holds all the FDs in the relation. This is frequently forgotten when we are told that some FDs hold. We must either be given a canonical/minimal cover for the relation or be given an arbitrary set and be told that the FDs that hold in the relation are the ones in its transitive closure. If we're just given a set of FDs that hold, we know that the ones in its transitive closure hold, but there might be others. So in general we can't normalize.
Here you give some MVDs that hold. But they aren't the only ones, because each has a partner. Moreover others might (and here do) consequently hold. (Eg X ↠ Y and Y ↠ Z implies X ↠ Z-Y holds.) But you don't say that they form a canonical or minimal cover. One way to get a canonical form for MVDs (a unique one per each transitive closure, hopefully more concise!) would be a minimal cover (one that can't lose any MVDs and still have the same transitive closure) augmented by the partner of each MVD. (Whereas for FDs the standard canonical form is minimal.) You also don't say "the MVDs that hold are those in the transitive closure of these". You just say that those MVDs hold. So maybe some not in the transitive closure do too. So your example can't be solved. We can guess that you probably mean that this is a minimal cover. (It's not canonical.) Or that the MVDs that hold in the relation are those in the transitive closure of the given ones. (Which in this case are then a minimal cover.)
A Table is in 4NF if and only if, for every one of its non-trivial multivalued dependencies X ->> Y, X is a superkey—that is, X is either a candidate key or a superset.
In your first decomposition(1 with R1 and R2) B->>D is not satisfying so it's not dependency preserving decomposition as well as not in 4NF as A is not superkey in 2nd table.
On the other hand,second decomposition(2 with R3 and R4) is dependency preserving and lossless join with B and ACE as primary key in respective tables but it's not in 4NF because A->>B dependency exists in second table and A is not superkey, you have to decompose second table further in to two tables that can be {A B} and {A C E}.
So if I follow your reasoning (suraj3), are R1(A,B) and R2(B,C,D,E) correct decomposition? I think this will preserve the FD B->>D.

BCNF -- Impossible to achieve?

Let R be a relation with Schema R(X,Y,Z)
and it's FDs are
{XY -> Z, Z -> Y}
I am not able to decompose it into BCNF .
Because r1(Z,Y), r2(Z,X) will lose FD XY -> Z and
R(X,Y,Z) itself is not the solution as Z->Y shows that Z should be a key ..
How to do this ???
Every conversion into BCNF may not be dependency preserving
We only need to give a counter example: Consider the following schema;
a b c and c->b
Clearly the above schema is in 3NF, because ab->c is a superkey dependency and ,from c->b we
can see that b-c=b, which is a subset of the primary key (such dependency is also allowed in 3NF).
But, the above schema is not in BCNF because c->b is neither super-key nor trivial dependency.
So we decompose above schema , keeping it lossless.
Only possible lossless decomposition is: ac and cb. (because,their intersection c is primary key for the 2nd table).
But clearly the dependency ab->c is lost.
Hence, proved.

Resources