lec 7
lec 7
Functional Dependencies
• Consider the whole database as being described by a single universal relation schema
R = {A1, A2, ... , An} has n attributes A1, A2, ...,An.
• Constraint : For all pairs of tuples t1 and t2 in r that have t1[X] = t2[X], they must also
have t1[Y] = t2[Y].
• The set of attributes X is called the left-hand side of the FD, and Y is called the right-
hand side.
Example
• Let us consider the relation r, to see which functional dependencies are satisfied.
• Similarly, the two tuples with an A value of a2 have the same C value, c2.
• There are no other pairs of distinct tuples that have the same A value.
• Observe that there is no pair of distinct tuples t1 and t2 such that t1[AB] = t2[AB].
• So, r satisfies AB → D.
b3
Functional Dependency
• Consider the relation schema EMP_PROJ; the following functional dependencies should
hold:
a. Ssn→Ename
b. Pnumber →{Pname, Plocation}
c. {Ssn, Pnumber}→Hours
• These functional dependencies specify that:
– (a) the value of an employee’s Social Security number (Ssn) uniquely determines
the employee name (Ename), alternatively,we say that Ename is functionally
determined by (or functionally dependent on) Ssn.
– (b) the value of a project’s number (Pnumber) uniquely determines the project
name (Pname) and location (Plocation), and
– (c) a combination of Ssn and Pnumber values uniquely determines the number of
hours the employee currently works on the project per week (Hours).
Diagrammatic Notation for FDs
Trivial Functional Dependency
• Some functional dependencies are said to be trivial because they are satisfied by
all relations.
• We see that, for all tuples t1 and t2 such that t1[A] = t2[A], it is the case that t1[A]
= t2[A].
• The following six rules IR1 through IR6 are well-known inference rules for
functional dependencies:
• Inference rules IR1 through IR3 are known as Armstrong’s inference rules.
Inferred Functional Dependency
• Let F denote the set of functional dependencies that are specified on relation
schema R.
• Typically, the schema designer specifies the functional dependencies that are
semantically obvious.
• This is an inferred FD and need not be explicitly stated in addition to the two given
FDs.
Closure of FD
• Formally, the set of all dependencies that include F as well as all dependencies
that can be inferred from F is called the closure of F; it is denoted by F+.
• Some of the additional functional dependencies that we can infer from F are the
following:
– Ssn → Ssn
– Dnumber → Dname
attributes of R.
contains β.
Example
• Consider the schema R = (A, B, C, G, H, I) and the set F of functional dependencies:
• F={A → B, A → C, CG → H, CG → I, B → H} and
• Solution:
• AG+= AG
• Consider the FD B->H, here B ⊆ AG+ thus AG+ = AGBCHI ∪ H=AGBCHI(old AG+)
• That is, if every dependency in E can be inferred from F; alternatively, we can say
that E is covered by F.
• Therefore, equivalence means that every FD in E can be inferred from F, and every
FD in F can be inferred from E;
• That is, E is equivalent to F if both the conditions- E covers F and F covers E- hold.
– F = {A → C, AC → D, E → AD, E → H}
– G = {A → CD, E → AH}
– F = {A → C, AC → D, E → AD, E → H}
– G = {A → CD, E → AH}.
– Here CD ⊆ A+
– Here AH ⊆ E+
• Thus F covers G.
Equivalence of Sets of Functional
Dependencies
– F = {A → C, AC → D, E → AD, E → H}
– G = {A → CD, E → AH}.
• Determining whether G covers F
– A+ = { A C D } // closure of left side of A → C w.r.t. set G
– Here C ⊆ A+
– (AC)+= { A C D } // closure of left side of AC → D w.r.t. set G
– Here D ⊆ (AC)+
– E+= { E A C D H } // closure of left side of E → AD w.r.t. set G
– Here AD ⊆ E+
– E+= { E A C D H } // closure of left side of E → H w.r.t. set G
– Here H ⊆ E+
– Thus G covers F.
– It means both F and G are equivalent.
Extraneous attributes
• An attribute of a functional dependency is said to be extraneous if we can remove
it without changing the closure of the set of functional dependencies.
F’ = (F – {α → β}) U { α → (β – A) }.
F’ = (F – {α → β}) U { α → (β – A) }.
• F’ = ({Q→ R} U {P→Q})
• F’ = {Q→R, P→Q}
1. Set K := R.
Note: This algorithm determines only one key out of the possible candidate keys
for R; the key returned depends on the order in which attributes are removed
from R in step 2.
Finding Key Attribute
• Determine all essential attributes of the given relation.
• Essential attributes are those attributes which are not present on RHS of any
functional dependency.
• Case-1:
• If all essential attributes together can not determine all remaining non-essential
attributes, then-
– The set of essential attributes and some non-essential attributes will be the
candidate key(s).
• Note: In general, if we have ‘N’ attributes with one candidate key then the
number of possible super keys is 2(N – (size of candidate key)).
Example
• Ex1. Let R = (A, B, C, D, E, F) be a relation scheme with the following dependencies- F={
C → F, E → A, EC → D, A → B } Find the candidate key(s). How many possible super keys
are there?
• Solution:
• Essential attributes of the relation are- C and E.
• So, attributes C and E will definitely be a part of every candidate key.
• { CE }+
={C,E}
= { C , E , F } ( Using C → F )
= { A , C , E , F } ( Using E → A )
= { A , C , D , E , F } ( Using EC → D )
= { A , B , C , D , E , F } ( Using A → B )
Thus CE is the only possible candidate key of the relation.
Example
• As number of possible super keys is 2(N – (size of candidate key))
Solution:
• { AB }+
= { A,B,C,D,E }
• Solution:
• { EFH }+
• = { EFGHIJKLMN }
• Solution:
• In addition, this property is lost if any dependency from the set F is removed;
• Whenever a user performs an update on the relation, the database system must
ensure that the update does not violate any functional dependencies,
• That is, all the functional dependencies in F are satisfied in the new database
state.
• The system must roll back the update if it violates any functional dependencies in
the set F.
• We can reduce the effort spent in checking for violations by testing a simplified
set of functional dependencies that has the same closure as the given set.
Minimal Cover
• Formal definition of minimal cover:
• A Canonical cover Fc for F is a set of dependencies such that F logically implies all
dependencies in Fc, and Fc logically implies all dependencies in F.
• repeat
– /* Note: the test for extraneous attributes is done using Fc, not F */
Solution:
• Fc= {A →BC, B → C, AB → C}
• Is B extraneous in AB → C?
• Is A extraneous in AB → C?
• F’ = B → C, A → C
• Is C extraneous in A →BC?
• F’ = B → C, A → B
• A+ = ABC contains C thus C is extraneous, remove C from A →BC which becomes A→B