Vous êtes sur la page 1sur 6

CS-450— Fall 2013

Dr. A. Motro

3 December 2011

Solution to Assignment No. 7: The Theory of Database Design

Problem 1.

1. Does the following relation instance satisfy the functional dependency AB C?

A C B 1 2 1 1 3 1 1 3 2
A C
B
1 2
1
1 3
1
1 3
2

Answer: No. The first two tuples agree on AB but their C values are different.

2. List all the functional dependencies (involving the attributes A, B, C) that are satisfied by the following relation instance:

A C B 1 2 1 1 3 2 1 3 4
A C
B
1 2
1
1 3
2
1 3
4

Answer: There are 7 possibilities for the left-hand-side of functional dependencies (the number of subsets of a set of three attributes, except the empty set), and the same 7 possibilities for the right-hand-side. Altogether, there are 7 · 7 = 49 possible functional dependencies. Checking each of these 49 is a problem similar to part 1.

Of these 49, 35 are satisfied by this instance (including 19 trivial functional depen- dencies), and 4 are not satisfied by this instance. The following table summarizes the answer (“T” means trivial):

ABC

AB

AC

BC

A

B

C

ABC

T

T

T

T

T

T

T

AB

Y

T

Y

Y

T

T

Y

AC

N

N

T

N

T

N

T

BC

Y

Y

Y

T

Y

T

T

 

A N

N

N

N

T

N

N

 

B Y

Y

Y

Y

Y

T

Y

 

C N

N

Y

N

Y

N

T

Problem 2. Assume a schema R = (A, B, C) and the functional dependencies F = {A B, B C}. Prove that the functional dependency AB CB is entailed by the set F . (Hint: Try to derive this functional dependency from the functional dependencies in F using Armstrong’s Axioms.)

Answer:

1

A B

given

2

B C

given

3

A C

from 1 and 2 by transitivity

4

AB CB

from 3 by augmentation with B

Problem 3. The decomposition rule states that if X Y Z then X Y and X Z. Prove that the decomposition rule is sound. (Hint: Try to derive these two functional dependencies from Armstrong’s Axioms.)

Answer: Armstrongs Axioms allow us to infer new functional dependencies from given functional dependencies. The following argument shows that if X Y Z then X Y :

1 given

2 axiom of reflexivity

3 X Y

X Y Z

Y Z Y

from 1 and 2 by transitivity

To show that if X Y Z then X Z , in the above, replace line 2 with Y Z Z , and then line 3 becomes X Z.

Problem 4.

X Y and Z Y then X Z. (Hint: find a relation instance r that refutes the “rule”.)

Show that the following “rule” for functional dependencies is not sound: If

Answer: It is enough to construct one relation instance of one schema that satisfies X Y and Z Y but does not satisfy X Z. It would be nice to find a small example. In this example we choose A for the set X , B for the set Y and C for the set Z . We only need two tuples:

A B C 1 2 3 1 2 4
A
B
C
1
2
3
1
2
4

Notice that A B is satisfied (whenever two tuples agree on A they also agree on B), and

C B is satisfied (because there aren’t any different tuples that agree on C). Yet, A C

is not satisfied (there are two tuples that agree on A, yet they do not agree on C).

Problem 5. Consider the schema R = (A, B, C) and the set of functional dependencies

F = {A B, BC A}.

1. Use Armstrong’s Axioms to generate F + ; i.e., the set of all functional dependencies that are entailed by F . Indicate on the list the functional dependencies that are trivial.

Answer: Generating F + could be done by attempting to generate all the 49 possible functional dependencies (the argument for this number was given in Problem 1). Again, this can be summarized in a 7 x 7 table. In this table “T” means it is in F + because it is generated by the reflexivity axiom (trivial), “G” means it is in F + because it is in the given set F ; a number means that it is in F + and a short derivation is given below the table; and “—” means that it is not in the closure (could not be generated).

ABC

AB

AC

BC

A

B

C

ABC

T

T

T

T

T

T

T

AB

T

T

T

AC

2

4

T

1

T

3

T

BC

5

6

7

T

G

T

T

 

A

8

T

G

 

B

T

 

C

T

2

1.

A B given; then augmentation by C.

2. AC BC derived in step 1; then augmentation by A.

3. AC A trivial; A B given; then transitivity.

4. AC B derived in step 3; then augmentation by A.

5. BC A given; then augmentation by BC .

6. BC A given; then augmentation by B.

7. BC A given; then augmentation by C.

8. A B given; then augmentation by A.

Altogether F + include 29 functional dependencies. Note that discovering that a “func- tional dependency” is not in the closure (i.e., it is not a functional dependency) requires that all further attempts to infer additional functional dependencies fail.

2. By examining F + , find all the superkeys and then the candidate keys of R. (Hint:

Recall that K is a superkey of R iff K R.)

Answer: The closure includes 3 functional dependencies with ABC in the right-hand- side: ABC ABC, AB ABC, and AC ABC. Hence, ABC, AC and BC are 3 superkeys. The keys (i.e., the candidate keys; the superkeys without unnecessary attributes) are AC and BC. The superkey ABC is not a key, because there are strict subsets of it that are superkeys (both AB and AC).

Problem 6. Consider the relation schema R = (A, B, C, D, E) and the set of functional dependencies F = {A BC, CD E, B D, E A}.

1. Show that (A, B, C) and (A, D, E) is a lossless-join decomposition of R (under F ).

Answer: It is recommended here to play the attribute closure game and discover that A, E , CD and BC are all(candidate) keys) of R. We argued that a decomposition is lossless if the intersection of the schemas is a superkey of at least one of the schemas. The intersection of these two schemas is A, and A is a superkey of both schemas (obviously, since A is a superkey of ABCDE, it is a superkey of any subset of ABCDE that includes it).

2. Show that (A, B, C) and (C, D, E) is not a lossless-join decomposition of R (under F ).

Answer: The intersection of these two schemas is C, and C is not a superkey of neither ABC nor CDE. Recall that X is a superkey of R if X R; in other words, X is a superkey of R if the attribute closure of X is R (X + = R). Yet, in the attribute closure game, clicking on C does not color red neither ABC nor CDE.

3. Using the normalization algorithm, find a lossless-join decomposition of R (under F ) into BCNF relation schemas.

Answer:

1. The given relation schema ABCDE is not in BCNF.

2. An example functional dependency that violates BCNF is B D (because it is not trivial and the left-hand-side is not a superkey).

3

3.

Based on this functional dependency we decompose R into ABCE and BD.

4. Both are in BCNF and we are done.

Problem 7. Consider the relation schema R = (A, B, C, D, E), and the set of functional dependencies F = {A C, D CB, AC E}.

1. Is (A, B, C, D, E) in BCNF (under F )? Why?

Answer: Again, use the attribute closure game to discover that the only (candidate) key is AD. Consequently, ABCDE is not in BCNF, because of the functional depen- dency A C which is not trivial and its left-hand-side is not a superkey.

2. Is (C, D, E) in BCNF (under F )? Why?

Answer: Wiping away A and B from the game board (along with the arrows D B, A C and AC E), leaves the game board with three boxes: C, D and E, and one connecting arrow from D to C. The (candidate) key of this schema is therefore DE. Consequently, DCE is not in BCNF, because the functional dependency D E is not trivial and its left-hand-side is not a superkey.

3. Is (A, B, C) in BCNF (under F )? Why?

Answer: Wiping away D and E from the game board (along with the arrows D C, D B, and AC E), leaves the game board with three boxes A, C and B, and one connecting arrow from A to C. The (candidate) key of this schema is therefore AB. Consequently, ABC is not in BCNF, because the functional dependency A C is not trivial and its left-hand-side is not a superkey.

4. Is (A, B, C) and (C, D, E) a lossless-join decomposition (under F )? Why?

Answer: The intersection of these two schemas is C, and C is not a superkey of neither ABC nor CDE (as we just showed, the candidate keys of these schemas are, respectively, AB and DE).

5. Using the normalization algorithm, find a lossless-join decomposition of (A, B, C, D, E) into BCNF relation schemas (under F ).

Answer:

1. The given relation schema ABCDE is not in BCNF.

2. An example functional dependency that violates BCNF is D BC (because it is not trivial and the left-hand-side is not a superkey).

3. Based on this functional dependency we decompose R into DBC and ADE.

4. BCD is in BCNF: D is its key with only two non-trivial functional dependencies:

D B and D C.

5. The other schema ADE is not in BCNF yet. Why? Wiping away C and B from the game board (along with the arrows D B, A C and AC E), leaves the game board with three boxes A, D and E, and no connecting arrows. But we must introduce the arrow A E because it is entailed from A C and AC E. The (candidate) key of this schema is therefore AD. Consequently, ADE is not in BCNF, because the functional dependency A E is not trivial and its left-hand-side is not a superkey.

4

6.

Based on the functional dependency A D we decompose ADE into AD and AE.

7. The final design is DBC, AD, AE.

Problem 8. Consider a database for surgery appointments. The patient is given an appoint- ment at a specific time and date and at a particular surgery location. On each date for which

there are appointments, one surgeon is assigned to a specific surgery location for that entire day. Initially, the following relation schema is proposed: R = (SurgId, SurgN ame, P atId,

surgeon identification number,

P atN ame, AppDate, AppT ime, SurgLoc), where SurgId is

SurgName is surgeon name, PatId is patient identification number, PatNameia is patient name, AppDate is appointment date, AppTime is appointment time, and is surgery location.

1. List the functional dependencies that denote the information given above.

Answer: We abbreviate the attributes, respectively, with Sid, Sname, Pid, Pname, Date, Time, Loc.

1. Sid Sname (obvious)

2. P id P name (obvious)

3. Date, Loc Sid (on given date, a location is assigned one surgeon)

4. Date, Sid Loc (on given date, a surgeon is assigned to one location)

5. Date, T ime, P id Loc (on given date and time, a patient is in one location)

6. Date, T ime, Loc P id (on given date and time, a location has one patient)

7. Date, T ime, Sid P id (on given date and time, a surgeon is with one patient)

8. Date, T ime, P id Sid (on given date and time, a patient is with one surgeon)

The pair 3 and 4 can be summarized: On given date, location and surgeon are one-to- one.

The pair 5 and 6 can be summarized: On given date and time, location and patient are one-to-one.

The pair 7 and 8 can be summarized: On given date and time, surgeon and patient are one-to-one.

It can be shown that 7 and 8 are entailed from 3–6.

The (candidate) keys of the schema are:

1. Date, T ime, P id

2. Date, T ime, Sid

3. Date, T ime, Loc

In other words, an apppointment can be identified uniquely by specifying the date and time and either the patient or the surgeon or the location.

2. Describe the negative aspects of the initial relation.

5

Answer: There are multiple anomalies including (there are others as well!)

1. The surgeon name is repeated in all appointments with the same surgeon.

2. The patient name is repeated in all appointments with the same patient.

3. The location is repeated in all appointments on the same date and with the same surgeon.

4. The surgeon id is repeated in all appointments on the same date and in the same location.

3. Using the normalization algorithm, find a lossless-join decomposition of R into BCNF relations schemas (under the set of functional dependencies listed earlier).

Answer:

1. Initial design: R 0 = (P id, P name, Sid, Sname, Date, T ime, Loc) R 0 is not in BCNF. Choose the functional dependency P id P name and replace R 0 with

2.

R 1

R 2

=

=

(P id, P name)

(P id, Sid, Sname, Date, T ime, Loc)

Current design: R 1 , R 2 .

R 1 is in BCNF but R 2 is not. Choose the functional dependency Sid Sname and replace R 2 with

R

R

3

4

=

=

(Sid, Sname) (P id, Sid, Date, T ime, Loc)

3. Current design: R 1 , R 3 , R 4 . R 1 and R 3 are in BCNF but R 4 is not. Choose Loc, Date Sid and replace R 4 with

R 5

S 6

=

=

(Date, Sid, Loc) (Date, T ime, P id, Sid)

4. Current design: R 1 , R 3 , R 5 , R 6 . All schemas are in BCNF. Done.

Intuitively, R 1 and R 3 are, respectively, the patient file and the surgeon file. R 5 is the assignment of surgeons to locations, and R 6 is the appointment file.

Alternatively, in Step 3 we could choose Sid, Date Loc, and replace R 4 with the same assignment file R 5 , but with the appointment file R 6 = (Date, T ime, P id, Loc).

6