You are on page 1of 17

Functional dependencies

Hemani Parikh
Lecturer, CE dept.,BIT
Informal Design Guidelines for
relation schemas
• Semantics of the relation attributes
– Design a relation schema so that it is easy to explain
its meaning. Do not combine attributes from multiple
entity types and relationship types into a single
relation.
• Redundant information in tuples and update
anomalies
– Design base relation schema with no anomalies, if any
are present, note them clearly and make sure that the
programs that update the database will operate
correctly.
Informal Design Guidelines for
relation schemas
• Null values in tuples
– As far as possible, avoid placing attributes in a base
relation whose values may frequently be null.
• Generation of spurious tuples
– Design relation schemas so that they can be joined
with equality conditions on attributes that are either
primary keys or foreign keys in a way that guarantees
that no spurious tuples are generated. Avoid relations
that contain matching attributes that are not (foreign
key, primary key) combinations, because joining on
such attributes may produce spurious tuples.
Tables:
• Employee:
– Ename, ssn, bdate, address, dnumber
• Department:
– Dname, dnumber, dmgrssn (fk)
• Dept_locations
– Dnumber (fk), dlocation
• Project
– Pname, pnumber, plocation, dnumber(fk)
• Works_on:
– Ssn(fk), pnumber(fk), hours
Tables:
• Emp_dept:
– Ename, ssn, bdate, address, dnumber, dname,
dmgrssn
• Emp_proj:
– Ssn, pnumber, hours, ename, pname, plocation
• Emp_locs:
– Ename, plocation
• Emp_proj1:
– Ssn, pnumber, hours, pname, plocation
Function dependencies
• Definition:
– A functional dependency, denoted by X Y, between
two sets of attributes X and Y that are subsets of R
specifies a constraint on the possible tuples that can
form a relation r of R. The constraint is that, for any
two tuples t1 and t2 in r that have t1[X]=t2[X], they must
also have t1[Y]=t2[Y]
– K is a superkey of R, if KR, i.e if t1[K]=t2[K] for any
two tuples t1 and t2, then, t1[R]=t2[R].
– FD specifies constraints that we cannot express with
superkeys.
Example
A B C D
a1 b1 c1 d1

a1 b2 c1 d2

a2 b2 c2 d2

a2 b3 c2 d3

a3 b3 c2 d4
Inference Rules for Functional
Dependencies
• An FD X Y is inferred from a set of dependencies F
specified on R if X Y holds in every legal relation r of
R, that is whenever r satisfies all dependencies in F,
XY also holds in r.
• 1 – reflexive rule – if Y is subset of X, then XY
• 2 – augmentation rule – XY implies XZYZ
• 3 – transitive rule – XY, YZ, then XZ
• 4 – decomposition or projective rule – XYZ then XY
and XZ
• 5 – union or additive rule – XY, XZ then XYZ
• 6 - Self-determination rule – AA
• 7 – composition rule – If XY and WZ then XWYZ
• 8 – pseudotransitive rule – XY, WYZ, WXZ
Trivial and non-trivial FDs
• IR1 generates dependencies that are
always true, such dependencies are called
trivial; formally, if Y is a subset of X then
FD XY is trivial otherwise it is non-trivial.
Inference Rules for Functional
Dependencies
• IR1 to IR3 – Armstrong’s Axioms - sound and complete
rules
• Sound – do not generate any incorrect FDs
• Complete – for a given set F of FDs, they allow us to
generate all F+.
• Set of dependencies that include F as well as all
dependencies that can be inferred from F, is called the
closure of F; denoted by F+.
• To determine additional FDs, first determine each set of
attributes X that appears as a left-hand side of some
functional dependency in S and then to determine set of
all attributes that are dependent of X, i.e closure of X
under S, X+.
Closure of functional dependency
• Algo : Compute F+

F+=F;
repeat
for each functional dependency f in F+
apply reflexivity and augmentation rules on f
add the resulting functional dependencies to
F+
for each pair of functional dependencies f1 and f2 in F+
if f1 and f2 can be combined using transitivity
add the resulting functional dependency to F+
until F+ does not change any further
Closure of set of attributes
• Algo: compute X+
result:=X;
while (changes to result) do
for each functional dependency YZ in F do
begin
if Y is subset of result then result :=
result U Z;
end

– It gives us an alternative way to compute F+: for each A subset


of R, we find the closure A+, and for each B subset of A+, we
output a functional dependency A B.
Equivalence sets of FDs
• A set of functional dependencies F is said to cover
another set of functional dependencies E if every FD in E
is also in F+; i.e if every dependency in E can be inferred
from F; it can be said as E is covered by F.

• Two sets of FDs E and F are equivalent if E+ = F+ ; i.e E


covers F and F covers E.

• If F and E are equivalent, then if the DBMS enforces the


FDs in F will automatically be enforcing the FDs in E,
and vice versa.
Irreducible set of FDs
• A set F of FDs to be irreducible if and only if it satisfies
the following three properties:

– The right-hand side (dependent) of every FD in F involves just


one attribute (i.e it is a singleton set).

– The left-hand side (the determinant) of every FD in F is


irreducible in turn – meaning that no attribute can be discarded
from the determinant without changing the closure F+ ( i.e.
without converting F into some set not equivalent to F). We will
say that such an FD is left-irreducible.

– No FD in F can be discarded from F without changing the


closure F+ .
Canonical Cover
• To minimize the number of functional
dependencies that need to be tested in
case of an update to the database we may
restrict a set of functional dependencies F
to a canonical cover Fc.
• Canonical cover of F is a minimum set of
functional dependencies that is equivalent
to F.
Canonical Cover
• Consider a set F of functional dependencies and
the functional dependency α → β in F.
• Attribute A is extraneous in α if A belongs to α
and F logically implies (F – {α → β}) U {(α – A)
→ β}.
• Attribute A is extraneous in β if A belongs to β
and the set of functional dependencies (F – {α
→ β}) U {α →(β – A)} logically implies F.
Testing if an Attribute is
Extraneous
• Consider a set F of functional dependencies and
the functional dependency α → β in F.
• To test if attribute A belongs to α is extraneous
in α
– compute ({α} – A)+ using the dependencies in F
– check that ({α} – A)+ contains β; if it does, A is
extraneous
• To test if attribute A belongs to β is extraneous
in β
– compute α+ using only the dependencies in F’ = (F –
{α → β}) U {α →(β – A)},
– check that α+ contains A; if it does, A is extraneous

You might also like