0% found this document useful (0 votes)
214 views

Chapter 11: Relational Database Design Algorithms and Further Dependencies

Exercise 11: Show that the relation schemas produced by algorithm 11. Are in 3NF. Show that if the matrix S does not have a row that is all "a" symbols, then projecting S on the decomposition and joining it back will always produce at least one spurious tuple.

Uploaded by

rvsamy80
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
214 views

Chapter 11: Relational Database Design Algorithms and Further Dependencies

Exercise 11: Show that the relation schemas produced by algorithm 11. Are in 3NF. Show that if the matrix S does not have a row that is all "a" symbols, then projecting S on the decomposition and joining it back will always produce at least one spurious tuple.

Uploaded by

rvsamy80
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Exercises of April 27, 2006

CHAPTER 11: RELATIONAL DATABASE DESIGN ALGORITHMS AND FURTHER DEPENDENCIES


Answers to Selected Exercises 11.15 Show that the relation schemas produced by Algorithm 11.2 are in 3NF. Answer: We give a proof by contradiction. Suppose that one of the relations Ri resulting from Algorithm 11.2 is not in 3NF. Then (by definition of 3 NF) a FD Y -> A holds in Ri where: (a) Y is not a superkey of Ri, and (b) A is not a prime attribute. According to step 2 of the algorithm, Ri will contain a set of attributes X A 1 ... An, X is a key of Ri and the A i are the non-prime attributes of Ri. The set G of FDs X -> Ai is minimal. Hence, if an FD Y -> A holds in Ri where A is non-prime and Y is not a superkey of Ri , Y must be a proper subset of X (otherwise Y would contain X and hence be a superkey, and Y cannot contain non-prime attributes). If both Y -> A and X -> A hold and Y is a proper subset of X, this contradicts that X -> A is a FD in a minimal set of FDs that is input to the algorithm, since removing an attribute from X leaves a valid FD, thus violating one of the minimality conditions. This produces a contradiction of our assumptions. Hence, Ri must be in 3NF.

This material has been taken from draft Pre-Publication Material, Copyright AWL2004

Exercises of April 27, 2006

11.16 Show that if the matrix S resulting from Algorithm 11.1 does not have a row that is all "a" symbols, then projecting S on the decomposition and joining it back will always produce at least one spurious tuple. Answer: The matrix S initially has one row for each relation Ri in the decomposition, with "a" symbols under the columns for the attributes in Ri. Since we never change an "a" symbol into a "b" symbol during the application of the algorithm, projecting S on each Ri at the end of applying the algorithm will produce one row consisting of all "a" symbols in each S(Ri). Joining these back together again will produce at least one row of all "a" symbols (resulting from joining the all "a" rows in each projection S(Ri)). Hence, if after applying the algorithm, S does not have a row that is all "a", projecting S over the Ri's and joining will result in at least one all "a" row, which will be a spurious tuple (since it did not exist in S but will exist after projecting and joining over the Ri's). If this line of reasoning is not immediate clear, take R(A,B,C) without any FDs and its decomposition R1(A,B) and R2(B,C). Then the initial matrix S will be R1 R2 A a1 b21 B C a2 b12 a 2 a3

The algorithm will stop immediate, as there are no FDs at all. Let us take an extension of R (a concrete set of tuples), that corresponds with the initial value of the matrix S. So we have two tuples, with the same value for the B attribute, but with different values for the A and C attributes. If we take the two projections, S(R1) = (a1, a2) and S(R2) = (a2, a3) and join these results we get a spurious tuple (a1, a2, a3), i.e., a tuple which did not exist in the set of tuples from which we started. To instantiate this example even more, take R(Bar, Brand, Beer) with R1(Bar, Brand) and R2(Brand, Beer), and the following extension Bar Hardrock Cooldown Brand Heineken Heineken Beer Amstel-1870 Pilsener

The two projections will contain, for S(R1) Bar Hardrock Cooldown Brand Heineken Heineken

and for S(R2) Brand Heineken Heineken Beer Amstel-1870 Pilsener

Joining these projections will give us

This material has been taken from draft Pre-Publication Material, Copyright AWL2004

Exercises of April 27, 2006

Bar Hardrock Hardrock Cooldown Cooldown

Brand Heineken Heineken Heineken Heineken

Beer Amstel-1870 Pilsener Amstel-1870 Pilsener

We see two spurious tuples, one of them is (Hardrock, Heineken, Pilsener), corresponding with the spurious tuple (a1, a2, a3). Note that if return to the R(A,B,C) case, we add the FD B -> C and we apply the algorithm again, then we obtain the matrix R1 R2 A a1 b21 B C a 2 a3 a 2 a3

Which shows us that in this case the lossless join property does hold. In the Beer-example this means that the Brand (i.e. Heineken) must determine the Beer which must be either Amstel-1870 or Pilsener, but not both.

This material has been taken from draft Pre-Publication Material, Copyright AWL2004

Exercises of April 27, 2006

11.21 Prove that a functional dependency is also a multivalued dependency. Answer: Suppose that a functional dependency X -> Y exists in a relation R={X, Y, Z}, and suppose there are two tuples with the same value of X. Because of the functional dependency, they must also have the same value of Y. Suppose the tuples are t1 = < x, y, z1 > and t2 = < x, y, z2 >. Then, according to the definition of multivalued dependency, we must have two tuples t3 and t4 (not necessarily distinct from t1 and t2 ) satisfying: t3[X]= t4[X]= t1[X]= t2[X], t3[Y]= t2[Y], t4[Y]= t1[Y], t3[Z]= t1[Z], and t4[Z]= t2[Z].

Two tuples satisfying this are t2 (satisfies conditions for t4 ) and t1 (satisfies conditions for t3). Hence, whenever the condition for functional dependency holds, so does the condition for multivalued dependency.

This material has been taken from draft Pre-Publication Material, Copyright AWL2004

Exercises of April 27, 2006

11.29 Consider universal relation R(A,B,C,D,E,F,G,H,I,J) of Exercise 10:26 with the following set of FDs F = {{A,B} -> C, {A} -> {D,E}, {B} -> {F}, {F} -> {G,H}, {D}-> {I,J}}. Determine for each of the following decompositions whether (i) the dependencies are preserved, (ii) the lossless join property holds, and (iii) determine which normal form the decomposition is in. a) D1 = {R1, R2, R3, R4, R5}, R1 = {A,B,C}, R2 = {A,D,E}, R3 = {B,F}, R4 = {F,G,H}, R5 = {D,I,J}, All dependencies are preserved. Does the lossless join property hold? We start with the following matrix: R1 R2 R3 R4 R5 A a1 a1 b31 b41 b51 B a2 b22 a2 b42 b52 C a3 b23 b33 b43 b53 D b14 a4 b34 b44 a4 E b15 a5 b35 b45 b55 F b16 b26 a6 a6 b56 G b17 b27 b37 a7 b57 H b18 b28 b38 a8 b58 I b19 b29 b39 b49 a9 J b110 b210 b310 b410 a10

We apply the Fds as follows: - {A,B} -> C, no changes; - {A} -> {D,E}, a4 and a5 are copied from R2 to R1; - {B} -> {F}, a6 is copied from R3 to R1; - {F} -> {G,H}, a7 and a8 are copied from R4 to R1 and R3; - {D}-> {I,J}, a9 and a10 are copied from R5 to R1 and R2 This gives us the following matrix, with all as in the R1 row. Hence, this decomposition does satisfy the lossless join property. R1 R2 R3 R4 R5 A a1 a1 b31 b41 b51 B a2 b22 a2 b42 b52 C a3 b23 b33 b43 b53 D a4 a4 b34 b44 a4 E a5 a5 b35 b45 b55 F a6 b26 a6 a6 b56 G a7 b27 a7 a7 b57 H a8 b28 a8 a8 b58 I a9 a9 b39 b49 a9 J a10 a10 b310 b410 a10

There are no partial dependencies, so it is at least in 2 NF. For every FD X -> A in F It holds that X is the key of the associated (sub-)relation scheme, so this decomposition is in BCNF. There are no real MVDs, i.e., every MVD is also an FD, hence the decomposition is also in 4 NF. Similarly, there are only join dependencies, JDs, which are also MVDs/FDs, hence the decomposition is also in 5 NF.

b) D2 = {R1, R2, R3}, R1 = {A,B,C,D,E}, R2 = {B,F,G,H}, R3 = {D,I,J}. All dependencies are preserved. Does the lossless join property hold? We start with the following matrix: R1 R2 R3 A a1 b21 b31 B a2 a2 b32 C a3 b23 b33 D E a4 a5 b24 b25 a4 b35 F b16 a6 b36 G b17 a7 b37 H b18 a8 b38 I b19 b29 a9 J b110 b210 a10

We apply the Fds as follows: {A,B} -> C, no changes; {A} -> {D,E}, no changes;

This material has been taken from draft Pre-Publication Material, Copyright AWL2004

Exercises of April 27, 2006

{B} -> {F}, a6 is copied from R2 to R1; {F} -> {G,H}, a7 and a8 are copied from R2 to R1; {D}-> {I,J}, a9 and a10 are copied from R3 to R1.

This gives us the following matrix, with all as in the R1 row. Hence, this decomposition does satisfy the lossless join property. R1 R2 R3 A a1 b21 b31 B a2 a2 b32 C a3 b23 b33 D E a4 a5 b24 b25 a4 b35 F a6 a6 b36 G a7 a7 b37 H a8 a8 b38 I a9 b29 a9 J a10 b210 a10

It is in 1 NF, because of the partial dependency {A} -> {D,E}.

c) D3 = {R1, R2, R3, R4, R5}, R1 = {A,B,C,D}, R2 = {D,E}, R3 = {B,F}, R4 = {F,G,H}, R5 = {D,I,J}, The dependency A -> E is not preserved. Does the lossless join property hold? We start with the following matrix: R1 R2 R3 R4 R5 A a1 b12 b31 b41 b51 B a2 b22 a2 b42 b52 C a3 b23 b33 b43 b53 D a4 a4 b34 b44 a4 E b15 a5 b35 b45 b55 F b16 b26 a6 a6 b56 G b17 b27 b37 a7 b57 H b18 b28 b38 a8 b58 I b19 b29 b39 b49 a9 J b110 b210 b310 b410 a10

We apply the Fds as follows: - {A,B} -> C, no changes; - {A} -> {D,E}, no changes; - {B} -> {F}, a6 is copied from R3 to R1; - {F} -> {G,H}, a7 and a8 are copied from R4 to R1 and R3; - {D}-> {I,J}, a9 and a10 are copied from R5 to R1 and R2. Iterating over this loop will not give us any new updates, so we stop with all rows containg at least one b. Hence, the lossless join property does not hold. Note that we would need an FD {D} -> {E} to change the b15 field in the R1 into a5. R1 R2 R3 R4 R5 A a1 b12 b31 b41 b51 B a2 b22 a2 b42 b52 C a3 b23 b33 b43 b53 D a4 a4 b34 b44 a4 E b15 a5 b35 b45 b55 F a6 b26 a6 a6 b56 G a7 b27 a7 a7 b57 H a8 b28 a8 a8 b58 I a9 a9 b39 b49 a9 J a10 a10 b310 b410 a10

Because of the partial dependency {A} -> {D} it cannot be in 2 NF, hence it is in 1 NF.

This material has been taken from draft Pre-Publication Material, Copyright AWL2004

Exercises of April 27, 2006

11.30 Consider the relation REFRIG(MODEL#, YEAR, PRICE, MANUF_PLANT, COLOR), which is abbreviated as REFRIG(M, Y, P, MP, C), and the following set of F of functional dependencies: F={M -> MP, {M,Y} -> P, MP -> C} (a) Evaluate each of the following as a candidate key for REFRIG, giving reasons why it can or cannot be a key: {M}, {M,Y}, {M.C} (b) Based on the above key determination, state whether the relation REFRIG is in 3NF and in BCNF, giving proper reasons. (c) Consider the decomposition of REFRIG into D={R1(M,Y,P), R2 (M,MP,C)}. Is this decomposition lossless? Show why. (You may consult the test under Property LJ1 in Section 11.1.4) Answers: (a) {M} IS NOT a candidate key since it does not functionally determine attributes Y or P. {M, Y} IS a candidate key since it functionally determines the remaining attributes P, MP, and C. From F it is immediate the MP and P are functionally determined by M and Y. By transitivity (M -> MP and MP -> C) we also know that M -> C. {M, C} IS NOT a candidate key since it does not functionally determine attributes Y or P.

(b) REFRIG is not in 2NF, because {M,Y} is the key which makes M -> MP a partial dependency. Therefore REFRIG is neither in 3NF nor in BCNF. Alternatively: BCNF can be directly tested by using all of the given dependencies and finding out if the left hand side of each is a superkey (or if the right hand side is a prime attribute). Take the two FDs M -> MP and MP -> C. Since neither M nor MP is a superkey, we can conclude that REFRIG is is neither in 3NF nor in BCNF. (c) R = {M, Y, P, MP, C} R1 = {M, Y, P}, R2 = {M, MP, C} F = { M -> MP, {M,Y} -> P, MP -> C} R1 R2 = {M} R2 R1 = {MP, C} R1 R2 -> R2 R1 (see Property LJ1) reduces to {M} -> {MP, C}. The FD {M} -> {MP} is in F, and the FD {M} -> {C} is in F+ by transitivity of M -> MP and MP -> C. Hence, R1 R2 -> R2 R1 is in F+ by which we have shown the lossless property.

This material has been taken from draft Pre-Publication Material, Copyright AWL2004

You might also like