Normalization DB Tuning CS186 Final Review Session.

Slides:



Advertisements
Similar presentations
Schema Refinement and Normal Forms
Advertisements

Normalization 1 Instructor: Mohamed Eltabakh Part II.
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Physical Database Design Section Chapter 20.
CS Schema Refinement and Normal Forms Chapter 19.
CS Algorithm : Decomposition into 3NF  Obviously, the algorithm for lossless join decomp into BCNF can be used to obtain a lossless join decomp.
Normalization DB Tuning CS186 Final Review Session.
H.Lu/HKUST L02: Logical Database Design  Introduction  Functional Dependencies  Normal Forms  Normalization by decomposition.
1 Normalization Chapter What it’s all about Given a relation, R, and a set of functional dependencies, F, on R. Assume that R is not in a desirable.
Schema Refinement and Normal Forms. The Evils of Redundancy v Redundancy is at the root of several problems associated with relational schemas: – redundant.
1 Schema Refinement and Normal Forms Chapter 19 Raghu Ramakrishnan and J. Gehrke (second text book) In Course Pick-up box tomorrow.
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
Cs3431 Normalization Part II. cs3431 Attribute Closure : Example Consider R (A, B, C, D, E) with FDs A  B, B  C, CD  E Does A  E hold ? (Is A  E.
1 Schema Refinement and Normal Forms Yanlei Diao UMass Amherst April 10, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Functional Dependencies CS 186, Spring 2006, Lecture 21 R&G Chapter 19 Science is the knowledge of consequences, and dependence of one fact upon another.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
Database Management Systems, R. Ramakrishnan and J. Gehrke 1 Schema Refinement and Normal Forms Chapter 19 Instructor: Mirsad Hadzikadic.
Schema Refinement and Normal Forms Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Relational Database Design by Relational Database Design by Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING.
Normal Forms1. 2 The Problems of Redundancy Redundancy is at the root of several problems associated with relational schemas: Wastes storage Causes problems.
CSCD34 - Data Management Systems - A. Vaisman1 Schema Refinement and Normal Forms.
Schema Refinement and Normalization. Functional Dependencies (Review) A functional dependency X  Y holds over relation schema R if, for every allowable.
Schema Refinement and Normal Forms Chapter 19 1 Database Management Systems 3ed, R.Ramakrishnan & J.Gehrke.
CS143 Review: Normalization Theory Q: Is it a good table design? We can start with an ER diagram or with a large relation that contain a sample of the.
THIRD NORMAL FORM (3NF) A relation R is in BCNF if whenever a FD XA holds in R, one of the following statements is true: XA is a trivial FD, or X is.
1 Schema Refinement, Normalization, and Tuning. 2 Design Steps v The design steps: 1.Real-World 2. ER model 3. Relational Schema 4. Better relational.
Functional Dependencies and Normalization 1 Instructor: Mohamed Eltabakh
LECTURE 5: Schema Refinement and Normal Forms SOME OF THESE SLIDES ARE BASED ON YOUR TEXT BOOK.
R EVIEW. 22 Exam Su 3:30PM - 6:30PM 2010/12/12 Room C9000.
Functional Dependencies and Normalization R&G Chapter 19 Lecture 26 Science is the knowledge of consequences, and dependence of one fact upon another.
Christoph F. Eick: Functional Dependencies, BCNF, and Normalization 1 Functional Dependencies, BCNF and Normalization.
Functional Dependencies And Normalization R&G Chapter 19.
CHAPTER 19 SCHEMA, REFINEMENT AND NORMAL FORMS
Database Systems/COMP4910/Spring02/Melikyan1 Schema Refinement and Normal Forms.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
1 Schema Refinement and Normal Forms Week 6. 2 The Evils of Redundancy  Redundancy is at the root of several problems associated with relational schemas:
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
1 Functional Dependencies. 2 Motivation v E/R  Relational translation problems : –Often discover more “detailed” constraints after translation (upcoming.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 15.
Functional Dependencies R&G Chapter 19 Science is the knowledge of consequences, and dependence of one fact upon another. Thomas Hobbes ( )
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
1 Schema Refinement and Normal Forms Chapter The Evils of Redundancy  Redundancy is at the root of several problems associated with relational.
CS542 1 Schema Refinement Chapter 19 (part 1) Functional Dependencies.
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
© D. Wong Functional Dependencies (FD)  Given: relation schema R(A1, …, An), and X and Y be subsets of (A1, … An). FD : X  Y means X functionally.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
1 Schema Refinement and Normal Forms Chapter The Evils of Redundancy  Redundancy causes several problems associated with relational schemas: 
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
1 CS122A: Introduction to Data Management Lecture #13: Relational DB Design Theory (II) Instructor: Chen Li.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Functional Dependencies and Schema Refinement
Introduction to Database Systems Functional Dependencies
Schema Refinement and Normal Forms
Normalization First Normal Form (1NF) Boyce-Codd Normal Form (BCNF)
Functional Dependencies, BCNF and Normalization
Functional Dependencies, BCNF and Normalization
Schema Refinement & Normalization Theory
Functional Dependencies
Functional Dependencies and Normalization
Schema Refinement and Normalization
Schema Refinement and Normal Forms
Functional Dependencies
Normalization Part II cs3431.
Schema Refinement and Normalization
Schema Refinement and Normal Forms
Schema Refinement and Normalization
Schema Refinement and Normal Forms
Functional Dependencies and Normalization
Presentation transcript:

Normalization DB Tuning CS186 Final Review Session

Plan Functional Dependencies, Rules of Inference Candidate Keys Normal forms (BCNF/3NF) Decomposition –BCNF –Lossless –Dependency preserving –3NF + Minimal cover

Functional Dependencies A functional dependency X  Y holds over relation schema R if, for every allowable instance r of R: t1  r, t2  r,  X (t1) =  X (t2) implies  Y (t1) =  Y (t2) (where t1 and t2 are tuples;X and Y are sets of attributes) In other words: X  Y means Given any two tuples in r, if the X values are the same, then the Y values must also be the same. (but not vice versa!!) Can read “  ” as “determines”

Rules of Inference Armstrong’s Axioms (X, Y, Z are sets of attributes): –Reflexivity: If X  Y, then X  Y –Augmentation: If X  Y, then XZ  YZ for any Z –Transitivity: If X  Y and Y  Z, then X  Z Some 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

Plan Functional Dependencies, Rules of Inference Candidate Keys Normal forms (BCNF/3NF) Decomposition –BCNF –Lossless –Dependency preserving –3NF + Minimal cover

Candidate Keys R = {A, B, C, D, E} F = { B  CD, D  E, B  A, E  C, AD  B } Is B  E in F + ? B + = B B + = BCD B + = BCDA B + = BCDAE … Yes! and B is a key for R too! Is D a key for R? D + = D D + = DE D + = DEC … Nope! Is AD a key for R? AD + = AD AD + = ABD and B is a key, so Yes! Is AD a candidate key for R? A + = A, D+ = DEC … A,D not keys, so Yes! Is ADE a candidate key for R? … No! AD is a key, so ADE is a superkey, but not a candidate key

Plan Functional Dependencies, Rules of Inference Candidate Keys Normal forms (BCNF/3NF) Decomposition –BCNF –Lossless –Dependency preserving –3NF + Minimal cover

Boyce-Codd Normal Form (BCNF) Reln R with FDs F is in BCNF if, for all X  A in F + –A  X (called a trivial FD), or –X is a superkey for R. In other words: “R is in BCNF if the only non- trivial FDs over R are key constraints.”

Third Normal Form (3NF) Reln R with FDs F is in 3NF if, for all X  A in F + A  X (called a trivial FD), or X is a superkey of R, or A is part of some candidate key (not superkey!) for R. (sometimes stated as “A is prime”) If R is in BCNF, obviously in 3NF. –Lossless-join, dependency-preserving decomposition of R into a collection of 3NF relations always possible.

Plan Functional Dependencies, Rules of Inference Candidate Keys Normal forms (BCNF/3NF) Decomposition –BCNF –Lossless –Dependency preserving –3NF + Minimal cover

Lossless Decomposition The decomposition of R into X and Y is lossless with respect to F if and only if the closure of F contains: X  Y  X, or X  Y  Y Useful result: If W  Z holds over R and W  Z is empty, then decomposition of R into R-Z and WZ is loss-less. i.e. the common attributes form a superkey for one side or the other

Dependency Preserving Decompositions Decomposition of R into X and Y is dependency preserving if (F X  F Y ) + = F + –i.e., 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 +. Important to consider F + in this definition: –ABC, A  B, B  C, C  A, decomposed into AB and BC. F+ also contains B  A, A  C, C  B … F AB contains A  B and B  A; F BC contains B  C and C  B So, (F AB  F BC) + contains C  A

BCNF Decomposition For each FD in F+ that violates BCNF, X  A Decompose R into (R - A) and XA If either (R - A) or XA is not in BCNF, decompose recursively Guaranteed to be lossless but not dependency preserving

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 –Do we need ACDF  EG? It can be derived from ACD  E and EF  G. Same for ACDF  E, ACDF  G

3NF Decomposition Compute minimal cover For each FD X  A in minimal cover that is not preserved –Add relation XA Guaranteed to be lossless AND dependency preserving

We will concentrate on Contracts, denoted as CSJDPQV. The following ICs are given to hold: JP C, SD P, C is the primary key. – C and JP are candidate keys – 3NF normal form Contracts (Cid, Sid, Jid, Did, Pid, Qty, Val) Depts (Did, Budget, Report) Suppliers (Sid, Address) Parts (Pid, Cost) Projects (Jid, Mgr) Tuning the Schema

BCNF Decomposition Use SD  P, we get SDP and CSJDQV Lossless but not dependency-preserving (JP  C) Three options –Leave it in 3NF without decomposition –Add JPC as an extra table (redundancy across relations) –Create an assertion to enforce JP  C Acceptable when updates are infrequent

CREATE ASSERTION checkDep CHECK (NOT EXISTS (SELECT * FROM PartInfo PI, ContractInfo CI WHERE PI.supplierid=CI.supplierid AND PI.deptid = CI.deptid GROUP BY CI.projectid, PI.partid HAVING COUNT (cid) > 1 ) Check Assertion (JP  C) PartInfo: SDP ContractInfo: CSJDQV Lossless join on SD Group By JP Count C

Questions?

Don’t forget.. Relational algebra, calculus Query optimization –Nested loop, index nested, block nested, hash.. –Computing costs –Enumerating plans Good luck!