SlideShare a Scribd company logo
1 of 69
Download to read offline
Database System Concepts, 7th Ed.
©Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Chapter 7: Normalization
Database Management Systems
Course Code: CSE309
2022
©Silberschatz, Korth and Sudarshan
7.2
Database System Concepts - 7th Edition
Course Teacher
Dr. Mrinal Kanti Baowaly
Associate Professor
Department of Computer Science
and Engineering, Bangabandhu
Sheikh Mujibur Rahman Science
and Technology University,
Bangladesh.
Email: baowaly@gmail.com
©Silberschatz, Korth and Sudarshan
7.3
Database System Concepts - 7th Edition
Outline
 Features of Good Relational Design
 Functional Dependencies
 Decomposition Using Functional Dependencies
 Normal Forms
 Functional Dependency Theory
 Algorithms for Decomposition using Functional Dependencies
 Decomposition Using Multivalued Dependencies
 More Normal Form
 Atomic Domains and First Normal Form
 Database-Design Process
 Modeling Temporal Data
©Silberschatz, Korth and Sudarshan
7.5
Database System Concepts - 7th Edition
Features of Good Relational Designs
 Suppose we combine instructor and department into in_dep, which
represents the natural join on the relations instructor and department
 There is repetition of information, e.g., department information (“building”
and “budget”). It creates data inconsistency.
 Need to use null values (if we add a new department with no instructors)
©Silberschatz, Korth and Sudarshan
7.6
Database System Concepts - 7th Edition
Decomposition
 The only way to avoid the repetition-of-information problem in the in_dep
schema is to decompose it into two schemas – instructor and department
schemas.
instructor(ID, name, dept name, salary)
department(dept_name, building, budget)
 Not all decompositions are good. Suppose we decompose
employee(ID, name, street, city, salary)
into
employee1 (ID, name)
employee2 (name, street, city, salary)
The problem arises when we have two employees with the same name
 The next slide shows how we lose information -- we cannot reconstruct
the original employee relation -- and so, this is a lossy decomposition.
©Silberschatz, Korth and Sudarshan
7.7
Database System Concepts - 7th Edition
A Lossy Decomposition
Notice that the two
original tuples appear
in the result along with
two new tuples that
incorrectly mix data
values pertaining to the
two employees named
Kim.
©Silberschatz, Korth and Sudarshan
7.8
Database System Concepts - 7th Edition
Lossless Decomposition
 Let R be a relation schema and let R1 and R2 form a decomposition of R .
That is R = R1 U R2
 We say that the decomposition is a lossless decomposition if there is
no loss of information by replacing R with the two relation schemas R1
U R2
 Formally,
 R1
(r)  R2
(r) = r
 And, conversely a decomposition is lossy if
r   R1
(r)  R2
(r)
©Silberschatz, Korth and Sudarshan
7.9
Database System Concepts - 7th Edition
Example of Lossless Decomposition
 Decomposition of R = (A, B, C)
R1 = (A, B) R2 = (B, C)
©Silberschatz, Korth and Sudarshan
7.10
Database System Concepts - 7th Edition
Normalization Theory
 Normalization is the process of organizing data in a database to ensure
that each relation is in good form.
 In the case that a relation R is not in “good” form, decompose it into set
of relations {R1, R2, ..., Rn} such that
• Each relation is in good form
• The decomposition is a lossless decomposition
 Normalization helps to reduce data redundancy and eliminates
undesirable characteristics like insertion, deletion, and update anomalies
in a database.
©Silberschatz, Korth and Sudarshan
7.11
Database System Concepts - 7th Edition
Normalization (Cont.)
 There are a few rules for database normalization. Each rule is called a
"normal form." These normal forms are:
• First Normal Form (1NF)
• Second Normal Form (2NF)
• Third Normal Form (3NF)
• Boyce-Codd Normal Form (BCNF)
• Fourth Normal Form (4NF) etc.
 If the first rule is observed, the relation is said to be in "first normal form."
If the first three rules are observed, the relation is considered to be in
"third normal form.“
 Normalization theory is based on:
• Functional dependencies
• Multivalued dependencies
©Silberschatz, Korth and Sudarshan
7.12
Database System Concepts - 7th Edition
Functional Dependencies
 There are usually a variety of constraints (rules) on the data in the real
world.
 For example, some of the constraints that are expected to hold in a
university database are:
• Students and instructors are uniquely identified by their ID.
• Each student and instructor has only one name.
• Each instructor and student is (primarily) associated with only one
department.
• Each department has only one value for its budget, and only one
associated building.
©Silberschatz, Korth and Sudarshan
7.13
Database System Concepts - 7th Edition
Functional Dependencies Definition
 Let R be a relation schema
  R and   R
 The functional dependency    holds on R if and only if for any legal
relations r(R), whenever any two tuples t1 and t2 of r agree on the attributes
, they also agree on the attributes . That is,
t1[] = t2 []  t1[ ] = t2 [ ]
 Alternative Definition: A functional dependency A->B in a relation holds if
two tuples having same value of attribute A also have same value for
attribute B.
 Example: Consider r(A,B ) with the following instance of r.
 On this instance, A  B does NOT hold, but B  A does hold.
A B
1 4
1 5
3 7
3 7
©Silberschatz, Korth and Sudarshan
7.14
Database System Concepts - 7th Edition
Closure of a Set of Functional Dependencies
 Given a set F set of functional dependencies, there are certain other
functional dependencies that are logically implied by F.
• If A  B and B  C, then we can infer that A  C
• etc.
 The set of all functional dependencies logically implied by F is the
closure of F.
 We denote the closure of F by F+
.
©Silberschatz, Korth and Sudarshan
7.15
Database System Concepts - 7th Edition
Keys and Functional Dependencies
 K is a superkey for relation schema R if and only if K  R
 K is a candidate key for R if and only if
• K  R, and
• for no   K,   R
 Functional dependencies allow us to express constraints that cannot be
expressed using superkeys. Consider the schema:
in_dep (ID, name, salary, dept_name, building, budget ).
We expect these functional dependencies to hold:
dept_name building
ID  building
but would not expect the following to hold:
dept_name  salary
©Silberschatz, Korth and Sudarshan
7.16
Database System Concepts - 7th Edition
Use of Functional Dependencies
 We use functional dependencies to:
• To test relations to see if they are legal under a given set of
functional dependencies.
 If a relation r is legal under a set F of functional dependencies,
we say that r satisfies F.
• To specify constraints on the set of legal relations
 We say that F holds on R if all legal relations on R satisfy the set
of functional dependencies F.
 Note: A specific instance of a relation schema may satisfy a functional
dependency even if the functional dependency does not hold on all legal
instances.
• For example, a specific instance of instructor may, by chance, satisfy
name  ID.
©Silberschatz, Korth and Sudarshan
7.17
Database System Concepts - 7th Edition
Trivial Functional Dependencies
 A functional dependency is trivial if it is satisfied by all instances of a
relation
 Example:
• ID, name  ID
• name  name
 In general,    is trivial if   
©Silberschatz, Korth and Sudarshan
7.18
Database System Concepts - 7th Edition
Lossless Decomposition
 We can use functional dependencies to show when certain
decomposition are lossless.
 For the case of R = (R1, R2), we require that for all possible relations r on
schema R
r = R1 (r ) R2 (r )
 A decomposition of R into R1 and R2 is lossless decomposition if at least
one of the following dependencies is in F+:
• R1  R2  R1
• R1  R2  R2
 The above functional dependencies are a sufficient condition for lossless
join decomposition; the dependencies are a necessary condition only if all
constraints are functional dependencies
©Silberschatz, Korth and Sudarshan
7.19
Database System Concepts - 7th Edition
Lossless Decomposition (Example)
 R = (A, B, C)
F = {A  B, B  C)
 R1 = (A, B), R2 = (B, C)
• Lossless decomposition: if R1  R2  R1 or R1  R2  R2
R1  R2 = {B}
Check if B  AB or B  BC
Since B  C, therefore B  BC and the decomposition is
lossless
 R1 = (A, B), R2 = (A, C)
• Lossless decomposition: if R1  R2  R1 or R1  R2  R2
R1  R2 = {A}
Check if A  AB or A  BC
Since A  B, therefore A  AB and the decomposition is
lossless
©Silberschatz, Korth and Sudarshan
7.20
Database System Concepts - 7th Edition
Dependency Preservation
 Testing functional dependency constraints each time the database is
updated can be costly
 It is useful to design the database in a way that constraints can be
tested efficiently.
 If testing a functional dependency can be done by considering just one
relation, then the cost of testing this constraint is low
 When decomposing a relation it is possible that it is no longer possible
to do the testing without having to perform a Cartesian Produced.
 A decomposition that makes it computationally hard to enforce
functional dependency is said to be NOT dependency preserving.
©Silberschatz, Korth and Sudarshan
7.21
Database System Concepts - 7th Edition
Dependency Preservation Example
 Consider a schema:
dept_advisor(s_ID, i_ID, department_name)
 With function dependencies:
i_ID  dept_name
s_ID, dept_name  i_ID
 In the above design we are forced to repeat the department name once
for each time an instructor participates in a dept_advisor relationship.
 To fix this, we need to decompose dept_advisor
 Any decomposition will not include all the attributes in
s_ID, dept_name  i_ID
 Thus, the composition NOT be dependency preserving
©Silberschatz, Korth and Sudarshan
7.22
Database System Concepts - 7th Edition
Dependency Preservation (Example)
 R = (A, B, C)
F = {A  B, B  C)
 R1 = (A, B), R2 = (B, C)
• Lossless-join decomposition:
R1  R2 = {B} and
R1  R2  R2 i.e. B  BC holds because B  C
• Dependency preserving
 R1 = (A, B), R2 = (A, C)
• Lossless-join decomposition:
R1  R2 = {A} and
R1  R2  R1 i.e. A  AB holds because A  B
• Not dependency preserving
(cannot check B  C without computing R1 R2)
©Silberschatz, Korth and Sudarshan
7.24
Database System Concepts - 7th Edition
First Normal Form
 A relational schema R is in first normal form (1NF) if the domains of all
attributes of R are atomic
 A domain is atomic if elements of the domain are considered to be
indivisible units.
 In other words, a relational schema R is in 1NF if it does not contain any
multi-valued and composite attributes.
 Non-atomic values complicate storage and encourage redundant
(repeated) storage of data.
 Example 1: If a relation student includes an attribute course whose domain
elements are sets of course names (multi-valued attribute), the relation
would not be in first normal form.
Solution: Put a single value for each attribute cell
 Example 2: If a relation has an composite attribute, such as an address
with component attributes street, city, state, and zip; the relation would not
be in first normal form.
Solution: Create a separate attribute for each subpart of the composite
attribute.
©Silberschatz, Korth and Sudarshan
7.25
Database System Concepts - 7th Edition
First Normal Form (Example)
student_id name Course
S01 Tuhin Word, Excel, Access
S02 Shuvro PowerPoint, Outlook
Unnormalized table
Normalized table in 1NF
student_id Name Course
S01 Tuhin Word
S01 Tuhin Excel
S01 Tuhin Access
S02 Shuvro PowerPoint
S02 Shuvro Outlook
©Silberschatz, Korth and Sudarshan
7.26
Database System Concepts - 7th Edition
Second Normal Form
 A relational schema R is in second normal form (2NF) if it is in 1NF and
all non-key attributes are fully functionally dependent on the (entire) primary
key.
 In other words, a relational schema R is in second normal form (2NF) if it is
in 1NF and must not contain any partial dependencies.
 A functional dependency X->Y is called a fully functional dependency if
an attribute Y is functionally dependent on an attribute X but not
functionally dependent on any proper subset of X.
 If the primary key is one attribute, then the relation automatically satisfies
2NF.
 When a relation has a composite primary key, a partial dependency may
occur if a non-key attribute is functionally dependent on any proper subset
of the primary key.
 2NF involves removing partial dependencies from R and creates a
separate table for each partial dependency, taking a note that one attribute
remains in the 1NF table as a foreign key to link the new table.
©Silberschatz, Korth and Sudarshan
7.27
Database System Concepts - 7th Edition
Second Normal Form (Example)
student_id project_id student_name project_name
S89 P09 Olivia Geo Location
S56 P07 Jacob Cluster Exploration
S56 P03 Jacob IoT Devices
S92 P05 Alexandra Cloud Deployment
Functional dependencies: student_id, project_id → student_name, project_name
student_id → student_name
project_id → project_name
student_id project_id
S89 P09
S56 P07
S56 P03
S92 P05
student_id student_name
S89 Olivia
S56 Jacob
S92 Alexandra
project_id project_name
P09 Geo Location
P07 Cluster Exploration
P03 IoT Devices
P05 Cloud Deployment
Unnormalized table
Normalized tables in 2NF
©Silberschatz, Korth and Sudarshan
7.28
Database System Concepts - 7th Edition
Decomposing a Schema
 Let R be a schema R that is not in 2NF. Let   be the FD that
causes a violation of 2NF.
 We decompose R into:
• ( U  )
• ( R - (  -  ) )
 In our example of in_dep (ID, name, salary, dept_name, building,
budget ), it holds:
dept_name  building, budget
•  = dept_name
•  = building, budget
and in_dep is replaced by
• ( U  ) = (dept_name, building, budget )
• ( R - (  -  ) ) = (ID, name, salary, dept_name)
©Silberschatz, Korth and Sudarshan
7.29
Database System Concepts - 7th Edition
Third Normal Form
 A relational schema R is in third normal form (3NF) if it is in 2NF and has
no transitive dependencies.
 A transitive dependency occurs when a non-key attribute depends on
another non-key attribute.
 3NF involves removing dependencies between non-key attributes in the
relation and creates a separate table for each such dependency. This
ensures the relation has no transitive dependencies.
 Example:
Course_id Instructor_id Instructor Course_topic
CSE101 001 MKB ML
CSE208 002 SA Database
CSE305 003 MNH NLP
CSE109 004 MMA DL
For the above relation, it holds:
Instructor_id  Instructor
Hence, there is a transitive dependency:
Course_id  Instructor_id, Instructor_id  Instructor
©Silberschatz, Korth and Sudarshan
7.30
Database System Concepts - 7th Edition
Third Normal Form (Example)
Course_id Instructor_id Instructor Course_topic
CSE101 001 MKB ML
CSE208 002 SA Database
CSE305 003 MNH NLP
CSE109 004 MMA DL
Normalized tables in 3NF
Unnormalized table in 3NF
Instructor_id Instructor
001 MKB
002 SA
003 MNH
004 MMA
Course_id Instructor_id Course_topic
CSE101 001 ML
CSE208 002 Database
CSE305 003 NLP
CSE109 004 DL
©Silberschatz, Korth and Sudarshan
7.31
Database System Concepts - 7th Edition
3NF Another Example
 Consider a schema:
dept_advisor(s_ID, i_ID, dept_name)
 With function dependencies:
i_ID  dept_name
s_ID, dept_name  i_ID
 Two candidate keys = {s_ID, dept_name}, {s_ID, i_ID }
 We have seen before that dept_advisor is not in BCNF
 R, however, is in 3NF
• s_ID, dept_name is a superkey
• i_ID  dept_name and i_ID is NOT a superkey, but:
 { dept_name} – {i_ID } = {dept_name } and
 dept_name is contained in a candidate key
©Silberschatz, Korth and Sudarshan
7.32
Database System Concepts - 7th Edition
Redundancy in 3NF
 Consider the schema R below, which is in 3NF
 What is wrong with the table?
• R = (J, K, L )
• F = {JK  L, L  K }
• And an instance table:
• Repetition of information
• Need to use null values (e.g., to represent the relationship l2, k2
where there is no corresponding value for J)
©Silberschatz, Korth and Sudarshan
7.33
Database System Concepts - 7th Edition
Advantages and Disadvantages to 3NF
 Advantages to 3NF.
• It is always possible to obtain a 3NF design without sacrificing
losslessness or dependency preservation.
 Disadvantages to 3NF.
• We may have to use null values to represent some of the possible
meaningful relationships among data items.
• There is the problem of repetition of information.
©Silberschatz, Korth and Sudarshan
7.34
Database System Concepts - 7th Edition
Goals of Normalization
 Let R be a relation scheme with a set F of functional dependencies.
 Decide whether a relation scheme R is in “good” form.
 In the case that a relation scheme R is not in “good” form, need to
decompose it into a set of relation scheme {R1, R2, ..., Rn} such that:
• Each relation scheme is in good form
• The decomposition is a lossless decomposition
• Preferably, the decomposition should be dependency preserving.
©Silberschatz, Korth and Sudarshan
7.35
Database System Concepts - 7th Edition
Boyce-Codd Normal Form
 A more restricted version of 3NF known as Boyce-Codd Normal Form
requires that the determinant of every functional dependency in a relation
is a candidate key.
 A relation schema R is in BCNF with respect to a set F of functional
dependencies if for all functional dependencies in F+ of the form
  
where   R and   R, at least one of the following holds:
•    is trivial (i.e.,   )
•  is a superkey for R
©Silberschatz, Korth and Sudarshan
7.36
Database System Concepts - 7th Edition
Boyce-Codd Normal Form (Cont.)
 Example schema that is not in BCNF:
in_dep (ID, name, salary, dept_name, building, budget )
because :
• dept_name building, budget
 holds on in_dep
 but dept_name is not a superkey
 When decompose in_dept into instructor (ID, name, salary, dept_name)
and department (dept_name, building, budget )
• instructor is in BCNF
• department is in BCNF
©Silberschatz, Korth and Sudarshan
7.37
Database System Concepts - 7th Edition
BCNF and Dependency Preservation
 It is not always possible to achieve both BCNF and dependency
preservation
 Consider a schema:
dept_advisor(s_ID, i_ID, department_name)
 With function dependencies:
i_ID  dept_name
s_ID, dept_name  i_ID
 dept_advisor is not in BCNF
• i_ID is not a superkey.
 Any decomposition of dept_advisor will not include all the attributes in
s_ID, dept_name  i_ID
 Thus, the composition is NOT be dependency preserving
©Silberschatz, Korth and Sudarshan
7.38
Database System Concepts - 7th Edition
Comparison of BCNF and 3NF
 It is always possible to decompose a relation into a set of relations that
are in 3NF such that:
• The decomposition is lossless
• The dependencies are preserved
 It is always possible to decompose a relation into a set of relations that
are in BCNF such that:
• The decomposition is lossless
• It may not be possible to preserve dependencies.
©Silberschatz, Korth and Sudarshan
7.39
Database System Concepts - 7th Edition
How good is BCNF?
 There are database schemas in BCNF that do not seem to be
sufficiently normalized
 Consider a relation
inst_info (ID, child_name, phone)
• where an instructor may have more than one phone and can have
multiple children
• Instance of inst_info
©Silberschatz, Korth and Sudarshan
7.40
Database System Concepts - 7th Edition
 There are no non-trivial functional dependencies and therefore the
relation is in BCNF
 Insertion anomalies – i.e., if we add a phone 981-992-3443 to 99999, we
need to add two tuples
(99999, David, 981-992-3443)
(99999, William, 981-992-3443)
How good is BCNF? (Cont.)
©Silberschatz, Korth and Sudarshan
7.41
Database System Concepts - 7th Edition
 It is better to decompose inst_info into:
• inst_child:
• inst_phone:
 This suggests the need for higher normal forms, such as Fourth
Normal Form (4NF), which we shall see later
Higher Normal Form
©Silberschatz, Korth and Sudarshan
7.42
Database System Concepts - 7th Edition
 A relation R is in 4NF if and only if it is in the Boyce-Codd Normal
Form (BCNF) and the relation should not have any multi-valued
dependency.
 A relation with a multi-valued dependency violates the normalization
standard of Fourth Normal Form (4NK) because it creates
unnecessary redundancies and can contribute to inconsistent data
 A table is said to have multi-valued dependency, if the following
conditions are true:
• For a dependency A → B, if for a single value of A, multiple value
of B exists, then the relation may have multi-valued dependency.
• Also, a relation should have at-least 3 columns for it to have a
multi-valued dependency.
• And, for a relation R(A,B,C), if there is a multi-valued dependency
between, A and B, then B and C should be independent of each
other.
 To make a relation satisfy the fourth normal form, we can decompose
the table.
Fourth Normal Form (4NF)
©Silberschatz, Korth and Sudarshan
7.43
Database System Concepts - 7th Edition
Fourth Normal Form (Example)
Student_id Name Course
S01 Tuhin Word
S01 Tuhin Excel
S01 Tuhin Access
S02 Shuvro PowerPoint
S02 Shuvro Outlook
Not in 4NF
Student_id  Course
Student_id Course
S01 Word
S01 Excel
S01 Access
S02 PowerPoint
S02 Outlook
Student_id Name
S01 Tuhin
S02 Shuvro
Normalized tables in 4NF
©Silberschatz, Korth and Sudarshan
7.45
Database System Concepts - 7th Edition
Functional-Dependency Theory Roadmap
 We now consider the formal theory that tells us which functional
dependencies are implied logically by a given set of functional
dependencies.
 We then develop algorithms to generate lossless decompositions into
BCNF and 3NF
 We then develop algorithms to test if a decomposition is dependency-
preserving
©Silberschatz, Korth and Sudarshan
7.46
Database System Concepts - 7th Edition
Closure of a Set of Functional Dependencies
 Given a set F set of functional dependencies, there are certain other
functional dependencies that are logically implied by F.
• If A  B and B  C, then we can infer that A  C
• etc.
 The set of all functional dependencies logically implied by F is the closure
of F.
 We denote the closure of F by F+
.
©Silberschatz, Korth and Sudarshan
7.47
Database System Concepts - 7th Edition
Closure of a Set of Functional Dependencies
 We can compute F+, the closure of F, by repeatedly applying Armstrong’s
Axioms:
• Reflexive rule: if   , then   
• Augmentation rule: if   , then     
• Transitivity rule: if   , and   , then   
 These rules are
• Sound -- generate only functional dependencies that actually hold,
and
• Complete -- generate all functional dependencies that hold.
©Silberschatz, Korth and Sudarshan
7.48
Database System Concepts - 7th Edition
Example of F+
 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
 by augmenting CG  I to infer CG  CGI,
and augmenting of CG  H to infer CGI  HI,
and then transitivity
©Silberschatz, Korth and Sudarshan
7.49
Database System Concepts - 7th Edition
Closure of Functional Dependencies (Cont.)
 Additional rules:
• Union rule: If    holds and    holds, then     holds.
• Decomposition rule: If     holds, then    holds and  
 holds.
• Pseudotransitivity rule:If    holds and     holds, then
   holds.
 The above rules can be inferred from Armstrong’s axioms.
• Union rule: by augmenting    with , we get    and
by augmenting    with , we get     and
then using transitivity we have    
• Decomposition rule: we have    , and using reflexivity we
get     and    , and then using transitivity it infers:
   and   
• Pseudotransitivity rule: by augmenting    with , to get  
  and then transitivity with   , we have   
©Silberschatz, Korth and Sudarshan
7.50
Database System Concepts - 7th Edition
Procedure for Computing F+
 To compute the closure of a set of functional dependencies 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 f1and f2 in F +
if f1 and f2 can be combined using transitivity
then add the resulting functional dependency to F +
until F + does not change any further
 NOTE: We shall see an alternative procedure for this task later
©Silberschatz, Korth and Sudarshan
7.51
Database System Concepts - 7th Edition
Closure of Attribute Sets
 Given a set of attributes , define the closure of  under F (denoted by
+) as the set of attributes that are functionally determined by  under F
 Algorithm to compute +, the closure of  under F
result := ;
while (changes to result) do
for each    in F do
begin
if   result then result := result  
end
©Silberschatz, Korth and Sudarshan
7.52
Database System Concepts - 7th Edition
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 = AG
2. result = ABCG (A  C and A  B)
3. result = ABCGH (CG  H and CG  AGBC)
4. result = ABCGHI (CG  I and CG  AGBCH)
 Is AG a candidate key?
1. Is AG a super key?
1. Does AG  R? == Is R  (AG)+
2. Is any subset of AG a superkey?
1. Does A  R? == Is R  (A)+
2. Does G  R? == Is R  (G)+
3. In general: check for each subset of size n-1
©Silberschatz, Korth and Sudarshan
7.53
Database System Concepts - 7th Edition
Uses of Attribute Closure
There 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.
©Silberschatz, Korth and Sudarshan
7.54
Database System Concepts - 7th Edition
Testing for Super Key and Candidate Key
 R = (A, B, C, G, H, I)
 F = {A  B
A  C
CG  H
CG  I
B  H}
 (AG)+
1. result = AG
2. result = ABCG (A  B and A  C and A  AG)
3. result = ABCGH (CG  H and CG  AGBC)
4. result = ABCGHI (CG  I and CG  AGBCH)
 Is AG a super key?
• (AG)+ = ABCGHI. AG is super key because (AG)+ contains all attributes
of R
 Is AG a candidate key?
• Start with computing the closure of single attributes in R
A+ = ABCH, B+ = BH, C+ = C, G+ = G, H+ = H, I+ = I
• No single attribute can contain all attributes of R, hence AG is candidate
key.
©Silberschatz, Korth and Sudarshan
7.55
Database System Concepts - 7th Edition
HW: Find Candidate Keys
 R = (A, B, C, D, E)
 F = {A  BC
C  B
D  E
E  D}
 List the candidate keys for R
©Silberschatz, Korth and Sudarshan
7.56
Database System Concepts - 7th Edition
Testing Functional Dependencies
 We are given R(A, B, C, D, E, F). The functional dependencies (FD) are:
{AB  C, BC  AD, D  E, CF  B}
 Check whether AB  DE can be derived from the given FD set.
 Solution: Compute (AB) +
1. result = AB
2. result = ABC (AB  C and AB  AB)
3. result = ABCD (BC  AD and BC  ABC)
4. result = ABCDE (D  E and D  ABCD)
Since DE  (AB) +, therefore AB  DE holds
Problem: Is AB a super key?
©Silberschatz, Korth and Sudarshan
7.57
Database System Concepts - 7th Edition
Testing Lossless Decomposition
 R = (A, B, C)
F = {A  B, B  C)
 R1 = (A, B), R2 = (B, C)
• Lossless decomposition: if R1  R2  R1 or R1  R2  R2
R1  R2 = {B}
Check if B  AB or B  BC holds
Since B+ = BC, BC  B+, therefore B  BC holds and the
decomposition is lossless
 R1 = (A, B), R2 = (A, C)
• Lossless decomposition: if R1  R2  R1 or R1  R2  R2
R1  R2 = {A}
Check if A  AB or A  BC holds
Since A+ = ABC, A is candidate key (or both AB  A+ and BC  A+),
therefore both A  AB and A  BC hold and the decomposition is
lossless
©Silberschatz, Korth and Sudarshan
7.58
Database System Concepts - 7th Edition
Computing F + Using Attribute Closure
 R = (A, B, C)
F = {A  B, B  C)
 Compute F+ (Consider only non-trivial functional dependencies)
• Start with computing the closure of single attributes in R
A+ = ABC, B+ = BC, C+ = C
FD: A  B, A  C, B  C
• Compute the closure of two attributes in R
(AB)+ = ABC, (BC)+ = BC, (AC)+ = ABC
FD: AB  C, AB  BC, AB  AC, AC  B, AC  AB, AC  BC
• F+ = {A  B, A  C, B  C, AB  C, AB  BC, AB  AC, AC  B, AC 
AB, AC  BC}
©Silberschatz, Korth and Sudarshan
7.59
Database System Concepts - 7th Edition
Canonical Cover
 Suppose that we have a set of functional dependencies F on a relation
schema. 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.
 If an update violates any functional dependencies in the set F, the system
must roll back the update.
 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.
 This simplified set is termed the canonical cover
 To define canonical cover we must first define extraneous attributes.
• An attribute of a functional dependency in F is extraneous if we can
remove it without changing F +
©Silberschatz, Korth and Sudarshan
7.60
Database System Concepts - 7th Edition
Extraneous Attributes
 An attribute of a functional dependency in F is extraneous if we can
remove it without changing F +
 Consider a set F of functional dependencies and the functional
dependency    in F.
• Remove from the left side: Attribute A is extraneous in  if
 A   and
 F logically implies (F – {  })  {( – A)  }.
• Remove from the right side: Attribute A is extraneous in  if
 A   and
 The set of functional dependencies
(F – {  })  { ( – A)} logically implies F.
©Silberschatz, Korth and Sudarshan
7.61
Database System Concepts - 7th Edition
Testing if an Attribute is Extraneous
 Let R be a relation schema and let F be a set of functional
dependencies that hold on R . Consider an attribute A in the functional
dependency   .
 To test if attribute A   is extraneous in 
• Consider the set:
F' = (F – {  })  { ( – A)},
• Check if   A can be inferred from F'
• To do so, compute + under F' ; if + includes A, then A is
extraneous in 
 To test if attribute A   is extraneous in 
• Let  =  – {A}. Check if    can be inferred from F.
• Compute + under F
• If + includes all attributes in  then , A is extraneous in 
©Silberschatz, Korth and Sudarshan
7.62
Database System Concepts - 7th Edition
Examples of Extraneous Attributes
 Let F = {AB  CD, A  E, E  C }
 To check if C is extraneous in AB  CD:
• Check if AB  CD can be inferred from F' = {AB  D, A  E, E  C}
• We compute the attribute closure of AB under F'
• (AB)+ = ABCDE, which includes CD
• This implies that C is extraneous
 Let F = {AB  C, A  C }
 To check if B is extraneous in AB  C:
• Check if A  C can be inferred from F = {AB  C, A  C}
• A  C is already in F
• This implies that B is extraneous
©Silberschatz, Korth and Sudarshan
7.63
Database System Concepts - 7th Edition
Canonical Cover
 F logically implies all dependencies in Fc , and
 Fc logically implies all dependencies in F, and
 No functional dependency in Fc contains an extraneous attribute, and
 Each left side of functional dependency in Fc is unique. That is, there
are no two dependencies in Fc
• 1  1 and 2  2 such that
• 1 = 2
A canonical cover for F is a set of dependencies Fc such that
©Silberschatz, Korth and Sudarshan
7.64
Database System Concepts - 7th Edition
Canonical Cover
 To compute a canonical cover for F:
Fc = F
repeat
Use the union rule to replace any dependencies in F of the form
1  1 and 1  2 with 1  1 2
Find a functional dependency    in Fc with an extraneous
attribute either in  or in 
/* Note: test for extraneous attributes done using Fc, not F*/
If an extraneous attribute is found, delete it from   
until Fc not change
 Note: Union rule may become applicable after some extraneous attributes
have been deleted, so it has to be re-applied
©Silberschatz, Korth and Sudarshan
7.65
Database System Concepts - 7th Edition
Example: Computing a Canonical Cover
 R = (A, B, C)
F = {A  BC
B  C
A  B
AB  C}
 Using union rule, combine A  BC and A  B into A  BC
• Set is now {A  BC, B  C, AB  C}
 A is extraneous in AB  C
• Check if B  C can be inferred from F = {A  BC, B  C, AB  C}
• B  C is already in F, this implies that A is extraneous
• Set is now {A  BC, B  C}
 C is extraneous in A  BC
• Check if A  C is logically implied by {A  B, B  C}
• Yes: using transitivity on A  B and B  C, we get A  C
• Set is now {A  B, B  C}
 The canonical cover is: A  B
B  C
©Silberschatz, Korth and Sudarshan
7.66
Database System Concepts - 7th Edition
Example: Computing a Canonical Cover
 A canonical cover might not be unique
 R = (A, B, C)
F = {A  BC, B  AC, C  AB}
1. If C is extraneous in A  BC, we get F’ = {A  B, B  AC, C  AB}
• We find A is extraneous in C  AB, leading canonical cover:
Fc = {A  B, B  AC, C  B}
• We find B is extraneous in C  AB and then A is extraneous in B  AC,
leading canonical cover:
Fc = {A  B, B  C, C  A}
2. If B is extraneous in A  BC, we get F’ = {A  C, B  AC, C  AB}
• We find A is extraneous in B  AC, leading canonical cover:
Fc = {A  C, B  C, C  AB}
• We find C is extraneous in B  AC and then A is extraneous in C  AB,
leading canonical cover:
Fc = {A  C, B  A, C  B}
©Silberschatz, Korth and Sudarshan
7.67
Database System Concepts - 7th Edition
Dependency Preservation
 Let Fi be the set of dependencies F + that include only attributes in Ri.
• A decomposition is dependency preserving, if
(F1  F2  …  Fn )+ = F +
 Using the above definition, testing for dependency preservation take
exponential time.
 Not that if a decomposition is NOT dependency preserving then checking
updates for violation of functional dependencies may require computing
joins, which is expensive.
Link
©Silberschatz, Korth and Sudarshan
7.68
Database System Concepts - 7th Edition
Testing for Dependency Preservation
 To check if a dependency    is preserved in a decomposition of R into
R1, R2, …, Rn , we apply the following test (with attribute closure done with
respect to F)
• result = 
repeat
for each Ri in the decomposition
t = (result  Ri)+  Ri
result = result  t
until (result does not change)
• If result contains all attributes in , then the functional dependency 
  is preserved.
 We apply the test on all dependencies in F to check if a decomposition is
dependency preserving
 This procedure takes polynomial time, instead of the exponential time
required to compute F+ and (F1  F2  …  Fn)+
©Silberschatz, Korth and Sudarshan
7.69
Database System Concepts - 7th Edition
Dependency Preservation (Example -1)
 Let a relation R (A, B, C) and functional dependency F={A  B, B  C}.
Relation R is decomposed into R1( A, B) and R2(B, C). Check whether
decomposition is dependency preserving or not.
 Check if A  B is preserved, result = A
• For R1: t = (result  R1)+  R1 = (A  AB)+  AB = (A)+  AB = ABC  AB
= AB, result = result  t = A  AB = AB
• For R2: t = (result  R2)+  R2 = (AB  BC)+  BC = (B)+  BC = BC  BC
= BC, result = result  t = AB  BC = ABC
• Since B  ABC, therefore A  B is preserved
 Check if B  C is preserved, result = B
• For R1: t = (result  R1)+  R1 = (B  AB)+  AB = (B)+  AB = BC  AB =
B, result = result  t = B  B = B
• For R2: t = (result  R2)+  R2 = (B  BC)+  BC = (B)+  BC = BC  BC =
BC, result = result  t = B  BC = BC
• Since C  BC, therefore B  C is preserved
 All functional dependencies are preserved, hence the decomposition is
dependency preserving
©Silberschatz, Korth and Sudarshan
7.70
Database System Concepts - 7th Edition
Dependency Preservation (Example - 2)
 Let a relation R (A, B, C) and functional dependency F={A  B, B  C}.
Relation R is decomposed into R1( A, B) and R2(A, C). Check whether
decomposition is dependency preserving or not.
 Check if A  B is preserved, result = A
• For R1: t = (result  R1)+  R1 = (A  AB)+  AB = (A)+  AB = ABC  AB
= AB, result = result  t = A  AB = AB
• For R2: t = (result  R2)+  R2 = (AB  AC)+  AC = (A)+  AC = BC  AC
= C, result = result  t = A  C = AC
• Since B ⊄ AC, therefore A  B is not preserved
 Check if B  C is preserved, result = B
• For R1: t = (result  R1)+  R1 = (B  AB)+  AB = (B)+  AB = BC  AB =
B, result = result  t = B  B = B
• For R2: t = (result  R2)+  R2 = (B  AC)+  AC = (∅)+  AC = ∅  AC =
∅, result = result  t = B  ∅ = B
• Since C ⊄ B, therefore B  C is not preserved
 The functional dependencies are not preserved, hence the decomposition is not
dependency preserving
©Silberschatz, Korth and Sudarshan
7.71
Database System Concepts - 7th Edition
Example
 R = (A, B, C )
F = {A  B
B  C}
Key = {A}
 R is not in BCNF
 Decomposition R1 = (A, B), R2 = (B, C)
• R1 and R2 in BCNF
• Lossless-join decomposition
• Dependency preserving
©Silberschatz, Korth and Sudarshan
7.72
Database System Concepts - 7th Edition
End of Chapter 7

More Related Content

Similar to DBMS-Ch7-MKB (1).pdf

Database System Concepts ch4.pdf
Database System Concepts ch4.pdfDatabase System Concepts ch4.pdf
Database System Concepts ch4.pdfUsamaAlZayan
 
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybbjhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybbWrushabhShirsat3
 
Relational Algebra and relational queries .ppt
Relational Algebra and relational queries .pptRelational Algebra and relational queries .ppt
Relational Algebra and relational queries .pptShahidSultan24
 
DATABASE MANAGEMENT SYSTEMS ER MODEL.ppt
DATABASE MANAGEMENT SYSTEMS ER MODEL.pptDATABASE MANAGEMENT SYSTEMS ER MODEL.ppt
DATABASE MANAGEMENT SYSTEMS ER MODEL.pptYashShirude1
 
Intro to Relational Model
Intro to Relational ModelIntro to Relational Model
Intro to Relational ModelHazemWaheeb1
 
Database Design E-R Model.pdf
Database Design E-R Model.pdfDatabase Design E-R Model.pdf
Database Design E-R Model.pdfAbithaSam
 
03 Relational Databases.ppt
03 Relational Databases.ppt03 Relational Databases.ppt
03 Relational Databases.pptAmitpatil226799
 
ch7.ppt ER Model lecture 102 slides set in ppt
ch7.ppt ER Model lecture 102 slides set in pptch7.ppt ER Model lecture 102 slides set in ppt
ch7.ppt ER Model lecture 102 slides set in pptFerdazdemir
 
Relational database concept
Relational database conceptRelational database concept
Relational database conceptfikirabc
 
DBMS-UNIT 3-part1.ppt
DBMS-UNIT 3-part1.pptDBMS-UNIT 3-part1.ppt
DBMS-UNIT 3-part1.pptIshuIswarya3
 

Similar to DBMS-Ch7-MKB (1).pdf (20)

ch7-clean.ppt
ch7-clean.pptch7-clean.ppt
ch7-clean.ppt
 
Database System Concepts ch4.pdf
Database System Concepts ch4.pdfDatabase System Concepts ch4.pdf
Database System Concepts ch4.pdf
 
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybbjhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
 
ch2.ppt
ch2.pptch2.ppt
ch2.ppt
 
DBMS.pdf
DBMS.pdfDBMS.pdf
DBMS.pdf
 
L8 design1
L8 design1L8 design1
L8 design1
 
Relational Algebra and relational queries .ppt
Relational Algebra and relational queries .pptRelational Algebra and relational queries .ppt
Relational Algebra and relational queries .ppt
 
ER Models.ppt
ER Models.pptER Models.ppt
ER Models.ppt
 
DATABASE MANAGEMENT SYSTEMS ER MODEL.ppt
DATABASE MANAGEMENT SYSTEMS ER MODEL.pptDATABASE MANAGEMENT SYSTEMS ER MODEL.ppt
DATABASE MANAGEMENT SYSTEMS ER MODEL.ppt
 
Intro to Relational Model
Intro to Relational ModelIntro to Relational Model
Intro to Relational Model
 
App c
App cApp c
App c
 
ch6.pptx
ch6.pptxch6.pptx
ch6.pptx
 
Database Design E-R Model.pdf
Database Design E-R Model.pdfDatabase Design E-R Model.pdf
Database Design E-R Model.pdf
 
03 Relational Databases.ppt
03 Relational Databases.ppt03 Relational Databases.ppt
03 Relational Databases.ppt
 
ch7.ppt ER Model lecture 102 slides set in ppt
ch7.ppt ER Model lecture 102 slides set in pptch7.ppt ER Model lecture 102 slides set in ppt
ch7.ppt ER Model lecture 102 slides set in ppt
 
Relational database concept
Relational database conceptRelational database concept
Relational database concept
 
DBMS-UNIT 3-part1.ppt
DBMS-UNIT 3-part1.pptDBMS-UNIT 3-part1.ppt
DBMS-UNIT 3-part1.ppt
 
Relational Model
Relational ModelRelational Model
Relational Model
 
check 11
check 11check 11
check 11
 
ch4 (1).pptx
ch4 (1).pptxch4 (1).pptx
ch4 (1).pptx
 

Recently uploaded

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Recently uploaded (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

DBMS-Ch7-MKB (1).pdf

  • 1. Database System Concepts, 7th Ed. ©Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use Chapter 7: Normalization Database Management Systems Course Code: CSE309 2022
  • 2. ©Silberschatz, Korth and Sudarshan 7.2 Database System Concepts - 7th Edition Course Teacher Dr. Mrinal Kanti Baowaly Associate Professor Department of Computer Science and Engineering, Bangabandhu Sheikh Mujibur Rahman Science and Technology University, Bangladesh. Email: baowaly@gmail.com
  • 3. ©Silberschatz, Korth and Sudarshan 7.3 Database System Concepts - 7th Edition Outline  Features of Good Relational Design  Functional Dependencies  Decomposition Using Functional Dependencies  Normal Forms  Functional Dependency Theory  Algorithms for Decomposition using Functional Dependencies  Decomposition Using Multivalued Dependencies  More Normal Form  Atomic Domains and First Normal Form  Database-Design Process  Modeling Temporal Data
  • 4. ©Silberschatz, Korth and Sudarshan 7.5 Database System Concepts - 7th Edition Features of Good Relational Designs  Suppose we combine instructor and department into in_dep, which represents the natural join on the relations instructor and department  There is repetition of information, e.g., department information (“building” and “budget”). It creates data inconsistency.  Need to use null values (if we add a new department with no instructors)
  • 5. ©Silberschatz, Korth and Sudarshan 7.6 Database System Concepts - 7th Edition Decomposition  The only way to avoid the repetition-of-information problem in the in_dep schema is to decompose it into two schemas – instructor and department schemas. instructor(ID, name, dept name, salary) department(dept_name, building, budget)  Not all decompositions are good. Suppose we decompose employee(ID, name, street, city, salary) into employee1 (ID, name) employee2 (name, street, city, salary) The problem arises when we have two employees with the same name  The next slide shows how we lose information -- we cannot reconstruct the original employee relation -- and so, this is a lossy decomposition.
  • 6. ©Silberschatz, Korth and Sudarshan 7.7 Database System Concepts - 7th Edition A Lossy Decomposition Notice that the two original tuples appear in the result along with two new tuples that incorrectly mix data values pertaining to the two employees named Kim.
  • 7. ©Silberschatz, Korth and Sudarshan 7.8 Database System Concepts - 7th Edition Lossless Decomposition  Let R be a relation schema and let R1 and R2 form a decomposition of R . That is R = R1 U R2  We say that the decomposition is a lossless decomposition if there is no loss of information by replacing R with the two relation schemas R1 U R2  Formally,  R1 (r)  R2 (r) = r  And, conversely a decomposition is lossy if r   R1 (r)  R2 (r)
  • 8. ©Silberschatz, Korth and Sudarshan 7.9 Database System Concepts - 7th Edition Example of Lossless Decomposition  Decomposition of R = (A, B, C) R1 = (A, B) R2 = (B, C)
  • 9. ©Silberschatz, Korth and Sudarshan 7.10 Database System Concepts - 7th Edition Normalization Theory  Normalization is the process of organizing data in a database to ensure that each relation is in good form.  In the case that a relation R is not in “good” form, decompose it into set of relations {R1, R2, ..., Rn} such that • Each relation is in good form • The decomposition is a lossless decomposition  Normalization helps to reduce data redundancy and eliminates undesirable characteristics like insertion, deletion, and update anomalies in a database.
  • 10. ©Silberschatz, Korth and Sudarshan 7.11 Database System Concepts - 7th Edition Normalization (Cont.)  There are a few rules for database normalization. Each rule is called a "normal form." These normal forms are: • First Normal Form (1NF) • Second Normal Form (2NF) • Third Normal Form (3NF) • Boyce-Codd Normal Form (BCNF) • Fourth Normal Form (4NF) etc.  If the first rule is observed, the relation is said to be in "first normal form." If the first three rules are observed, the relation is considered to be in "third normal form.“  Normalization theory is based on: • Functional dependencies • Multivalued dependencies
  • 11. ©Silberschatz, Korth and Sudarshan 7.12 Database System Concepts - 7th Edition Functional Dependencies  There are usually a variety of constraints (rules) on the data in the real world.  For example, some of the constraints that are expected to hold in a university database are: • Students and instructors are uniquely identified by their ID. • Each student and instructor has only one name. • Each instructor and student is (primarily) associated with only one department. • Each department has only one value for its budget, and only one associated building.
  • 12. ©Silberschatz, Korth and Sudarshan 7.13 Database System Concepts - 7th Edition Functional Dependencies Definition  Let R be a relation schema   R and   R  The functional dependency    holds on R if and only if for any legal relations r(R), whenever any two tuples t1 and t2 of r agree on the attributes , they also agree on the attributes . That is, t1[] = t2 []  t1[ ] = t2 [ ]  Alternative Definition: A functional dependency A->B in a relation holds if two tuples having same value of attribute A also have same value for attribute B.  Example: Consider r(A,B ) with the following instance of r.  On this instance, A  B does NOT hold, but B  A does hold. A B 1 4 1 5 3 7 3 7
  • 13. ©Silberschatz, Korth and Sudarshan 7.14 Database System Concepts - 7th Edition Closure of a Set of Functional Dependencies  Given a set F set of functional dependencies, there are certain other functional dependencies that are logically implied by F. • If A  B and B  C, then we can infer that A  C • etc.  The set of all functional dependencies logically implied by F is the closure of F.  We denote the closure of F by F+ .
  • 14. ©Silberschatz, Korth and Sudarshan 7.15 Database System Concepts - 7th Edition Keys and Functional Dependencies  K is a superkey for relation schema R if and only if K  R  K is a candidate key for R if and only if • K  R, and • for no   K,   R  Functional dependencies allow us to express constraints that cannot be expressed using superkeys. Consider the schema: in_dep (ID, name, salary, dept_name, building, budget ). We expect these functional dependencies to hold: dept_name building ID  building but would not expect the following to hold: dept_name  salary
  • 15. ©Silberschatz, Korth and Sudarshan 7.16 Database System Concepts - 7th Edition Use of Functional Dependencies  We use functional dependencies to: • To test relations to see if they are legal under a given set of functional dependencies.  If a relation r is legal under a set F of functional dependencies, we say that r satisfies F. • To specify constraints on the set of legal relations  We say that F holds on R if all legal relations on R satisfy the set of functional dependencies F.  Note: A specific instance of a relation schema may satisfy a functional dependency even if the functional dependency does not hold on all legal instances. • For example, a specific instance of instructor may, by chance, satisfy name  ID.
  • 16. ©Silberschatz, Korth and Sudarshan 7.17 Database System Concepts - 7th Edition Trivial Functional Dependencies  A functional dependency is trivial if it is satisfied by all instances of a relation  Example: • ID, name  ID • name  name  In general,    is trivial if   
  • 17. ©Silberschatz, Korth and Sudarshan 7.18 Database System Concepts - 7th Edition Lossless Decomposition  We can use functional dependencies to show when certain decomposition are lossless.  For the case of R = (R1, R2), we require that for all possible relations r on schema R r = R1 (r ) R2 (r )  A decomposition of R into R1 and R2 is lossless decomposition if at least one of the following dependencies is in F+: • R1  R2  R1 • R1  R2  R2  The above functional dependencies are a sufficient condition for lossless join decomposition; the dependencies are a necessary condition only if all constraints are functional dependencies
  • 18. ©Silberschatz, Korth and Sudarshan 7.19 Database System Concepts - 7th Edition Lossless Decomposition (Example)  R = (A, B, C) F = {A  B, B  C)  R1 = (A, B), R2 = (B, C) • Lossless decomposition: if R1  R2  R1 or R1  R2  R2 R1  R2 = {B} Check if B  AB or B  BC Since B  C, therefore B  BC and the decomposition is lossless  R1 = (A, B), R2 = (A, C) • Lossless decomposition: if R1  R2  R1 or R1  R2  R2 R1  R2 = {A} Check if A  AB or A  BC Since A  B, therefore A  AB and the decomposition is lossless
  • 19. ©Silberschatz, Korth and Sudarshan 7.20 Database System Concepts - 7th Edition Dependency Preservation  Testing functional dependency constraints each time the database is updated can be costly  It is useful to design the database in a way that constraints can be tested efficiently.  If testing a functional dependency can be done by considering just one relation, then the cost of testing this constraint is low  When decomposing a relation it is possible that it is no longer possible to do the testing without having to perform a Cartesian Produced.  A decomposition that makes it computationally hard to enforce functional dependency is said to be NOT dependency preserving.
  • 20. ©Silberschatz, Korth and Sudarshan 7.21 Database System Concepts - 7th Edition Dependency Preservation Example  Consider a schema: dept_advisor(s_ID, i_ID, department_name)  With function dependencies: i_ID  dept_name s_ID, dept_name  i_ID  In the above design we are forced to repeat the department name once for each time an instructor participates in a dept_advisor relationship.  To fix this, we need to decompose dept_advisor  Any decomposition will not include all the attributes in s_ID, dept_name  i_ID  Thus, the composition NOT be dependency preserving
  • 21. ©Silberschatz, Korth and Sudarshan 7.22 Database System Concepts - 7th Edition Dependency Preservation (Example)  R = (A, B, C) F = {A  B, B  C)  R1 = (A, B), R2 = (B, C) • Lossless-join decomposition: R1  R2 = {B} and R1  R2  R2 i.e. B  BC holds because B  C • Dependency preserving  R1 = (A, B), R2 = (A, C) • Lossless-join decomposition: R1  R2 = {A} and R1  R2  R1 i.e. A  AB holds because A  B • Not dependency preserving (cannot check B  C without computing R1 R2)
  • 22. ©Silberschatz, Korth and Sudarshan 7.24 Database System Concepts - 7th Edition First Normal Form  A relational schema R is in first normal form (1NF) if the domains of all attributes of R are atomic  A domain is atomic if elements of the domain are considered to be indivisible units.  In other words, a relational schema R is in 1NF if it does not contain any multi-valued and composite attributes.  Non-atomic values complicate storage and encourage redundant (repeated) storage of data.  Example 1: If a relation student includes an attribute course whose domain elements are sets of course names (multi-valued attribute), the relation would not be in first normal form. Solution: Put a single value for each attribute cell  Example 2: If a relation has an composite attribute, such as an address with component attributes street, city, state, and zip; the relation would not be in first normal form. Solution: Create a separate attribute for each subpart of the composite attribute.
  • 23. ©Silberschatz, Korth and Sudarshan 7.25 Database System Concepts - 7th Edition First Normal Form (Example) student_id name Course S01 Tuhin Word, Excel, Access S02 Shuvro PowerPoint, Outlook Unnormalized table Normalized table in 1NF student_id Name Course S01 Tuhin Word S01 Tuhin Excel S01 Tuhin Access S02 Shuvro PowerPoint S02 Shuvro Outlook
  • 24. ©Silberschatz, Korth and Sudarshan 7.26 Database System Concepts - 7th Edition Second Normal Form  A relational schema R is in second normal form (2NF) if it is in 1NF and all non-key attributes are fully functionally dependent on the (entire) primary key.  In other words, a relational schema R is in second normal form (2NF) if it is in 1NF and must not contain any partial dependencies.  A functional dependency X->Y is called a fully functional dependency if an attribute Y is functionally dependent on an attribute X but not functionally dependent on any proper subset of X.  If the primary key is one attribute, then the relation automatically satisfies 2NF.  When a relation has a composite primary key, a partial dependency may occur if a non-key attribute is functionally dependent on any proper subset of the primary key.  2NF involves removing partial dependencies from R and creates a separate table for each partial dependency, taking a note that one attribute remains in the 1NF table as a foreign key to link the new table.
  • 25. ©Silberschatz, Korth and Sudarshan 7.27 Database System Concepts - 7th Edition Second Normal Form (Example) student_id project_id student_name project_name S89 P09 Olivia Geo Location S56 P07 Jacob Cluster Exploration S56 P03 Jacob IoT Devices S92 P05 Alexandra Cloud Deployment Functional dependencies: student_id, project_id → student_name, project_name student_id → student_name project_id → project_name student_id project_id S89 P09 S56 P07 S56 P03 S92 P05 student_id student_name S89 Olivia S56 Jacob S92 Alexandra project_id project_name P09 Geo Location P07 Cluster Exploration P03 IoT Devices P05 Cloud Deployment Unnormalized table Normalized tables in 2NF
  • 26. ©Silberschatz, Korth and Sudarshan 7.28 Database System Concepts - 7th Edition Decomposing a Schema  Let R be a schema R that is not in 2NF. Let   be the FD that causes a violation of 2NF.  We decompose R into: • ( U  ) • ( R - (  -  ) )  In our example of in_dep (ID, name, salary, dept_name, building, budget ), it holds: dept_name  building, budget •  = dept_name •  = building, budget and in_dep is replaced by • ( U  ) = (dept_name, building, budget ) • ( R - (  -  ) ) = (ID, name, salary, dept_name)
  • 27. ©Silberschatz, Korth and Sudarshan 7.29 Database System Concepts - 7th Edition Third Normal Form  A relational schema R is in third normal form (3NF) if it is in 2NF and has no transitive dependencies.  A transitive dependency occurs when a non-key attribute depends on another non-key attribute.  3NF involves removing dependencies between non-key attributes in the relation and creates a separate table for each such dependency. This ensures the relation has no transitive dependencies.  Example: Course_id Instructor_id Instructor Course_topic CSE101 001 MKB ML CSE208 002 SA Database CSE305 003 MNH NLP CSE109 004 MMA DL For the above relation, it holds: Instructor_id  Instructor Hence, there is a transitive dependency: Course_id  Instructor_id, Instructor_id  Instructor
  • 28. ©Silberschatz, Korth and Sudarshan 7.30 Database System Concepts - 7th Edition Third Normal Form (Example) Course_id Instructor_id Instructor Course_topic CSE101 001 MKB ML CSE208 002 SA Database CSE305 003 MNH NLP CSE109 004 MMA DL Normalized tables in 3NF Unnormalized table in 3NF Instructor_id Instructor 001 MKB 002 SA 003 MNH 004 MMA Course_id Instructor_id Course_topic CSE101 001 ML CSE208 002 Database CSE305 003 NLP CSE109 004 DL
  • 29. ©Silberschatz, Korth and Sudarshan 7.31 Database System Concepts - 7th Edition 3NF Another Example  Consider a schema: dept_advisor(s_ID, i_ID, dept_name)  With function dependencies: i_ID  dept_name s_ID, dept_name  i_ID  Two candidate keys = {s_ID, dept_name}, {s_ID, i_ID }  We have seen before that dept_advisor is not in BCNF  R, however, is in 3NF • s_ID, dept_name is a superkey • i_ID  dept_name and i_ID is NOT a superkey, but:  { dept_name} – {i_ID } = {dept_name } and  dept_name is contained in a candidate key
  • 30. ©Silberschatz, Korth and Sudarshan 7.32 Database System Concepts - 7th Edition Redundancy in 3NF  Consider the schema R below, which is in 3NF  What is wrong with the table? • R = (J, K, L ) • F = {JK  L, L  K } • And an instance table: • Repetition of information • Need to use null values (e.g., to represent the relationship l2, k2 where there is no corresponding value for J)
  • 31. ©Silberschatz, Korth and Sudarshan 7.33 Database System Concepts - 7th Edition Advantages and Disadvantages to 3NF  Advantages to 3NF. • It is always possible to obtain a 3NF design without sacrificing losslessness or dependency preservation.  Disadvantages to 3NF. • We may have to use null values to represent some of the possible meaningful relationships among data items. • There is the problem of repetition of information.
  • 32. ©Silberschatz, Korth and Sudarshan 7.34 Database System Concepts - 7th Edition Goals of Normalization  Let R be a relation scheme with a set F of functional dependencies.  Decide whether a relation scheme R is in “good” form.  In the case that a relation scheme R is not in “good” form, need to decompose it into a set of relation scheme {R1, R2, ..., Rn} such that: • Each relation scheme is in good form • The decomposition is a lossless decomposition • Preferably, the decomposition should be dependency preserving.
  • 33. ©Silberschatz, Korth and Sudarshan 7.35 Database System Concepts - 7th Edition Boyce-Codd Normal Form  A more restricted version of 3NF known as Boyce-Codd Normal Form requires that the determinant of every functional dependency in a relation is a candidate key.  A relation schema R is in BCNF with respect to a set F of functional dependencies if for all functional dependencies in F+ of the form    where   R and   R, at least one of the following holds: •    is trivial (i.e.,   ) •  is a superkey for R
  • 34. ©Silberschatz, Korth and Sudarshan 7.36 Database System Concepts - 7th Edition Boyce-Codd Normal Form (Cont.)  Example schema that is not in BCNF: in_dep (ID, name, salary, dept_name, building, budget ) because : • dept_name building, budget  holds on in_dep  but dept_name is not a superkey  When decompose in_dept into instructor (ID, name, salary, dept_name) and department (dept_name, building, budget ) • instructor is in BCNF • department is in BCNF
  • 35. ©Silberschatz, Korth and Sudarshan 7.37 Database System Concepts - 7th Edition BCNF and Dependency Preservation  It is not always possible to achieve both BCNF and dependency preservation  Consider a schema: dept_advisor(s_ID, i_ID, department_name)  With function dependencies: i_ID  dept_name s_ID, dept_name  i_ID  dept_advisor is not in BCNF • i_ID is not a superkey.  Any decomposition of dept_advisor will not include all the attributes in s_ID, dept_name  i_ID  Thus, the composition is NOT be dependency preserving
  • 36. ©Silberschatz, Korth and Sudarshan 7.38 Database System Concepts - 7th Edition Comparison of BCNF and 3NF  It is always possible to decompose a relation into a set of relations that are in 3NF such that: • The decomposition is lossless • The dependencies are preserved  It is always possible to decompose a relation into a set of relations that are in BCNF such that: • The decomposition is lossless • It may not be possible to preserve dependencies.
  • 37. ©Silberschatz, Korth and Sudarshan 7.39 Database System Concepts - 7th Edition How good is BCNF?  There are database schemas in BCNF that do not seem to be sufficiently normalized  Consider a relation inst_info (ID, child_name, phone) • where an instructor may have more than one phone and can have multiple children • Instance of inst_info
  • 38. ©Silberschatz, Korth and Sudarshan 7.40 Database System Concepts - 7th Edition  There are no non-trivial functional dependencies and therefore the relation is in BCNF  Insertion anomalies – i.e., if we add a phone 981-992-3443 to 99999, we need to add two tuples (99999, David, 981-992-3443) (99999, William, 981-992-3443) How good is BCNF? (Cont.)
  • 39. ©Silberschatz, Korth and Sudarshan 7.41 Database System Concepts - 7th Edition  It is better to decompose inst_info into: • inst_child: • inst_phone:  This suggests the need for higher normal forms, such as Fourth Normal Form (4NF), which we shall see later Higher Normal Form
  • 40. ©Silberschatz, Korth and Sudarshan 7.42 Database System Concepts - 7th Edition  A relation R is in 4NF if and only if it is in the Boyce-Codd Normal Form (BCNF) and the relation should not have any multi-valued dependency.  A relation with a multi-valued dependency violates the normalization standard of Fourth Normal Form (4NK) because it creates unnecessary redundancies and can contribute to inconsistent data  A table is said to have multi-valued dependency, if the following conditions are true: • For a dependency A → B, if for a single value of A, multiple value of B exists, then the relation may have multi-valued dependency. • Also, a relation should have at-least 3 columns for it to have a multi-valued dependency. • And, for a relation R(A,B,C), if there is a multi-valued dependency between, A and B, then B and C should be independent of each other.  To make a relation satisfy the fourth normal form, we can decompose the table. Fourth Normal Form (4NF)
  • 41. ©Silberschatz, Korth and Sudarshan 7.43 Database System Concepts - 7th Edition Fourth Normal Form (Example) Student_id Name Course S01 Tuhin Word S01 Tuhin Excel S01 Tuhin Access S02 Shuvro PowerPoint S02 Shuvro Outlook Not in 4NF Student_id  Course Student_id Course S01 Word S01 Excel S01 Access S02 PowerPoint S02 Outlook Student_id Name S01 Tuhin S02 Shuvro Normalized tables in 4NF
  • 42. ©Silberschatz, Korth and Sudarshan 7.45 Database System Concepts - 7th Edition Functional-Dependency Theory Roadmap  We now consider the formal theory that tells us which functional dependencies are implied logically by a given set of functional dependencies.  We then develop algorithms to generate lossless decompositions into BCNF and 3NF  We then develop algorithms to test if a decomposition is dependency- preserving
  • 43. ©Silberschatz, Korth and Sudarshan 7.46 Database System Concepts - 7th Edition Closure of a Set of Functional Dependencies  Given a set F set of functional dependencies, there are certain other functional dependencies that are logically implied by F. • If A  B and B  C, then we can infer that A  C • etc.  The set of all functional dependencies logically implied by F is the closure of F.  We denote the closure of F by F+ .
  • 44. ©Silberschatz, Korth and Sudarshan 7.47 Database System Concepts - 7th Edition Closure of a Set of Functional Dependencies  We can compute F+, the closure of F, by repeatedly applying Armstrong’s Axioms: • Reflexive rule: if   , then    • Augmentation rule: if   , then      • Transitivity rule: if   , and   , then     These rules are • Sound -- generate only functional dependencies that actually hold, and • Complete -- generate all functional dependencies that hold.
  • 45. ©Silberschatz, Korth and Sudarshan 7.48 Database System Concepts - 7th Edition Example of F+  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  by augmenting CG  I to infer CG  CGI, and augmenting of CG  H to infer CGI  HI, and then transitivity
  • 46. ©Silberschatz, Korth and Sudarshan 7.49 Database System Concepts - 7th Edition Closure of Functional Dependencies (Cont.)  Additional rules: • Union rule: If    holds and    holds, then     holds. • Decomposition rule: If     holds, then    holds and    holds. • Pseudotransitivity rule:If    holds and     holds, then    holds.  The above rules can be inferred from Armstrong’s axioms. • Union rule: by augmenting    with , we get    and by augmenting    with , we get     and then using transitivity we have     • Decomposition rule: we have    , and using reflexivity we get     and    , and then using transitivity it infers:    and    • Pseudotransitivity rule: by augmenting    with , to get     and then transitivity with   , we have   
  • 47. ©Silberschatz, Korth and Sudarshan 7.50 Database System Concepts - 7th Edition Procedure for Computing F+  To compute the closure of a set of functional dependencies 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 f1and f2 in F + if f1 and f2 can be combined using transitivity then add the resulting functional dependency to F + until F + does not change any further  NOTE: We shall see an alternative procedure for this task later
  • 48. ©Silberschatz, Korth and Sudarshan 7.51 Database System Concepts - 7th Edition Closure of Attribute Sets  Given a set of attributes , define the closure of  under F (denoted by +) as the set of attributes that are functionally determined by  under F  Algorithm to compute +, the closure of  under F result := ; while (changes to result) do for each    in F do begin if   result then result := result   end
  • 49. ©Silberschatz, Korth and Sudarshan 7.52 Database System Concepts - 7th Edition 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 = AG 2. result = ABCG (A  C and A  B) 3. result = ABCGH (CG  H and CG  AGBC) 4. result = ABCGHI (CG  I and CG  AGBCH)  Is AG a candidate key? 1. Is AG a super key? 1. Does AG  R? == Is R  (AG)+ 2. Is any subset of AG a superkey? 1. Does A  R? == Is R  (A)+ 2. Does G  R? == Is R  (G)+ 3. In general: check for each subset of size n-1
  • 50. ©Silberschatz, Korth and Sudarshan 7.53 Database System Concepts - 7th Edition Uses of Attribute Closure There 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.
  • 51. ©Silberschatz, Korth and Sudarshan 7.54 Database System Concepts - 7th Edition Testing for Super Key and Candidate Key  R = (A, B, C, G, H, I)  F = {A  B A  C CG  H CG  I B  H}  (AG)+ 1. result = AG 2. result = ABCG (A  B and A  C and A  AG) 3. result = ABCGH (CG  H and CG  AGBC) 4. result = ABCGHI (CG  I and CG  AGBCH)  Is AG a super key? • (AG)+ = ABCGHI. AG is super key because (AG)+ contains all attributes of R  Is AG a candidate key? • Start with computing the closure of single attributes in R A+ = ABCH, B+ = BH, C+ = C, G+ = G, H+ = H, I+ = I • No single attribute can contain all attributes of R, hence AG is candidate key.
  • 52. ©Silberschatz, Korth and Sudarshan 7.55 Database System Concepts - 7th Edition HW: Find Candidate Keys  R = (A, B, C, D, E)  F = {A  BC C  B D  E E  D}  List the candidate keys for R
  • 53. ©Silberschatz, Korth and Sudarshan 7.56 Database System Concepts - 7th Edition Testing Functional Dependencies  We are given R(A, B, C, D, E, F). The functional dependencies (FD) are: {AB  C, BC  AD, D  E, CF  B}  Check whether AB  DE can be derived from the given FD set.  Solution: Compute (AB) + 1. result = AB 2. result = ABC (AB  C and AB  AB) 3. result = ABCD (BC  AD and BC  ABC) 4. result = ABCDE (D  E and D  ABCD) Since DE  (AB) +, therefore AB  DE holds Problem: Is AB a super key?
  • 54. ©Silberschatz, Korth and Sudarshan 7.57 Database System Concepts - 7th Edition Testing Lossless Decomposition  R = (A, B, C) F = {A  B, B  C)  R1 = (A, B), R2 = (B, C) • Lossless decomposition: if R1  R2  R1 or R1  R2  R2 R1  R2 = {B} Check if B  AB or B  BC holds Since B+ = BC, BC  B+, therefore B  BC holds and the decomposition is lossless  R1 = (A, B), R2 = (A, C) • Lossless decomposition: if R1  R2  R1 or R1  R2  R2 R1  R2 = {A} Check if A  AB or A  BC holds Since A+ = ABC, A is candidate key (or both AB  A+ and BC  A+), therefore both A  AB and A  BC hold and the decomposition is lossless
  • 55. ©Silberschatz, Korth and Sudarshan 7.58 Database System Concepts - 7th Edition Computing F + Using Attribute Closure  R = (A, B, C) F = {A  B, B  C)  Compute F+ (Consider only non-trivial functional dependencies) • Start with computing the closure of single attributes in R A+ = ABC, B+ = BC, C+ = C FD: A  B, A  C, B  C • Compute the closure of two attributes in R (AB)+ = ABC, (BC)+ = BC, (AC)+ = ABC FD: AB  C, AB  BC, AB  AC, AC  B, AC  AB, AC  BC • F+ = {A  B, A  C, B  C, AB  C, AB  BC, AB  AC, AC  B, AC  AB, AC  BC}
  • 56. ©Silberschatz, Korth and Sudarshan 7.59 Database System Concepts - 7th Edition Canonical Cover  Suppose that we have a set of functional dependencies F on a relation schema. 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.  If an update violates any functional dependencies in the set F, the system must roll back the update.  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.  This simplified set is termed the canonical cover  To define canonical cover we must first define extraneous attributes. • An attribute of a functional dependency in F is extraneous if we can remove it without changing F +
  • 57. ©Silberschatz, Korth and Sudarshan 7.60 Database System Concepts - 7th Edition Extraneous Attributes  An attribute of a functional dependency in F is extraneous if we can remove it without changing F +  Consider a set F of functional dependencies and the functional dependency    in F. • Remove from the left side: Attribute A is extraneous in  if  A   and  F logically implies (F – {  })  {( – A)  }. • Remove from the right side: Attribute A is extraneous in  if  A   and  The set of functional dependencies (F – {  })  { ( – A)} logically implies F.
  • 58. ©Silberschatz, Korth and Sudarshan 7.61 Database System Concepts - 7th Edition Testing if an Attribute is Extraneous  Let R be a relation schema and let F be a set of functional dependencies that hold on R . Consider an attribute A in the functional dependency   .  To test if attribute A   is extraneous in  • Consider the set: F' = (F – {  })  { ( – A)}, • Check if   A can be inferred from F' • To do so, compute + under F' ; if + includes A, then A is extraneous in   To test if attribute A   is extraneous in  • Let  =  – {A}. Check if    can be inferred from F. • Compute + under F • If + includes all attributes in  then , A is extraneous in 
  • 59. ©Silberschatz, Korth and Sudarshan 7.62 Database System Concepts - 7th Edition Examples of Extraneous Attributes  Let F = {AB  CD, A  E, E  C }  To check if C is extraneous in AB  CD: • Check if AB  CD can be inferred from F' = {AB  D, A  E, E  C} • We compute the attribute closure of AB under F' • (AB)+ = ABCDE, which includes CD • This implies that C is extraneous  Let F = {AB  C, A  C }  To check if B is extraneous in AB  C: • Check if A  C can be inferred from F = {AB  C, A  C} • A  C is already in F • This implies that B is extraneous
  • 60. ©Silberschatz, Korth and Sudarshan 7.63 Database System Concepts - 7th Edition Canonical Cover  F logically implies all dependencies in Fc , and  Fc logically implies all dependencies in F, and  No functional dependency in Fc contains an extraneous attribute, and  Each left side of functional dependency in Fc is unique. That is, there are no two dependencies in Fc • 1  1 and 2  2 such that • 1 = 2 A canonical cover for F is a set of dependencies Fc such that
  • 61. ©Silberschatz, Korth and Sudarshan 7.64 Database System Concepts - 7th Edition Canonical Cover  To compute a canonical cover for F: Fc = F repeat Use the union rule to replace any dependencies in F of the form 1  1 and 1  2 with 1  1 2 Find a functional dependency    in Fc with an extraneous attribute either in  or in  /* Note: test for extraneous attributes done using Fc, not F*/ If an extraneous attribute is found, delete it from    until Fc not change  Note: Union rule may become applicable after some extraneous attributes have been deleted, so it has to be re-applied
  • 62. ©Silberschatz, Korth and Sudarshan 7.65 Database System Concepts - 7th Edition Example: Computing a Canonical Cover  R = (A, B, C) F = {A  BC B  C A  B AB  C}  Using union rule, combine A  BC and A  B into A  BC • Set is now {A  BC, B  C, AB  C}  A is extraneous in AB  C • Check if B  C can be inferred from F = {A  BC, B  C, AB  C} • B  C is already in F, this implies that A is extraneous • Set is now {A  BC, B  C}  C is extraneous in A  BC • Check if A  C is logically implied by {A  B, B  C} • Yes: using transitivity on A  B and B  C, we get A  C • Set is now {A  B, B  C}  The canonical cover is: A  B B  C
  • 63. ©Silberschatz, Korth and Sudarshan 7.66 Database System Concepts - 7th Edition Example: Computing a Canonical Cover  A canonical cover might not be unique  R = (A, B, C) F = {A  BC, B  AC, C  AB} 1. If C is extraneous in A  BC, we get F’ = {A  B, B  AC, C  AB} • We find A is extraneous in C  AB, leading canonical cover: Fc = {A  B, B  AC, C  B} • We find B is extraneous in C  AB and then A is extraneous in B  AC, leading canonical cover: Fc = {A  B, B  C, C  A} 2. If B is extraneous in A  BC, we get F’ = {A  C, B  AC, C  AB} • We find A is extraneous in B  AC, leading canonical cover: Fc = {A  C, B  C, C  AB} • We find C is extraneous in B  AC and then A is extraneous in C  AB, leading canonical cover: Fc = {A  C, B  A, C  B}
  • 64. ©Silberschatz, Korth and Sudarshan 7.67 Database System Concepts - 7th Edition Dependency Preservation  Let Fi be the set of dependencies F + that include only attributes in Ri. • A decomposition is dependency preserving, if (F1  F2  …  Fn )+ = F +  Using the above definition, testing for dependency preservation take exponential time.  Not that if a decomposition is NOT dependency preserving then checking updates for violation of functional dependencies may require computing joins, which is expensive. Link
  • 65. ©Silberschatz, Korth and Sudarshan 7.68 Database System Concepts - 7th Edition Testing for Dependency Preservation  To check if a dependency    is preserved in a decomposition of R into R1, R2, …, Rn , we apply the following test (with attribute closure done with respect to F) • result =  repeat for each Ri in the decomposition t = (result  Ri)+  Ri result = result  t until (result does not change) • If result contains all attributes in , then the functional dependency    is preserved.  We apply the test on all dependencies in F to check if a decomposition is dependency preserving  This procedure takes polynomial time, instead of the exponential time required to compute F+ and (F1  F2  …  Fn)+
  • 66. ©Silberschatz, Korth and Sudarshan 7.69 Database System Concepts - 7th Edition Dependency Preservation (Example -1)  Let a relation R (A, B, C) and functional dependency F={A  B, B  C}. Relation R is decomposed into R1( A, B) and R2(B, C). Check whether decomposition is dependency preserving or not.  Check if A  B is preserved, result = A • For R1: t = (result  R1)+  R1 = (A  AB)+  AB = (A)+  AB = ABC  AB = AB, result = result  t = A  AB = AB • For R2: t = (result  R2)+  R2 = (AB  BC)+  BC = (B)+  BC = BC  BC = BC, result = result  t = AB  BC = ABC • Since B  ABC, therefore A  B is preserved  Check if B  C is preserved, result = B • For R1: t = (result  R1)+  R1 = (B  AB)+  AB = (B)+  AB = BC  AB = B, result = result  t = B  B = B • For R2: t = (result  R2)+  R2 = (B  BC)+  BC = (B)+  BC = BC  BC = BC, result = result  t = B  BC = BC • Since C  BC, therefore B  C is preserved  All functional dependencies are preserved, hence the decomposition is dependency preserving
  • 67. ©Silberschatz, Korth and Sudarshan 7.70 Database System Concepts - 7th Edition Dependency Preservation (Example - 2)  Let a relation R (A, B, C) and functional dependency F={A  B, B  C}. Relation R is decomposed into R1( A, B) and R2(A, C). Check whether decomposition is dependency preserving or not.  Check if A  B is preserved, result = A • For R1: t = (result  R1)+  R1 = (A  AB)+  AB = (A)+  AB = ABC  AB = AB, result = result  t = A  AB = AB • For R2: t = (result  R2)+  R2 = (AB  AC)+  AC = (A)+  AC = BC  AC = C, result = result  t = A  C = AC • Since B ⊄ AC, therefore A  B is not preserved  Check if B  C is preserved, result = B • For R1: t = (result  R1)+  R1 = (B  AB)+  AB = (B)+  AB = BC  AB = B, result = result  t = B  B = B • For R2: t = (result  R2)+  R2 = (B  AC)+  AC = (∅)+  AC = ∅  AC = ∅, result = result  t = B  ∅ = B • Since C ⊄ B, therefore B  C is not preserved  The functional dependencies are not preserved, hence the decomposition is not dependency preserving
  • 68. ©Silberschatz, Korth and Sudarshan 7.71 Database System Concepts - 7th Edition Example  R = (A, B, C ) F = {A  B B  C} Key = {A}  R is not in BCNF  Decomposition R1 = (A, B), R2 = (B, C) • R1 and R2 in BCNF • Lossless-join decomposition • Dependency preserving
  • 69. ©Silberschatz, Korth and Sudarshan 7.72 Database System Concepts - 7th Edition End of Chapter 7