Sunteți pe pagina 1din 9
UVA DEPARTMENT OF COMPUTER SCIENCE

UVA

DEPARTMENT OF COMPUTER SCIENCE

Multivalued Dependencies

FD is a powerful formalism for decomposing schema to eliminate redundancyUVA DEPARTMENT OF COMPUTER SCIENCE Multivalued Dependencies Idea behind FD: - the value of a particular

Idea behind FD:formalism for decomposing schema to eliminate redundancy - the value of a particular attribute uniquely determine

-

the value of a particular attribute uniquely determine the value of some other attribute

-

what if change uniquely determine by restrict?

-

FD

rules out existence of certain tuples in the relation:

A

t 1 [A]=t 2 [A]

of certain tuples in the relation: A t 1 [A]=t 2 [A] B means there’s no

B means there’s no two tuples t 1 and t 2 such that

means there’s no two tuples t 1 and t 2 such that t 1 [B] t

t 1 [B]

no two tuples t 1 and t 2 such that t 1 [B] t 2 [B]

t 2 [B]

Multivalued dependency (MVD)tuples t 1 and t 2 such that t 1 [B] t 2 [B] - MVD

- MVD requires other tuples of a certain form be present

- consequence of 1NF that disallows a set of values for an attribute in a tuple

- if two or more multivalued independent attributes in the relation, every value of one attribute must be repeated with every value of other attribute to keep it consistent

UVA DEPARTMENT OF COMPUTER SCIENCE

UVA

DEPARTMENT OF COMPUTER SCIENCE

MVD

Let R be a relation schema, and X and Y be disjoint subsets of R

(i.e., X

A relation r(R) satisfies X

t 1 (X)=t 2 (X), then there exist t 3 in r such that

t 3 (X)=t 1 (X),

By symmetry, there exist t 4 in r such that

t 4 (X)=t 1 (X), t 4 (Y)=t 2 (Y),

such that t 4 (X)=t 1 (X), t 4 (Y)=t 2 (Y), R, Y R, X

R, Y

that t 4 (X)=t 1 (X), t 4 (Y)=t 2 (Y), R, Y R, X Y=

R, X

t 4 (X)=t 1 (X), t 4 (Y)=t 2 (Y), R, Y R, X Y= ),

Y=

4 (X)=t 1 (X), t 4 (Y)=t 2 (Y), R, Y R, X Y= ), and

), and Z = R

XY.

(X), t 4 (Y)=t 2 (Y), R, Y R, X Y= ), and Z = R

Y if for any two tuples t 1 and t 2 ,

t 3 (Y)=t 1 (Y), t 3 (Z)=t 2 (Z).

t 4 (Z)=t 1 (Z).

1 (Y), t 3 (Z)=t 2 (Z). t 4 (Z)=t 1 (Z). t t t t

t

t

t

t

1

2

3

4

X

---------------

Y

Z

x1

y1

z1

x1

y2

z2

x1

y1

z2

x1

y2

z1

Intuition

The MVD X

z2 x1 y1 z2 x1 y2 z1 Intuition The MVD X Y says that the relationship

Y says that the relationship between

X

and Y is independent of the relationship between

X

and R

Y

UVA DEPARTMENT OF COMPUTER SCIENCE

UVA

DEPARTMENT OF COMPUTER SCIENCE

<ex> Employee

MVD

(E-name

------------------------------------------------

P-name

D-name)

Smith

X

John

Smith

Y

Ann

Smith

X

Ann

Smith

Y

John

MVDs E-name hold in the relation:Y Ann Smith X Ann Smith Y John P-name and E-name D-name The employee named Smith

Ann Smith Y John MVDs E-name hold in the relation: P-name and E-name D-name The employee
Ann Smith Y John MVDs E-name hold in the relation: P-name and E-name D-name The employee

P-name and E-name

John MVDs E-name hold in the relation: P-name and E-name D-name The employee named Smith works

D-name

The employee named Smith works on projects X and Y, and has two dependents John and Ann.

If we store only the first two tuples in the relation, it would incorrectly show the associations among attributes.on projects X and Y, and has two dependents John and Ann. If we have MVDs

If we have MVDs in a relation, we may have to repeat values

redundantly in the tuples. In the Employee relation, values

X and Y of P-name are repeated with each value of D-name.

--- clearly undesirable

Problem: Employee schema is in BCNF because no FDs hold for it

UVA DEPARTMENT OF COMPUTER SCIENCE

UVA

DEPARTMENT OF COMPUTER SCIENCE

Notes on MVD

Trivial MVDUVA DEPARTMENT OF COMPUTER SCIENCE Notes on MVD If MVD X schemas include X and Y,

If MVD X

schemas include X and Y, it is called trivial MVD.

- X

X schemas include X and Y, it is called trivial MVD. - X Y is satisfied

Y is satisfied by all relations whose

trivial MVD. - X Y is satisfied by all relations whose Y is trivial whenever Y

Y is trivial whenever Y

is satisfied by all relations whose Y is trivial whenever Y X or X Y=R If

X or X

by all relations whose Y is trivial whenever Y X or X Y=R If a relation

Y=R

If a relation r fails to satisfy a given MVD, a relation r’ that satisfies the MVD can be constructed by adding tuples to rby all relations whose Y is trivial whenever Y X or X Y=R - MVD is

- MVD is called "tuple generating dependency"

- compare it with FD: need to delete tuples to make the relation to satisfy a given FD

MVD can be used in two waysto delete tuples to make the relation to satisfy a given FD - test relations to

- test relations to determine whether they are legal under a given set of FDs and MVDs

- specify constraints on a set of relations

UVA DEPARTMENT OF COMPUTER SCIENCE

UVA

DEPARTMENT OF COMPUTER SCIENCE

Inference Rules for Computing D +

D: a set of FDs and MVDs

D + : the closure of D, the set of all FDs and MVDs logically implied by D

Sound and complete rules

1. reflexivity: if Y X then X Y 2. augmentation: if X Y then WX
1. reflexivity: if Y
X then X
Y
2. augmentation: if X
Y then WX

Y

3. transitivity: if X

4. complementation: if X

Y and YY then WX Y 3. transitivity: if X 4. complementation: if X Z then X Y

WX Y 3. transitivity: if X 4. complementation: if X Y and Y Z then X

Z then XWX Y 3. transitivity: if X 4. complementation: if X Y and Y Y then X

Y then X

Z R
Z
R

XY

5. MV augmentation: if X

Y and W then WX

X Y then X Z R XY 5. MV augmentation: if X Y and W then
X Y then X Z R XY 5. MV augmentation: if X Y and W then
X Y then X Z R XY 5. MV augmentation: if X Y and W then
X Y then X Z R XY 5. MV augmentation: if X Y and W then

R, VX Y then X Z R XY 5. MV augmentation: if X Y and W then

VY

X Z R XY 5. MV augmentation: if X Y and W then WX R, V

W,

6. MV transitivity: if X

6. MV transitivity: if X Y and Y
6. MV transitivity: if X Y and Y

Y and Y

6. MV transitivity: if X Y and Y Z then X Z Y
6. MV transitivity: if X Y and Y Z then X Z Y

Z then X

Z then X
Z then X

Z

Y

7. replication: if X

7. replication: if X Y then X

Y then X

7. replication: if X Y then X
Y

Y

 

8. coalescence: if X then X

8. coalescence: if X then X Y, W Z Y and Z

Y, W8. coalescence: if X then X Z Y and Z

Z8. coalescence: if X then X Y, W Y and Z

Y and Z

8. coalescence: if X then X Y, W Z Y and Z
8. coalescence: if X then X Y, W Z Y and Z R, W Y= ,

R, W

Y= , W

Y=

Y= , W

, W

8. coalescence: if X then X Y, W Z Y and Z R, W Y= ,

Z,

Note: The first three rules are Armstrong’s axioms.

UVA DEPARTMENT OF COMPUTER SCIENCE

UVA

DEPARTMENT OF COMPUTER SCIENCE

Fourth Normal Form

A relation scheme R is in 4NF w.r.t. D, if for every

non-trivial MVD X

Y in D + , X is a superkey for R

every non-trivial MVD X Y in D + , X is a superkey for R 4NF
every non-trivial MVD X Y in D + , X is a superkey for R 4NF

4NF and BCNF

- 4NF is different from BCNF only in the use of

D (FD + MVD) instead of F (FDs)

- every 4NF schemas are also in BCNF. Why?

By replication rule, X

If R is not in BCNF, there exists a non-trivial FD X

where X is not a superkey --- R cannot be in 4NF

FD X where X is not a superkey --- R cannot be in 4NF Y implies

Y implies X

where X is not a superkey --- R cannot be in 4NF Y implies X Y.

Y.

X is not a superkey --- R cannot be in 4NF Y implies X Y. Y

Y

<ex> Employee (E-name, P-name, D-name) is not in 4NF, since

E-name

Decompose into Emp-proj (E-n, P-n) and Emp-dep (E-n, D-n)

Decompose into Emp-proj (E-n, P-n) and Emp-dep (E-n, D-n) P-name but E-name is not a key.

P-name but E-name is not a key.

<ex> Borrow (Loan#, C-name, Street, C-city) is in BCNF, but

not in 4NF, because C-name

where C-name is not a key in this schema. R 1 =(C-name, Loan#), R 2 =(C-name, Street, C-city)

is not a key in this schema. R 1 =(C-name, Loan#), R 2 =(C-name, Street, C-city)

Loan# is a non-trivial MVD,

UVA DEPARTMENT OF COMPUTER SCIENCE

UVA

DEPARTMENT OF COMPUTER SCIENCE

Benefits of Fourth Normal Form

Reduced number of tuplesOF COMPUTER SCIENCE Benefits of Fourth Normal Form No anomalies for insert/delete/update <ex> Employee

No anomalies for insert/delete/updateBenefits of Fourth Normal Form Reduced number of tuples <ex> Employee (E-name

<ex> Employee

(E-name

------------------------------------------------

P-name

D-name)

Smith

X

John

Smith

Y

Ann

Smith

X

Ann

Smith

Y

John

Brown

W

Jim

Brown

X

Jim

Brown

Y

Jim

Brown

W

Bob

Brown

X

Bob

Brown

Y

Bob

Emp-proj (E-name P-name) Emp-dep (E-name D-name) ---------------------

-----------------------

Smith

X

Smith

John

Smith

Y

Smith

Ann

Brown

W

Brown

Jim

Brown

X

Brown

Bob

Brown

Y

UVA DEPARTMENT OF COMPUTER SCIENCE

UVA

DEPARTMENT OF COMPUTER SCIENCE

Lossless Join Decomposition

The decomposition of R into R 1 and R 2 is a lossless join decomposition iff one of the following MVDs 1 and R 2 is a lossless join decomposition iff one of the following MVDs hold in D +

R 1

R 1

iff one of the following MVDs hold in D + R 1 R 1 R R

iff one of the following MVDs hold in D + R 1 R 1 R R

R

R

2

2

iff one of the following MVDs hold in D + R 1 R 1 R R

iff one of the following MVDs hold in D + R 1 R 1 R R

iff one of the following MVDs hold in D + R 1 R 1 R R

iff one of the following MVDs hold in D + R 1 R 1 R R

R

R

1

2

(or

(or

R

R

1

2

R 2 ) R 1 )

--- whenever R is decomposed into R 1 =(X

Y) and R 2 =(R 2 =(R

based on an MVD X

it is a lossless join decomposition

=(R based on an MVD X it is a lossless join decomposition Y that holds in

Y that holds in R,

AlgorithmMVD X it is a lossless join decomposition Y that holds in R, Y) set D:={R}

Y)

set D:={R}

while there is a schema Q in D that is not in 4NF do

begin

end.

choose Q in D not in 4NF find a non-trivial MVD X that violates 4NF

replace Q in D by (Q

a non-trivial MVD X that violates 4NF replace Q in D by (Q Y in Q

Y in Q

MVD X that violates 4NF replace Q in D by (Q Y in Q Y) and

Y) and (X

Y)

Dependency preservation is not guaranteedend. choose Q in D not in 4NF find a non-trivial MVD X that violates 4NF

UVA DEPARTMENT OF COMPUTER SCIENCE

UVA

DEPARTMENT OF COMPUTER SCIENCE

4NF

Goal of database designUVA DEPARTMENT OF COMPUTER SCIENCE 4NF - 4NF (BCNF if there is no MVD) - dependency

- 4NF (BCNF if there is no MVD)

- dependency preservation

- lossless join decomposition

If cannot satisfy all these, which one to compromise?MVD) - dependency preservation - lossless join decomposition The first one: 4NF > BCNF > 3NF

The first one: 4NF > BCNF > 3NF to ensure other two

BCNF and 4NFThe first one: 4NF > BCNF > 3NF to ensure other two - although they are

- although they are well known, they are not widely accepted as 1NF, 2NF, and 3NF, since dependency preservation is not guaranteed

Comparing FD and MVDand 3NF, since dependency preservation is not guaranteed - if we have (a1 b1 c1 d1)

- if we have (a1 b1 c1 d1)

guaranteed Comparing FD and MVD - if we have (a1 b1 c1 d1) r and (a1

r and (a1 b2 c2 d2)

FD and MVD - if we have (a1 b1 c1 d1) r and (a1 b2 c2

r

A B implies b1=b2

A B implies b1=b2

A B implies (a1 b1 c2 d2)

A B implies (a1 b1 c2 d2)
A B implies (a1 b1 c2 d2)
A B implies (a1 b1 c2 d2) r

r