Professional Documents
Culture Documents
Introduction to Databases
1
Databases
Functional Dependencies and Normalization
Chapter 19
2
Review-Database Design Process
Requirements Analysis
Interact with users and domain experts to
specify what the database should do.
Conceptual Design
Translate the requirements into a high-level
conceptual description (often using E/R Model)
Logical Design CREATE TABLE T ( cin
Convert the E/R Model into the DBMS logical data INTEGER, pname
VARCHAR(50),
model (in this class the relational model with schemas address FLOAT,
and constraints) PRIMARY KEY (cin));
Schema Refinement
Refine the logical model for consistency (but keeping
in mind performance!)
Physical Design
Develop the physical schema: how are schemas
stored physically on disk? How are they partitionned
in a distributed setting? Which indexes should be built?
Security Design
Set up measures to secure and protect the database 3
Review-Database Design Process
Requirements Analysis
Interact with users and domain experts to
specify what the database should do.
Conceptual Design
Translate the requirements into a high-level
conceptual description (often using E/R Model)
Logical Design CREATE TABLE T ( cin
Convert the E/R Model into the DBMS logical data INTEGER, pname
VARCHAR(50),
model (in this class the relational model with schemas address FLOAT,
and constraints) PRIMARY KEY (cin));
Schema Refinement
Refine the logical model for consistency (but keeping
We are here!
in mind performance!)
Physical Design
Develop the physical schema: how are schemas
stored physically on disk? How are they partitionned
in a distributed setting? Which indexes should be built?
Security Design
Set up measures to secure and protect the database 4
The Evils of Redundancy
• Redundancy is at the root of several problems associated with relational
schemas:
• Redundancy means that some values in the database are replicated
• redundant storage,
• insert/delete/update anomalies
• Integrity constraints, in particular functional dependencies, can be used
to identify schemas with such problems and to suggest refinements.
• Main refinement technique: decomposition (replacing ABCD with, say,
AB and BCD, or ACD and ABD).
• Decomposition should be used judiciously:
• Is there reason to decompose a relation?
• What problems (if any) does the decomposition cause?
Functional Dependencies (FDs)
• Problems due to R → W: S N L R W H
• Update anomaly: Can we 123-22-3666 Attishoo 48 8 10 40
change W in just the 1st tuple 231-31-5368 Smiley 22 8 10 30
of SNLRWH?
131-24-3650 Smethurst 35 5 7 30
• Insertion anomaly: What if we
want to insert an employee and 434-26-3751 Guldu 35 5 7 32
don’t know the hourly wage for 612-67-4134 Madayan 35 8 10 40
his rating?
• Deletion anomaly: If we delete
all employees with rating 5, we
lose the information about the
wage for rating 5!
Example (Contd.)
Hourly_Emps
• Problems due to R → W: S N L R W H
• Update anomaly: Can we 123-22-3666 Attishoo 48 8 10 40
change W in just the 1st tuple 231-31-5368 Smiley 22 8 10 30
of SNLRWH?
131-24-3650 Smethurst 35 5 7 30
• Insertion anomaly: What if we
want to insert an employee and 434-26-3751 Guldu 35 5 7 32
don’t know the hourly wage for 612-67-4134 Madayan 35 8 10 40
his/her rating?
• Deletion anomaly: If we delete
all employees with rating 5, we
lose the information about the
wage for rating 5!
Example (Contd.)
Hourly_Emps
• Problems due to R → W: S N L R W H
• Update anomaly: Can we 123-22-3666 Attishoo 48 8 10 40
change W in just the 1st tuple 231-31-5368 Smiley 22 8 10 30
of SNLRWH?
131-24-3650 Smethurst 35 5 7 30
• Insertion anomaly: What if we
want to insert an employee and 434-26-3751 Guldu 35 5 7 32
don’t know the hourly wage for 612-67-4134 Madayan 35 8 10 40
his/her rating?
• Deletion anomaly: If we delete
all employees with rating 5, we
lose the information about the
wage for rating 5!
Example (Contd.)
Hourly_Emps
• Problems due to R → W: S N L R W H
• Update anomaly: Can we 123-22-3666 Attishoo 48 8 10 40
change W in just the 1st tuple 231-31-5368 Smiley 22 8 10 30
of SNLRWH?
131-24-3650 Smethurst 35 5 7 30
• Insertion anomaly: What if we
want to insert an employee and 434-26-3751 Guldu 35 5 7 32
don’t know the hourly wage for 612-67-4134 Madayan 35 8 10 40
his/her rating?
• Deletion anomaly: If we delete
all employees with rating 5, we
lose the information about the
wage for rating 5!
• Problems due to R → W: S N L R W H
• Update anomaly: Can we 123-22-3666 Attishoo 48 8 10 40
change W in just the 1st tuple 231-31-5368 Smiley 22 8 10 30
of SNLRWH?
131-24-3650 Smethurst 35 5 7 30
• Insertion anomaly: What if we
want to insert an employee and 434-26-3751 Guldu 35 5 7 32
don’t know the hourly wage for 612-67-4134 Madayan 35 8 10 40
his/her rating?
• Deletion anomaly: If we delete
all employees with rating 5, we
lose the information about the
wage for rating 5!
Using AA, we can get only the FDs in F+ and all these FDs
Reasoning About FDs (Contd.)
• Couple of additional rules (that follow from AA):
• Union: If X → Y and X → Z, then X → YZ
• Decomposition: If X → YZ, then X → Y and X →Z
• Example: Contracts(cid,sid,jid,did,pid,qty,value), and:
• C is the key: C → CSJDPQV
• Job (J) purchases each part (P) using single contract (C): JP → C
• Dept (D) purchases at most one part (P) from a supplier (S): SD → P
• Problem: Prove that SDJ is a key for Contracts
• JP → C, C → CSJDPQV imply JP → CSJDPQV (a key by transitivity)
• SD → P implies SDJ →JP (by augmentation)
• SDJ →JP, JP → CSJDPQV imply SDJ → CSJDPQV (a key by transitivity)
A → B A B
C → B 1 2
4 5
A B C 7 5 A B B C A B C
1 2 3 1 2 2 3 1 2 3
4 5 6 4 5 ⨝ 5 6 4 5 6
B C
7 5 8 7 5 5 8 4 5 8
2 3
7 5 6
5 6
7 5 8
5 8
Lossy!
More on Lossless Join
A → B A C
C → B 1 3
4 6
A B C 7 8 A C B C A B C
1 2 3 1 3 1 2 3
4 5 6 4 6
⨝ 2
5
3
6 4 5 6
B C
7 2 8 7 8 2 8 7 2 8
2 3
5 6
2 8
Non-lossy but we cannot check A→ B
Dependency Preserving Decomposition
• Obviously, the algorithm for lossless join decomp into BCNF can
be used to obtain a lossless join decomp into 3NF (typically, can
stop earlier).
• To ensure dependency preservation, one idea:
• If X → Y is not preserved, add relation XY.
• Problem is that XY may violate 3NF! e.g., consider the addition of CJP to
`preserve’ JP → C. What if we also have J → C ?
• Refinement: Instead of the given set of FDs F, use a minimal
cover for F.
Minimal Cover for a Set of FDs
• Minimal cover G for a set of FDs F:
• Closure of F = closure of G.
• Right hand side of each FD in G is a single attribute.
• If we modify G by deleting an FD or by deleting attributes from an FD in G, the
closure changes.
• Intuitively, every FD in G is needed, and ``as small as possible’’ in order
to get the same closure as F.
• e.g., A → B, ABCD → E, EF → GH, ACDF → EG has the
following minimal cover:
• A → B, ACD → E, EF →G and EF → H
• M.C. → Lossless-Join, Dep. Pres. Decomp!!! (i.e. 3NF)
Summary of Schema Refinement
• If a relation is in BCNF, it is free of redundancies that can be
detected using FDs. Thus, trying to ensure that all relations are in
BCNF is a good heuristic.
• If a relation is not in BCNF, we can try to decompose it into a
collection of BCNF relations.
• Must consider whether all FDs are preserved. If a lossless-join,
dependency preserving decomposition into BCNF is not possible (or
unsuitable, given typical queries), should consider decomposition into
3NF.
• Decompositions should be carried out and/or re-examined while keeping
performance requirements in mind.