0% found this document useful (0 votes)
32 views28 pages

Chapter 15

The document discusses functional dependencies in relational database design. It defines functional dependencies and outlines Armstrong's inference rules for deriving implied functional dependencies. These rules are reflexivity, augmentation, and transitivity. The document also discusses closure, which is the set of all attributes that can be functionally derived from a given set of attributes using the inference rules. An algorithm is provided to calculate closure. Examples are given to demonstrate finding functional dependencies from a closure set of attributes.

Uploaded by

aliza
Copyright
© © All Rights Reserved
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)
32 views28 pages

Chapter 15

The document discusses functional dependencies in relational database design. It defines functional dependencies and outlines Armstrong's inference rules for deriving implied functional dependencies. These rules are reflexivity, augmentation, and transitivity. The document also discusses closure, which is the set of all attributes that can be functionally derived from a given set of attributes using the inference rules. An algorithm is provided to calculate closure. Examples are given to demonstrate finding functional dependencies from a closure set of attributes.

Uploaded by

aliza
Copyright
© © All Rights Reserved
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/ 28

CE 301T

CHAPTER 15
Relational Database Design Algorithm
and Further Dependencies
Dr. Najma Ismat
[email protected]

Computer Engineering Depar


Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe
Chapter Outline

◼ 1. Further topics in Functional Dependencies


◼ 1.1 Inference Rules for FDs
◼ 1.2 Equivalence of Sets of FDs
◼ 1.3 Minimal Sets of FDs

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 2


1. Functional Dependencies : Inference
Rules, Equivalence and Minimal Cover

◼ We discussed functional dependencies in the last


chapter.
◼ To recollect:

A set of attributes X functionally determines a set of


attributes Y if the value of X determines a unique
value for Y.
◼ Our goal here is to determine the properties of

functional dependencies and to find out the ways


of manipulating them.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 3


Defining Functional Dependencies
◼ X → Y holds if whenever two tuples have the same value
for X, they must have the same value for Y
◼ For any two tuples t1 and t2 in any relation instance r(R): If
t1[X]=t2[X], then t1[Y]=t2[Y]
◼ X → Y in R specifies a constraint on all relation instances
r(R)
◼ Written as X → Y; can be displayed graphically on a
relation schema as in Figures in Chapter 14. ( denoted by
the arrow: ).
◼ FDs are derived from the real-world constraints on the
attributes

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 4


1.1 Inference Rules for FDs (1)
◼ Definition: An FD X → Y is inferred from or implied by
a set of dependencies F specified on R if X → Y holds in
every legal relation state r of R; that is, whenever r
satisfies all the dependencies in F, X → Y also holds in r.

◼ Given a set of FDs F, we can infer additional FDs that


hold whenever the FDs in F hold

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 5


Inference Rules for FDs (2)
◼ Armstrong rules/axioms: An axiom is a statement taken to
R(A,B,C)
be true and serves as a starting point of an argument.
X=ABC
◼ It holds on every relational database and is used to Y=AB
generate closure set ABC →AB
◼ Armstrong's inference rules:
◼ IR1. (Reflexive) If Y subset of X, then X → Y

◼ IR2. (Augmentation) If X → Y, then XZ → YZ

◼ (Notation: XZ stands for X U Z)

◼ IR3. (Transitive) If X → Y and Y → Z, then X →


Z
◼ IR1, IR2, and IR3 form a sound and complete set
of inference rules
◼ These are rules that hold and all other rules that
hold can be deduced from these

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 6


Inference Rules for FDs (3)
◼ Some additional inference rules AB→CD Union/co
mpositio
that are useful: AB→C n
AB→D
◼ Decomposition: If X → YZ, Decomposition
then X → Y and X → Z Applied on R.H.S only

◼ Union: If X → Y and X → Z,
then X → YZ
◼ Psuedotransitivity: If X → Y
and WY → Z, then WX → Z

◼ The last three inference rules, as


well as any other inference rules,
can be deduced from IR1, IR2,
and IR3 (completeness property)

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15 - 7


Closure
◼ Closure of a set F of FDs is the set F+ of all FDs that can
be inferred from F

◼ Closure of a set of attributes X with respect to F is the set


X+ of all attributes that are functionally determined by X

◼ X+ can be calculated by repeatedly applying IR1, IR2, IR3


using the FDs in F

The Closure Of Functional Dependency means the complete set of all possible
attributes that can be functionally derived from given functional dependency using
the inference rules known as Armstrong’s Rules.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15 - 8


Algorithm to determine Closure

◼ Algorithm 15.1. Determining X+, the Closure of X


under F
◼ Input: A set F of FDs on a relation schema R,
and a set of attributes X, which is a subset of R.
X+ := X;
repeat
oldX+ := X+;
for each functional dependency, Y → Z in F do
if X+  Y then X+ := X+  Z;
until (X+ = oldX+);
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15 - 9
Steps to find out the FDs from the closure
1. Step 1: Add the attributes that are present on the Left-Hand
Side in the original functional dependency.
2. Step 2: Now, add the attributes present on the Right-Hand
Side of the functional dependency.
3. Step 3: With the help of attributes present on the Right-
Hand Side, check the other attributes that can be derived
from the other given functional dependencies. Repeat this
process until all the possible attributes which can be derived
are added to the closure.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 10


Finding FDs from the Closure Set of
Attributes
◼ Assume a relation R with attributes A, B, and C R(A, B, C)
◼ The possible FDs are: A→B and B→C
◼ Some dependencies are visible, and some are invisible and that can
be found from the closure set of attributes
◼ There is an invisible dependency that can be found by transitivity that:
from B→C we can find C from A i.e., A→BC
◼ Finding the FDs from closure set of attributes:
◼ A+= {A,B}
◼ B+={B,C}
◼ C+={C}

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 11


Example of Closure (1)
◼ Consider the table student_details having (Roll_No, Name,Marks, Location)
as the attributes and having two functional dependencies.
◼ FD1 : Roll_No → Name, Marks
◼ FD2: Name → Marks, Location
◼ Step 1: Add attributes present on the LHS of the first functional
dependency to the closure {Roll_no}+ = {Roll_No}
◼ Step 2: Add attributes present on the RHS of the original functional
dependency to the closure. {Roll_no}+ = {Roll_No, Marks}
◼ Step 3: Add the other possible attributes that can be derived using
attributes present on the RHS of the closure.
◼ So,
◼ Roll_No attribute cannot functionally determine any attribute.
◼ The Name attribute can determine other attributes such as Marks and Location using
2nd Functional Dependency(Name → Marks, Location).
{Roll_no}+ = {Roll_No, Marks, Name, Location}
https://minigranth.in/dbms-tutorial/canonical-cover-of-functional-dependency
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 12
Example of Closure (1)
◼ Similarly, we can calculate closure for other attributes too i.e. “Name”.
◼ Step 1: Add attributes present on the LHS of the first functional
dependency to the closure {Name}+ = {Name}
◼ Step 2: Add attributes present on the RHS of the original functional
dependency to the closure. {Name}+ = {Name, Marks, Location}
◼ Step 3: Since we don’t have any functional dependency where the “Marks
or Location” attribute is functionally determining any other attribute, we
cannot add more attributes to the closure.
◼ Hence complete closure of the Name would be: So,
{Name}+ = {Name, Marks, Location}
◼ NOTE: We don’t have any Functional dependency where marks and
location can functionally determine any attribute. Hence, for those
attributes, we can only add the attributes themselves in their closures.
Therefore,
{Marks}+ = {Marks} and {Location}+ = { Location}
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 13
Example of Closure (2)
◼ For example, consider the following relation schema about classes
held at a university in a given academic year.
CLASS ( Classid, Course#, Instr_name, Credit_hrs, Text, Publisher,
Classroom, Capacity).
◼ Let F, the set of functional dependencies for the above relation
include the following f.d.s:

FD1: Sectionid → Course#, Instr_name, Credit_hrs, Text, Publisher,


Classroom, Capacity;
FD2: Course# → Credit_hrs;
FD3: {Course#, Instr_name} → Text, Classroom;
FD4: Text → Publisher
FD5: Classroom → Capacity
These f.d.s above represent the meaning of the individual attributes and the
relationship among them and defines certain rules about the classes.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15 - 14
Example of Closure (2)
◼ The closures of attributes or sets of attributes for some example sets:

{ Classid } + = { Classid , Course#, Instr_name, Credit_hrs, Text, Publisher,


Classroom, Capacity } = CLASS

{ Course#} + = { Course#, Credit_hrs}

{ Course#, Instr_name } + = { Course#, Credit_hrs, Text, Publisher,


Classroom, Capacity }

Note that each closure above has an interpretation that is revealing about the
attribute(s) on the left-hand-side. The closure of { Classid } + is the entire
relation CLASS indicating that all attributes of the relation can be determined
from Classid and hence it is a key.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15 - 15


1.2 Equivalence of Sets of FDs
◼ Two sets of FDs F and G are equivalent if:
◼ Every FD in F can be inferred from G, and
◼ Every FD in G can be inferred from F
◼ Hence, F and G are equivalent if F+ =G+
◼ Definition (Covers):
◼ F covers G if every FD in G can be inferred from F
◼ (i.e., if G+ subset-of F+)
◼ F and G are equivalent if F covers G and G covers F
◼ There is an algorithm for checking equivalence of sets of
FDs

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15 - 16


1.3 Finding Minimal Cover of F.D.s (1)
◼ Just as we applied inference rules to expand on a set F of
FDs to arrive at F+, its closure, it is possible to think in the
opposite direction to see if we could shrink or reduce the
set F to its minimal form so that the minimal set is still
equivalent to the original set F.
◼ Definition: An attribute in a functional dependency is
considered extraneous attribute if we can remove it
without changing the closure of the set of dependencies.
Formally, given F, the set of functional dependencies and
a functional dependency X → A in F , attribute Y is
extraneous in X if Y is a subset of X, and F logically
implies (F- (X → A)  { (X – Y) → A } )

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15 - 17


Canonical Cover Of Functional Dependency
◼ In any relational model, there exists a set of functional dependencies
that, when closely observed might contain redundant attributes.
◼ The ability to remove these redundant attributes without affecting the
capabilities of the functional dependency is known as the “Canonical
Cover of Functional Dependency” or “Minimal Cover”.
◼ There are three steps to calculate the canonical cover for a relational
schema having a set of functional dependencies.
1. Decompose the functional dependencies using the Decomposition
rule(Armstrong’s Axiom) i.e. single attribute on the right-hand side.
2. Remove extraneous attributes from LHS of functional dependencies by
calculating the closure of FD’s having two or more attributes on LHS.
3. Remove FD’s having transitivity.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 18


Minimal Sets of FDs (2)
◼ A set of FDs is minimal if it satisfies the following
conditions:
1. Every dependency in F has a single attribute for its
RHS.
2. We cannot remove any dependency from F and have
a set of dependencies that is equivalent to F.
3. We cannot replace any dependency X → A in F with
a dependency Y → A, where Y is a proper subset of
X and still has a set of dependencies that is
equivalent to F.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15 - 19


Minimal Cover Example 1
◼ Consider a relation R(A,B,C,D) having some attributes, and below are
mentioned functional dependencies.
◼ FD1 : B→ A
◼ FD2 : AD→C
◼ FD3 : C→ ABD
1. Step 1: Decompose the functional dependencies using the
Decomposition rule(Armstrong’s Axiom) i.e. single attribute on the R.H.S
FD1: B→A
FD2: AD→C
FD3: C→A
FD4: C→B
FD5: C→D

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 20


Minimal Cover Example 1
◼ Consider a relation R(A,B,C,D) having some attributes, and below are
mentioned functional dependencies.
◼ FD1 : B→ A
◼ FD2 : AD→C
◼ FD3 : C→ ABD
2. Step 2: Remove extraneous attributes from LHS of FDs by calculating the
closure of FDs having two or more attributes on LHS.
Here, only one FD has two or more attributes of LHS i.e. AD→C.
{A}+ = {A}
{D}+ = {D}
In this case, attribute “A” can only determine “A” and “D” can only determine
“D”. Hence, no extraneous attributes are present and the FD will remain the
same and will not be removed.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 21


Minimal Cover Example 1
3. Step 3: Remove FD’s having transitivity.
FD1 : B→A
FD2 : C→A
• FD1, FD2 and FD3 are forming transitive pair.
FD3 : C→B
• Hence, using Armstrong’s law of transitivity i.e.
FD4 : AD→C if X→Y, Y → X then X → Z should be removed.
FD5 : C→D
◼ Therefore, we will have the following FDs left :
FD1: B→A
FD2: C → B
FD3: AD → C
FD4 : C → D
◼ Also, FD2 and FD4 can be combined together, canonical cover of the
relation R(A,B,C,D) will be:
Mc {R(ABCD)} = {B→A , C → BD, AD → C}
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 22
Minimal Sets of FDs (3)
◼ Algorithm 15.2. Finding a Minimal Cover F for a Set of Functional
Dependencies E
◼ Input: A set of functional dependencies E.

1. Set F:=E.
2. Replace each functional dependency X → {A1, A2, ..., An} in F by
the n functional dependencies X →A1, X →A2, ..., X → An.
3. For each functional dependency X → A in F
for each attribute B that is an element of X
if { {F – {X → A} } ∪ { (X – {B} ) → A} } is equivalent to F
then replace X → A with (X – {B} ) → A in F.
(* The above constitutes a removal of the extraneous
attribute B from X *)
4. For each remaining functional dependency X → A in F if {F – {X → A}
} is equivalent to F, then remove X → A from F.
(* The above constitutes a removal of the redundant dependency
X → A from F *)

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 23


Computing the Minimal Sets of FDs using
algorithm 15.2
We illustrate algorithm 15.2 with the following:
Let the given set of FDs be E : {B → A, D → A, AB → D}.We have to find the minimum
cover of E.
■ All above dependencies are in canonical form; so we have completed step 1
of Algorithm 10.2 and can proceed to step 2. In step 2 we need to determine
if AB → D has any redundant attribute on the left-hand side; that is, can it be
replaced by B → D or A → D?
■ Since B → A, by augmenting with B on both sides (IR2), we have BB → AB, or
B → AB (i). However, AB → D as given (ii).
■ Hence by the transitive rule (IR3), we get from (i) and (ii), B → D. Hence
AB → D may be replaced by B → D.
■ We now have a set equivalent to original E , say E′ : {B → A, D → A, B → D}.
No further reduction is possible in step 2 since all FDs have a single attribute
on the left-hand side.
■ In step 3 we look for a redundant FD in E′. By using the transitive rule on
B → D and D → A, we derive B → A. Hence B → A is redundant in E’ and can
be eliminated.
■ Hence the minimum cover of E is {B → D, D → A}.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 24


Minimal Sets of FDs (5)

◼ Every set of FDs has an equivalent minimal set


◼ There can be several equivalent minimal sets
◼ There is no simple algorithm for computing a
minimal set of FDs that is equivalent to a set F of
FDs. The process of Algorithm 15.2 is used until
no further reduction is possible.
◼ To synthesize a set of relations, we assume that
we start with a set of dependencies that is a
minimal set
◼ E.g., see algorithm 15.4
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 25
Alternate Method
◼ Suppose a relation R with attributes W,X,Y,Z i.e., R(W,X,Y,Z) with FDs:
FD1: X→W
FD2: WZ→XY
FD3: Y→WXZ
◼ Reduce the FDs on the R.H.S to a single attribute.
FD1: X→W
FD2: WZ→X
FD3: WZ→Y
FD4: Y→W
FD5: Y→X
FD5: Y→Z

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 26


Alternate Method
◼ Identify the redundant/non-essential dependencies from FD1 to FD6.
◼ Compute closure of attributes and if redundancy is found remove it
X+=X,W
FD1: X→W
◼ Retaking the X+ by ignoring FD1 (if it is redundant then the presence FD2: WZ→X
and absence does not affect X+ FD3: WZ→Y
FD4: Y→W
◼ But if it is changing it means the FD is essential, not redundant
FD5: Y→X
Now X+=X (ignoring FD1) FD6: Y→Z
◼ Compute WZ+: WZ+=WZXY
◼ Ignoring FD2: WZ+=WZYX (FD2 is redundant)
FD1: X→W
◼ Ignoring FD3: WZ+=WZ (FD3 is essential) FD2: WZ→X
◼ Now compute Y+:Y+= YWXZ FD3: WZ→Y
FD4: Y→W
◼ Ignoring FD4: Y+= YXZW (redundant, so remove it) FD5: Y→X
◼ Again, computing Y+= YZ (ignoring FD5) essential FD6: Y→Z
◼ Again, computing Y+= YXW (ignoring FD6) essential

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 27


Alternate Method
◼ There is no redundancy on the R.H.S because all attributes are atomic
◼ There are multiple attributes on the L.H.S which WZ
◼ Retaking the closure of WZ+ = WZYZ FD1: X→W
FD3: WZ→Y
◼ Ignoring FD3, taking closure of W+=W FD5: Y→X
+
Ignoring FD3, taking closure of Z =Z
◼ FD6: Y→Z
◼ No redundancy so Z is essential
◼ If we get the same result as the one highlighted in yellow when taking W+ and
Z+ either both W and Z or both are redundant
◼ There is a redundant value of Z
◼ So, the minimal set FDs are:
X→W
WZ→Y
Y→XZ

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 15- 28

You might also like