Normal Forms (ii) ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Similar documents
Normal Forms 1. ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Schema Refinement and Normal Forms. The Evils of Redundancy. Schema Refinement. Yanlei Diao UMass Amherst April 10, 2007

Schema Refinement and Normal Forms

Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) [R&G] Chapter 19

The Evils of Redundancy. Schema Refinement and Normal Forms. Functional Dependencies (FDs) Example: Constraints on Entity Set. Example (Contd.

The Evils of Redundancy. Schema Refinement and Normal Forms. Example: Constraints on Entity Set. Functional Dependencies (FDs) Example (Contd.

The Evils of Redundancy. Schema Refinement and Normal Forms. Example: Constraints on Entity Set. Functional Dependencies (FDs) Refining an ER Diagram

Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) CIS 330, Spring 2004 Lecture 11 March 2, 2004

Schema Refinement and Normal Forms. Case Study: The Internet Shop. Redundant Storage! Yanlei Diao UMass Amherst November 1 & 6, 2007

CS 186, Fall 2002, Lecture 6 R&G Chapter 15

The Evils of Redundancy. Schema Refinement and Normalization. Functional Dependencies (FDs) Example: Constraints on Entity Set. Refining an ER Diagram

Schema Refinement and Normal Forms Chapter 19

Schema Refinement and Normal Forms

Schema Refinement and Normalization

12/3/2010 REVIEW ALGEBRA. Exam Su 3:30PM - 6:30PM 2010/12/12 Room C9000

Schema Refinement and Normal Forms

Schema Refinement and Normal Forms

CS122A: Introduction to Data Management. Lecture #13: Relational DB Design Theory (II) Instructor: Chen Li

Schema Refinement and Normal Forms. Chapter 19

Schema Refinement. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Introduction. Normalization. Example. Redundancy. What problems are caused by redundancy? What are functional dependencies?

Schema Refinement & Normalization Theory

Schema Refinement & Normalization Theory: Functional Dependencies INFS-614 INFS614, GMU 1

Schema Refinement and Normal Forms. Why schema refinement?

CAS CS 460/660 Introduction to Database Systems. Functional Dependencies and Normal Forms 1.1

Introduction to Data Management. Lecture #7 (Relational DB Design Theory II)

Design theory for relational databases

Introduction to Data Management. Lecture #6 (Relational DB Design Theory)

Lecture #7 (Relational Design Theory, cont d.)

Chapter 3 Design Theory for Relational Databases

Func8onal Dependencies

Introduction to Data Management. Lecture #6 (Relational Design Theory)

Database Design and Normalization

Introduction to Data Management. Lecture #9 (Relational Design Theory, cont.)

Schema Refinement. Feb 4, 2010

CSC 261/461 Database Systems Lecture 13. Spring 2018

MIS Database Systems Schema Refinement and Normal Forms

Design Theory for Relational Databases. Spring 2011 Instructor: Hassan Khosravi

Functional Dependencies

Information Systems for Engineers. Exercise 8. ETH Zurich, Fall Semester Hand-out Due

Normal Forms Lossless Join.

CSC 261/461 Database Systems Lecture 11

SCHEMA NORMALIZATION. CS 564- Fall 2015

Introduction to Data Management. Lecture #10 (DB Design Wrap-up)

INF1383 -Bancos de Dados

DESIGN THEORY FOR RELATIONAL DATABASES. csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Meraji Winter 2018

Chapter 11, Relational Database Design Algorithms and Further Dependencies

Database Design and Implementation

MIS Database Systems Schema Refinement and Normal Forms

Relational Design Theory

10/12/10. Outline. Schema Refinements = Normal Forms. First Normal Form (1NF) Data Anomalies. Relational Schema Design

Functional Dependency and Algorithmic Decomposition

Functional Dependencies and Normalization

Relational Database Design Theory Part II. Announcements (October 12) Review. CPS 116 Introduction to Database Systems

Information Systems (Informationssysteme)

UVA UVA UVA UVA. Database Design. Relational Database Design. Functional Dependency. Loss of Information

CSE 344 AUGUST 6 TH LOSS AND VIEWS

DECOMPOSITION & SCHEMA NORMALIZATION

Relational Design Theory II. Detecting Anomalies. Normal Forms. Normalization

Functional Dependencies, Schema Refinement, and Normalization for Relational Databases. CSC 375, Fall Chapter 19

Lossless Joins, Third Normal Form

Design Theory for Relational Databases

CSC 261/461 Database Systems Lecture 12. Spring 2018

Normalization. October 5, Chapter 19. CS445 Pacific University 1 10/05/17

Consider a relation R with attributes ABCDEF GH and functional dependencies S:

CSE 544 Principles of Database Management Systems

Constraints: Functional Dependencies

CSE 132B Database Systems Applications

But RECAP. Why is losslessness important? An Instance of Relation NEWS. Suppose we decompose NEWS into: R1(S#, Sname) R2(City, Status)

Consider a relation R with attributes ABCDEF GH and functional dependencies S:

Practice and Applications of Data Management CMPSCI 345. Lecture 16: Schema Design and Normalization

Relational Database Design

Functional Dependencies and Normalization. Instructor: Mohamed Eltabakh

Relational Design Theory I. Functional Dependencies: why? Redundancy and Anomalies I. Functional Dependencies

CMPT 354: Database System I. Lecture 9. Design Theory

FUNCTIONAL DEPENDENCY THEORY. CS121: Relational Databases Fall 2017 Lecture 19

Normal Forms. Dr Paolo Guagliardo. University of Edinburgh. Fall 2016

Problem about anomalies

Introduction to Data Management CSE 344

Functional Dependencies. Applied Databases. Not all designs are equally good! An example of the bad design

Databases 2012 Normalization

CS322: Database Systems Normalization

Schema Refinement: Other Dependencies and Higher Normal Forms

Review: Keys. What is a Functional Dependency? Why use Functional Dependencies? Functional Dependency Properties

Design Theory. Design Theory I. 1. Normal forms & functional dependencies. Today s Lecture. 1. Normal forms & functional dependencies

Constraints: Functional Dependencies

Functional Dependency Theory II. Winter Lecture 21

Relational-Database Design

Relational Database Design

CSIT5300: Advanced Database Systems

11/6/11. Relational Schema Design. Relational Schema Design. Relational Schema Design. Relational Schema Design (or Logical Design)

Introduction to Data Management. Lecture #10 (Relational Design Theory, cont.)

Design Theory for Relational Databases

CSC 261/461 Database Systems Lecture 10 (part 2) Spring 2018

Chapter 7: Relational Database Design

HKBU: Tutorial 4

CSE 344 MAY 16 TH NORMALIZATION

Comp 5311 Database Management Systems. 5. Functional Dependencies Exercises

11/1/12. Relational Schema Design. Relational Schema Design. Relational Schema Design. Relational Schema Design (or Logical Design)

Chapter 8: Relational Database Design

Transcription:

ICS 321 Fall 2012 Normal Forms (ii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 1

Hourly_Emps Redundancies & Decompositions SSN Name Lot Rating Hourly_wages Hours_worked 123-22-2366 Attishoo 48 8 10 40 231-31-5368 Smiley 22 8 10 30 131-24-3650 Smethurst 35 5 7 30 434-26-3751 Guldu 35 5 7 32 612-67-4134 Madayan 35 8 10 40 Hourly_Emps SSN Name Lot Rating Hours_ worked 123-22-2366 Attishoo 48 8 40 231-31-5368 Smiley 22 8 30 131-24-3650 Smethurst 35 5 30 434-26-3751 Guldu 35 5 32 612-67-4134 Madayan 35 8 40 RatingWages Rating 5 7 8 10 Hourly_ wages 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 2

Decompositions Reduces redundancies and anomalies, but could have the following potential problems: 1. Some queries become more expensive. 2. Given instances of the decomposed relations, we may not be able to reconstruct the corresponding instance of the original relation! 3. Checking some dependencies may require joining the instances of the decomposed relations. Two desirable properties: Lossless-join decomposition Dependency-preserving decomposition 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 3

Lossless-join Decomposition Decomposition of R into X and Y is lossless-join w.r.t. a set of FDs F if, for every instance r that satisfies F: π X (r) join π Y (r) = r In general one direction π X (r) join π Y (r) r is always true, but the other may not hold. Definition extended to decomposition into 3 or more relations in a straightforward way. It is essential that all decompositions used to deal with redundancy be lossless! (Avoids Problem (2).) 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 4

Conditions for Lossless Join The decomposition of R into X and Y is losslessjoin wrt F if and only if the closure of F contains: X Y X, or X Y Y In particular, the decomposition of R into UV and R - V is losslessjoin if U V holds over R. A B C 1 2 3 4 5 6 7 2 8 A B C 1 2 3 4 5 6 7 2 8 1 2 8 7 2 3 A B 1 2 4 5 7 2 B C 2 3 5 6 2 8 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 5

Chase Test for Lossless Join R(A,B,C,D) is decomposed into S1={A,D}, S2={A,C}, S3={B,C,D} Construct a Tableau One row for each decomposed relation For each row i, subscript an attribute with i if it does not occur in Si. FDs: A B, B C, CD A Rules for equating two rows using FDs: If one is unsubscripted, make the other the same If both are subscripted, make the subscripts the same Goal: one unsubscripted row A B C D a b 1 c 1 d a b 2 c d 2 a 3 b c d A B C D a b 1 cx 1 c d X b1 a b 2 c d 2 ax 3 a b c d one unsubscripted row imply lossless join 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 6 S1 S2 S3

Dependency-preserving Decomposition Student Course Instructor Smith OS Mark F= { SC I, I C } Student Instructor Course Instructor Smith Mark OS Mark Checking SC I requires a join! Dependency preserving decomposition (Intuitive): If R is decomposed into X, Y and Z, and we enforce the FDs that hold on X, on Y and on Z, then all FDs that were given to hold on R must also hold. (Avoids Problem (3).) Projection of set of FDs F: If R is decomposed into X,... projection of F onto X (denoted F X ) is the set of FDs U V in F + (closure of F ) such that U, V are in X. 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 7

Dependency-preserving Decomp. (Cont) Important : F +, not F Decomposition of R into X and Y is dependency preserving if (F X union F Y ) + = F + If we consider only dependencies in the closure F + that can be checked in X without considering Y, and in Y without considering X, these imply all dependencies in F +. Example: ABC decomposed into AB and BC. F={A B, B C, C A}. Is this dependency preserving? Dependency preserving does not imply lossless join: Eg. ABC, A B, decomposed into AB and BC. And vice-versa! (Example?) 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 8

Decomposition into BCNF Consider relation R with FDs F. How do we decompose R into a set of small relations that are in BCNF? Algorithm: If X Y violates BCNF, decompose R into R-Y and XY Repeat until all relations are in BCNF. Example: ABCD, B C, C D, C A. Order in which we deal with the violating FD can lead to different relations! 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 9

BCNF Decomposition Algorithm (3.20) Input: R 0, set of FDs S 0 Output: A decomposition of R 0 into a collection of relations, all of which are in BCNF Initially R = R 0, S=S 0 1. If R is in BCNF, return {R} 2. Let X Y be a violation. a. Compute X+. b. Choose R 1 =X+ c. Let R 2 = X union (R-X+) 3. Compute FD projections S 1 and S 2 for R 1 and R 2 4. Recursively decompose R 1 and R 2 and return the union of the results 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 10

BCNF & Dependency Preservation BCNF decomposition using Algo 3.20 is lossless join BUT in general there may not be a dependency preserving decomposition into BCNF Example: Bookings(Title, City, Theater), with FD s : Th C, TiC Th Not in BCNF. Can t decompose while preserving 2nd FD; This is the motivation for 3NF. 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 11

Decomposition into 3NF Obviously, the algorithm for lossless join decomp into BCNF can be used to obtain a lossless join decomp into 3NF (typically, can stop earlier). How can we ensure dependency preservation? If X Y is not preserved, add relation XY. Problem is that XY may violate 3NF! Example: JP C is not preserved, so add JPC. What if FDs also include J C? Refinement: Instead of the given set of FDs F, use a minimal cover for F. 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 12

Minimum Cover for a Set of FDs Minimal cover or basis 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 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 13

Computing the Minimal Cover Algorithm 1. Put the FDs into standard form X A. RHS is a single attribute. 2. Minimize the LHS of each FD. For each FD, check if we can delete an attribute from LHS while preserving F +. 3. Delete redundant FDs. Minimal covers are not unique. Different order of computation can give different covers. e.g., A B, ABCD E, EF GH, ACDF EG has the following minimal cover: A B, ACD E, EF G and EF H 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 14

3NF Decomposition Algorithm (3.26) Input: R, set of FDs F Output: A decomposition of R into a collection of relations, all of which are in BCNF 1. Find a minimal basis/cover for F, say G 2. For each FD X A in G, use XA as one of the decomposed relations. 3. If none of the relations from Step 2 is a superkey for R, add another relation whose schema is a key for R. 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 15

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. 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 16