CMU SCS Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies.

Slides:



Advertisements
Similar presentations
Announcements Read 6.1 – 6.3 for Wednesday Project Step 3, due now Homework 5, due Friday 10/22 Project Step 4, due Monday Research paper –List of sources.
Advertisements

Manipulating Functional Dependencies Zaki Malik September 30, 2008.
CS 440 Database Management Systems Lecture 4: Constraints, Schema Design.
Chapter 3 Notes. 3.1 Functional Dependencies A functional dependency is a statement that – two tuples of a relation that agree on some particular set.
Temple University – CIS Dept. CIS616– Principles of Data Management V. Megalooikonomou Functional Dependencies (based on notes by Silberchatz,Korth, and.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Integrity Constraints.
Database Management COP4540, SCS, FIU Functional Dependencies (Chapter 14)
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
Normalization DB Tuning CS186 Final Review Session.
Normalization DB Tuning CS186 Final Review Session.
Multivalued Dependency Prepared by Tomasz Kaciak CS157A.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
CMSC424: Database Design Instructor: Amol Deshpande
1 Database Design Theory Which tables to have in a database Normalization.
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 9.
Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Cs3431 Normalization. cs3431 Why Normalization? To remove potential redundancy in design Redundancy causes several anomalies: insert, delete and update.
1 Functional Dependency and Normalization Informal design guidelines for relation schemas. Functional dependencies. Normal forms. Normalization.
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.
1 Database Theory and Methodology. 2 The Good and the Bad So far we have not developed any measure of “goodness” to measure the quality of the design,
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
Computing & Information Sciences Kansas State University Monday, 13 Oct 2008CIS 560: Database System Concepts Lecture 18 of 42 Monday, 13 October 2008.
Normal Forms1. 2 The Problems of Redundancy Redundancy is at the root of several problems associated with relational schemas: Wastes storage Causes problems.
Lecture 6 Normalization: Advanced forms. Objectives How inference rules can identify a set of all functional dependencies for a relation. How Inference.
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.
Functional Dependencies An example: loan-info= Observe: tuples with the same value for lno will always have the same value for amt We write: lno  amt.
Computing & Information Sciences Kansas State University Tuesday, 27 Feb 2007CIS 560: Database System Concepts Lecture 18 of 42 Tuesday, 27 February 2007.
Ihr Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Chapter 10 Functional Dependencies and Normalization for Relational Databases.
Ihr Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Chapter 10 Functional Dependencies and Normalization for Relational Databases.
CS 564 Database Management Systems: Design and Implementation Discussion Session Friday, Sept 18, Apul Jain.
Logical Database Design (1 of 3) John Ortiz Lecture 6Logical Database Design (1)2 Introduction  The logical design is a process of refining DB schema.
1 Lecture 6: Schema refinement: Functional dependencies
Functional Dependencies. FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo Lecture#16: Schema Refinement & Normalization.
Christoph F. Eick: Functional Dependencies, BCNF, and Normalization 1 Functional Dependencies, BCNF and Normalization.
1 Dept. of CIS, Temple Univ. CIS616/661 – Principles of Data Management V. Megalooikonomou Integrity Constraints (based on slides by C. Faloutsos at CMU)
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Schema Refinement SHIRAJ MOHAMED M | MIS 1. Learning Objectives  Identify update, insertion and deletion anomalies  Identify possible keys given an.
© D. Wong Ch. 3 (continued)  Database design problems  Functional Dependency  Keys of relations  Decompositions based on Functional Dependency.
Minimum Cover of 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.
1 Functional Dependencies. 2 Motivation v E/R  Relational translation problems : –Often discover more “detailed” constraints after translation (upcoming.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Database Design and Normalization (based on notes by Silberchatz,Korth,
Functional Dependencies R&G Chapter 19 Science is the knowledge of consequences, and dependence of one fact upon another. Thomas Hobbes ( )
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
MIS 3053 Database Design And Applications The University Of Tulsa Professor: Akhilesh Bajaj Normal Forms Lecture 1 © Akhilesh Bajaj, 2000, 2002, 2003.
CS 222 Database Management System Spring Lecture 4 Database Design Theory Korra Sathya Babu Department of Computer Science NIT Rourkela.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Database design and normalization.
CS542 1 Schema Refinement Chapter 19 (part 1) Functional Dependencies.
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
Databases 1 Sixth lecture. 2 Functional Dependencies X -> A is an assertion about a relation R that whenever two tuples of R agree on all the attributes.
© 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 Dept. of CIS, Temple Univ. CIS661 – Principles of Data Management V. Megalooikonomou Database design and normalization (based on slides by C. Faloutsos.
1 CS 430 Database Theory Winter 2005 Lecture 8: Functional Dependencies Second, Third, and Boyce-Codd Normal Forms.
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.
Faloutsos & Pavlo SCS /615 Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization.
Lecture #17: Schema Refinement & Normalization - Normal Forms
Temple University – CIS Dept. CIS331– Principles of Database Systems
Chapter 19 (part 1) Functional Dependencies
CSC 453 Database Systems Lecture
Presentation transcript:

CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies (R&G, ch. 19)

CMU SCS Faloutsos & PavloSCS /6152 Functional dependencies motivation: ‘good’ tables takes1 (ssn, c-id, grade, name, address) ‘good’ or ‘bad’?

CMU SCS Faloutsos & PavloSCS /6153 Functional dependencies takes1 (ssn, c-id, grade, name, address)

CMU SCS Faloutsos & PavloSCS /6154 Functional dependencies ‘Bad’ – Q: why?

CMU SCS Faloutsos & PavloSCS /6155 Functional Dependencies A: Redundancy –space –inconsistencies –insertion/deletion anomalies (later…) Q: What caused the problem?

CMU SCS Faloutsos & PavloSCS /6156 Functional dependencies A: ‘name’ depends on the ‘ssn’ define ‘depends’

CMU SCS Faloutsos & PavloSCS /6157 Overview Functional dependencies –why –definition –Armstrong’s “axioms” –closure and cover

CMU SCS Faloutsos & PavloSCS /6158 Functional dependencies Definition: ‘a’ functionally determines ‘b’

CMU SCS Faloutsos & PavloSCS /6159 Functional dependencies Informally: ‘if you know ‘a’, there is only one ‘b’ to match’

CMU SCS Faloutsos & PavloSCS /61510 Functional dependencies formally: if two tuples agree on the ‘X’ attribute, the *must* agree on the ‘Y’ attribute, too (eg., if ssn is the same, so should address)

CMU SCS Faloutsos & PavloSCS /61511 Functional dependencies ‘X’, ‘Y’ can be sets of attributes Q: other examples?? (no repeat courses)

CMU SCS Faloutsos & PavloSCS /61512 Functional dependencies ssn -> name, address ssn, c-id -> grade

CMU SCS Faloutsos & PavloSCS /61513 Overview Functional dependencies –why –definition –Armstrong’s “axioms” –closure and cover

CMU SCS Faloutsos & PavloSCS /61514 Master goal Given tables –STUDENT(ssn, ….) –TAKES( ssn, cid, …) And FD (ssn -> …, cid-> …) WRITE CODE To automatically generate ‘good’ schemas

CMU SCS Faloutsos & PavloSCS /61515 Functional dependencies Closure of a set of FD: all implied FDs - eg.: ssn -> name, address ssn, c-id -> grade imply ssn, c-id -> grade, name, address ssn, c-id -> ssn

CMU SCS Faloutsos & PavloSCS /61516 FDs - Armstrong’s axioms Closure of a set of FD: all implied FDs - eg.: ssn -> name, address ssn, c-id -> grade how to find all the implied ones, systematically?

CMU SCS Faloutsos & PavloSCS /61517 FDs - Armstrong’s axioms “Armstrong’s axioms” guarantee soundness and completeness: Reflexivity: eg., ssn, name -> ssn Augmentation eg., ssn->name then ssn,grade-> name,grade

CMU SCS Faloutsos & PavloSCS /61518 FDs - Armstrong’s axioms Transitivity ssn -> address address -> county-tax-rate THEN: ssn -> county-tax-rate

CMU SCS Faloutsos & PavloSCS /61519 FDs - Armstrong’s axioms Reflexivity: Augmentation: Transitivity: ‘sound’ and ‘complete’

CMU SCS Faloutsos & PavloSCS /61520 FDs - Armstrong’s axioms Additional rules: Union Decomposition Pseudo-transitivity

CMU SCS Faloutsos & PavloSCS /61521 FDs - Armstrong’s axioms Prove ‘Union’ from three axioms:

CMU SCS Faloutsos & PavloSCS /61522 FDs - Armstrong’s axioms Prove ‘Union’ from three axioms:

CMU SCS Faloutsos & PavloSCS /61523 FDs - Armstrong’s axioms Prove Pseudo-transitivity:

CMU SCS Faloutsos & PavloSCS /61524 FDs - Armstrong’s axioms Prove Decomposition

CMU SCS Faloutsos & PavloSCS /61525 Overview Functional dependencies –why –definition –Armstrong’s “axioms” –closure and cover

CMU SCS Faloutsos & PavloSCS /61526 FDs - Closure F+ Given a set F of FD (on a schema) F+ is the set of all implied FD. Eg., takes(ssn, c-id, grade, name, address) ssn, c-id -> grade ssn-> name, address }F}F

CMU SCS Faloutsos & PavloSCS /61527 FDs - Closure F+ ssn, c-id -> grade ssn-> name, address ssn-> ssn ssn, c-id-> address c-id, address-> c-id... F+

CMU SCS Faloutsos & PavloSCS /61528 FDs - Closure A+ Given a set F of FD (on a schema) A+ is the set of all attributes determined by A: takes(ssn, c-id, grade, name, address) ssn, c-id -> grade ssn-> name, address {ssn}+ =?? }F}F

CMU SCS Faloutsos & PavloSCS /61529 FDs - Closure A+ takes(ssn, c-id, grade, name, address) ssn, c-id -> grade ssn-> name, address {ssn}+ ={ssn, name, address } }F}F

CMU SCS Faloutsos & PavloSCS /61530 FDs - Closure A+ takes(ssn, c-id, grade, name, address) ssn, c-id -> grade ssn-> name, address {c-id}+ = ?? }F}F

CMU SCS Faloutsos & PavloSCS /61531 FDs - Closure A+ takes(ssn, c-id, grade, name, address) ssn, c-id -> grade ssn-> name, address {c-id, ssn}+ = ?? }F}F

CMU SCS Faloutsos & PavloSCS /61532 FDs - Closure A+ if A+ = {all attributes of table} then ‘A’ is a superkey

CMU SCS Faloutsos & PavloSCS /61533 FDs - A+ closure - not in book Diagrams AB->C (1) A->BC (2) B->C (3) A->B (4) C A B

CMU SCS Faloutsos & PavloSCS /61534 FDs - ‘canonical cover’ Fc Given a set F of FD (on a schema) Fc is a minimal set of equivalent FD. Eg., takes(ssn, c-id, grade, name, address) ssn, c-id -> grade ssn-> name, address ssn,name-> name, address ssn, c-id-> grade, name F

CMU SCS Faloutsos & PavloSCS /61535 FDs - ‘canonical cover’ Fc ssn, c-id -> grade ssn-> name, address ssn,name-> name, address ssn, c-id-> grade, name F Fc takes(ssn, c-id, grade, name, address)

CMU SCS Faloutsos & PavloSCS /61536 FDs - ‘canonical cover’ Fc why do we need it? define it properly compute it efficiently

CMU SCS Faloutsos & PavloSCS /61537 FDs - ‘canonical cover’ Fc why do we need it? –easier to compute candidate keys define it properly compute it efficiently

CMU SCS Faloutsos & PavloSCS /61538 FDs - ‘canonical cover’ Fc define it properly - three properties –1) the RHS of every FD is a single attribute –2) the closure of Fc is identical to the closure of F (ie., Fc and F are equivalent) –3) Fc is minimal (ie., if we eliminate any attribute from the LHS or RHS of a FD, property #2 is violated

CMU SCS Faloutsos & PavloSCS /61539 #3: we need to eliminate ‘extraneous’ attributes. An attribute is ‘extraneous if – the closure is the same, before and after its elimination –or if F-before implies F-after and vice-versa FDs - ‘canonical cover’ Fc

CMU SCS Faloutsos & PavloSCS /61540 FDs - ‘canonical cover’ Fc ssn, c-id -> grade ssn-> name, address ssn,name-> name, address ssn, c-id-> grade, name F

CMU SCS Faloutsos & PavloSCS /61541 FDs - ‘canonical cover’ Fc Algorithm: examine each FD; drop extraneous LHS or RHS attributes; or redundant FDs make sure that FDs have a single attribute in their RHS repeat until no change

CMU SCS Faloutsos & PavloSCS /61542 FDs - ‘canonical cover’ Fc Trace algo for AB->C (1) A->BC (2) B->C (3) A->B (4)

CMU SCS Faloutsos & PavloSCS /61543 FDs - ‘canonical cover’ Fc Trace algo for AB->C (1) A->BC (2) B->C (3) A->B (4) split (2): AB->C (1) A->B (2’) A->C (2’’) B->C (3) A->B (4)

CMU SCS Faloutsos & PavloSCS /61544 FDs - ‘canonical cover’ Fc AB->C (1) A->B (2’) A->C (2’’) B->C (3) A->B (4) AB->C (1) A->C (2’’) B->C (3) A->B (4)

CMU SCS Faloutsos & PavloSCS /61545 FDs - ‘canonical cover’ Fc AB->C (1) A->C (2’’) B->C (3) A->B (4) (2’’): redundant (implied by (4), (3) and transitivity AB->C (1) B->C (3) A->B (4)

CMU SCS Faloutsos & PavloSCS /61546 FDs - ‘canonical cover’ Fc B->C (1’) B->C (3) A->B (4) AB->C (1) B->C (3) A->B (4) in (1), ‘A’ is extraneous: (1),(3),(4) imply (1’),(3),(4), and vice versa

CMU SCS Faloutsos & PavloSCS /61547 FDs - ‘canonical cover’ Fc B->C (3) A->B (4) B->C (1’) B->C (3) A->B (4) nothing is extraneous all RHS are single attributes final and original set of FDs are equivalent (same closure)

CMU SCS Faloutsos & PavloSCS /61548 FDs - ‘canonical cover’ Fc AFTER B->C (3) A->B (4) BEFORE AB->C (1) A->BC (2) B->C (3) A->B (4) R(A,B,C)

CMU SCS Faloutsos & PavloSCS /61549 Overview - conclusions Functional dependencies –why –definition –Armstrong’s “axioms” –closure and cover