manipulating functional dependencies

19
Manipulating Functional Dependencies Zaki Malik September 30, 2008

Upload: babu

Post on 10-Feb-2016

41 views

Category:

Documents


1 download

DESCRIPTION

Manipulating Functional Dependencies. Zaki Malik September 30, 2008. Definition of Functional Dependency. If t is a tuple in a relation R and A is an attribute of R , then t A is the value of attribute A in tuple t . - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Manipulating Functional Dependencies

Manipulating Functional Dependencies

Zaki MalikSeptember 30, 2008

Page 2: Manipulating Functional Dependencies

2

Definition of Functional Dependency

• If t is a tuple in a relation R and A is an attribute of R, then tA is the value of attribute A in tuple t.

• The FD AdvisorId AdvisorName holds in R if in every instance of R, for every pair of tuples t and u

Page 3: Manipulating Functional Dependencies

3

Rules for Manipulating FDs

• Learn how to reason about FDs.• Define rules for deriving new FDs from a given set of FDs.• Use these rules to remove “anomalies” from relational designs.• Example: A relation R with attributes A, B, and C, satisfies the FDs

A B and B C. What other FDs does it satisfy? A C

• What is the key for R ?– A, because A B and A C

Page 4: Manipulating Functional Dependencies

4

Splitting and Combining FDs

• Can we split and combine left hand sides of FDs?

– No !

Page 5: Manipulating Functional Dependencies

5

Triviality of FDs

Page 6: Manipulating Functional Dependencies

6

Closure of FD sets• Given a relation schema R and set S of FDs– is the FD F logically implied by S?

• Example– R = {A,B,C,G,H,I}– S = A B, A C, CG H, CG I, B H– would A H be logically implied? – yes (you can prove this, using the definition of FD)

• Closure of S: = all FDs logically implied by S• How to compute ? – we can use Armstrong's axioms

S

S

Page 7: Manipulating Functional Dependencies

7

Armstrong's Axioms• Reflexivity rule

– A1 A2 ... An a subset of A1 A2 ... An

• Augmentation rule– A1 A2 ... An B1 B2 ... Bm

then A1 A2 ... An C1 C2 ... Ck B1 B2 ... Bm C1 C2 ... Ck

• Transitivity rule– A1 A2 ... An B1 B2 ... Bm and

B1 B2 ... Bm C1 C2 ... Ck

then A1 A2 ... An C1 C2 ... Ck

Page 8: Manipulating Functional Dependencies

8

Inferring using Armstrong's Axioms

• = S• Loop– For each F in S, apply reflexivity and augmentation rules– add the new FDs to– For each pair of FDs in S, apply the transitivity rule– add the new FD to

• Until does not change any further

S

S

S

S

S

Page 9: Manipulating Functional Dependencies

9

Additional Rules• Union rule– X Y and X Z, then X YZ– (X, Y, Z are sets of attributes)

• Decomposition rule– X YZ, then X Y and X Z

• Pseudo-transitivity rule– X Y and YZ U, then XZ U

• These rules can be inferred from Armstrong's axioms

Page 10: Manipulating Functional Dependencies

Example• R = (A, B, C, G, H, I)

F = { A B A C CG H CG I B H}• some members of F+

A H • by transitivity from A B and B H

AG I • by augmenting A C with G, to get AG CG

and then transitivity with CG I CG HI

• from CG H and CG I : “union rule” can be inferred from– definition of functional dependencies, or – Augmentation of CG I to infer CG CGI, augmentation of

CG H to infer CGI HI, and then transitivity

Page 11: Manipulating Functional Dependencies

11

Closures of Attributes

Page 12: Manipulating Functional Dependencies

12

Closures of Attributes: Definition

Page 13: Manipulating Functional Dependencies

13

Closures of Attributes: Algorithm

Page 14: Manipulating Functional Dependencies

Closures of Attributes: Algorithm• Basis: Y + = Y• Induction: Look for an FD’s left side X that is a subset of the

current Y + – If the FD is X -> A, add A to Y +

Page 15: Manipulating Functional Dependencies

Y+

new Y+

X A

Diagramatically:

Page 16: Manipulating Functional Dependencies

Why is the Concept of Closures Useful?

Page 17: Manipulating Functional Dependencies

Uses of Attribute ClosureThere are several uses of the attribute closure algorithm:• Testing for superkey:– To test if is a superkey, we compute +, and check if +

contains all attributes of R.• Testing functional dependencies– To check if a functional dependency holds (or, in

other words, is in F+), just check if +. – That is, we compute + by using attribute closure, and then

check if it contains . – Is a simple and cheap test, and very useful

• Computing closure of F– For each R, we find the closure +, and for each S +,

we output a functional dependency S.

Page 18: Manipulating Functional Dependencies

Example of Attribute Set Closure• R = (A, B, C, G, H, I)• F = {A B A C CG H CG I B H}• (AG)+

1. result = AG2. (A C and A B) result = ABCG3. (CG H and CG AGBC) result = ABCGH (CG I and CG AGBCH) result = ABCGHI

• Is AG a super key? • Is AG a key?

Does A+ R?Does G+ R?

Page 19: Manipulating Functional Dependencies

Example of Closure Computation