CS 564 Database Management Systems: Design and Implementation Discussion Session Friday, Sept 18, 2015 1 Apul Jain.

Slides:



Advertisements
Similar presentations
Schema Refinement: Normal Forms
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
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.
Logical Database Design (3 of 3) John Ortiz. Lecture 7Logical Database Design (2)2 Normalization  If a relation is not in BCNF or 3NF, we refine it by.
CS 440 Database Management Systems Practice problems for normalization.
Manipulating Functional Dependencies Zaki Malik September 30, 2008.
Chapter 11 Functional Dependencies. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.11-2 Topics in this Chapter Basic Definitions Trivial.
Review for Final Exam Lecture Week 14. Problems on Functional Dependencies and Normal Forms.
CS 440 Database Management Systems Lecture 4: Constraints, Schema Design.
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)
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies.
Murali Mani Normalization. Murali Mani What and Why Normalization? To remove potential redundancy in design Redundancy causes several anomalies: insert,
©Silberschatz, Korth and Sudarshan Relational Database Design First Normal Form Pitfalls in Relational Database Design Functional Dependencies Decomposition.
7.1 Chapter 7: Relational Database Design. 7.2 Chapter 7: Relational Database Design Features of Good Relational Design Atomic Domains and First Normal.
CS Algorithm : Decomposition into 3NF  Obviously, the algorithm for lossless join decomp into BCNF can be used to obtain a lossless join decomp.
Classroom Exercise: Normalization
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
Normal Form Design addendum by C. Zaniolo. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Normal Form Design Compute the canonical cover.
Functional Dependencies (Part 3) Presented by Nash Raghavan All page numbers are in reference to Database System Concepts (5 th Edition)
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 9.
Normalization. FarkasCSCE 5202 Reading Assignments  Database Systems The Complete Book: Chapters 3.6, 3.7, 3.8  Following lecture slides are modified.
1 Triggers: Correction. 2 Mutating Tables (Explanation) The problems with mutating tables are mainly with FOR EACH ROW triggers STATEMENT triggers can.
Chapter 14 Advanced Normalization Transparencies © Pearson Education Limited 1995, 2005.
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.
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.
Chapter 7: Relational Database Design. 7.2Unite International CollegeDatabase Management Systems Chapter 7: Relational Database Design Features of Good.
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.
Design Theory for Relational Databases 2015, Fall Pusan National University Ki-Joune Li.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 7: Relational.
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.
BCNF & Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science.
Computing & Information Sciences Kansas State University Tuesday, 27 Feb 2007CIS 560: Database System Concepts Lecture 18 of 42 Tuesday, 27 February 2007.
Computing & Information Sciences Kansas State University Wednesday, 04 Oct 2006CIS 560: Database System Concepts Lecture 17 of 42 Wednesday, 04 October.
CS 564 Database Management Systems: Design and Implementation Lecture 3: Schema Normalization Chapter 19 in Cow Book Slide ACKs: AnHai Doan, Jeff Naughton,
Revisit FDs & BCNF Normalization 1 Instructor: Mohamed Eltabakh
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo Lecture#16: Schema Refinement & 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)
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
CS 405G: Introduction to Database Systems
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies.
Normalization MIS335 Database Systems. Why Normalization? Optimizing database structure Removing duplications Accelerating the instructions Data integrity!
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.
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
© 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 CS 430 Database Theory Winter 2005 Lecture 8: Functional Dependencies Second, Third, and Boyce-Codd Normal Forms.
Computing & Information Sciences Kansas State University Friday, 03 Oct 2007CIS 560: Database System Concepts Lecture 16 of 42 Wednesday, 03 October 2007.
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
Normal Forms Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems June 18, 2016 Some slide content courtesy of Susan Davidson.
Advanced Normalization
CS422 Principles of Database Systems Normalization
CS422 Principles of Database Systems Normalization
Canonical Cover & Normal Forms
Relational Database Design
Advanced Normalization
Canonical Cover & Normal Forms
Functional Dependencies and Normalization
Functional Dependencies and Normalization
Presentation transcript:

CS 564 Database Management Systems: Design and Implementation Discussion Session Friday, Sept 18, Apul Jain

Topics  Functional Dependencies Closure  Attribute Set Closure  Canonical Cover  BCNF  3NF 2

Functional Dependencies Constraint between two sets of attributes A → B Attributes {A1, A2, …., An} uniquely determine set {B1, B2,….., Bk} Enrollment StudentIDNameCourseCreditsSSN 111AliceCS BobCS CharlieCS DanielCS

Functional Dependencies FDs: StudentID → Name {StudentID, Course} → {Name, Credits, SSN} SSN → Name {SSN, Course} → {StudentID, Name, Credits} StudentIDNameCourseCreditsSSN 111AliceCS BobCS CharlieCS DanielCS

Functional Dependencies: Armstrong’s Axioms Reflexivity Given X ⊆ {A1, A2, ……, An} then FD {A1, A2, …. An} → X is a valid FD 5

Functional Dependencies: Armstrong’s Axioms Given X ⊆ {StudentID, Name, Course, Credits, SSN} X = {StudentID, Course} Then {StudentID, Name, Course, Credits, SSN} → {StudentID, Course} is a valid FD formed by applying reflexivity StudentIDNameCourseCreditsSSN 111AliceCS BobCS CharlieCS DanielCS Reflexivity Example:

Functional Dependencies: Armstrong’s Axioms Augmentation Given sets of attributes A, B, C If A → B then {A, C} → {B, C} 7

Functional Dependencies: Armstrong’s Axioms Given StudentID → Name then {StudentID, Course} → {Name, Course} StudentIDNameCourseCreditsSSN 111AliceCS BobCS CharlieCS DanielCS Augmentation Example

Functional Dependencies: Armstrong’s Axioms Transitivity Given two sets of attributes A, B. If A → B B → C then A → C 9

Functional Dependencies: Armstrong’s Axioms If StudentID → SSN and SSN → Name then StudentID → Name StudentIDNameCourseCreditsSSN 111AliceCS BobCS CharlieCS DanielCS Transitivity Example

Functional Dependencies Closure If F is a set of FDs, then closure of F denoted by F + = set of all FDs logically implied by F How to compute: Use Armstrong’s axioms if A ⊆ B then B → A (reflexivity) if A → B then {C, A} → {C, B} (augmentation) if A → B and B → C, then A → C (transitivity) 11

Functional Dependencies Closure: Derived Rules Derived Rules: if A → B and A → C then A → BC (union) if A → BC then A → B and A → C (decomposition) if A → B and BC → D, then AC → D (pseudo-transitivity) 12

Functional Dependencies Closure Algorithm Input: set of attributes X = {A1, …., An}, F (set of FDs) Result = F While (F changes) do: if {B1, B2, ……. Bm} → C is an FD and logically implied by FD’s in F then add {B1, …. Bm} → C to F 13

Functional Dependencies Closure Given FDs: F = {StudentID → Name, {StudentID, Course} → {Classroom, ISSN}, ISSN → Instructor} 14 StudentIDNameCourseInstructorClassroomISSN 111AliceCS564Arun BobCS532Rob CharlieCS564Paris DanielCS532Marc

Functional Dependencies Closure Given FDs: F = {StudentID → Name, {StudentID, Course} → {Classroom, ISSN}, ISSN → Instructor} One iteration of F + = F U { {StudentID, Course} → ISSN [decomposition] {StudentID, Course} → Classroom [decomposition] {StudentID, Course} → Instructor [transitivity] {StudentID, Course} → {Instructor, Classroom} [union rule] } 15 StudentIDNameCourseInstructorClassroomISSN

Topics  Functional Dependencies Closure  Attribute Set Closure  Canonical Cover  BCNF  3NF 16

Attribute Set Closure Given a set of Attributes {A1, A2, …., An} The closure {A1, ….., An} + is the set of attributes B such that {A1, A2, ……, An} → B 17

Attribute Set Closure Algorithm: Input A = set of attributes Let result = A; while (result changes) do for each FD H → K in F do if H ⊆ result add K to result 18

Attribute Set Closure Example: 19 StudentIDNameCourseInstructorClassroomISSN 111AliceCS564Arun BobCS532Rob CharlieCS564Paris DanielCS532Marc F = {StudentID → Name, {StudentID, Course} → {Classroom, ISSN}, ISSN → Instructor}

Attribute Set Closure Example: F = {StudentID → Name, {StudentID, Course} → {Classroom, ISSN}, ISSN → Instructor} Compute {StudentID, Course} + result = {StudentID, Course} result = {StudentID, Course, Name} [StudentID → Name] result = {StudentID, Course, Name, Classroom, ISSN} [{StudentID, Course} → {Classroom, ISSN}] result = {StudentID, Course, Name, Classroom, ISSN, Instructor} [ISSN → Instructor] Since the closure is the entire set of attributes we can verify that {StudentID, Course} is a super key 20

Topics  Functional Dependencies Closure  Attribute Set Closure  Canonical Cover  BCNF  3NF 21

Canonical Cover Algorithm: 1.Standardization of RHS: Rewrite all FDs with 1 attribute on RHS 2. Minimization of LHS For each FD, can the LHS be reduced without affecting the closure? 3. Eliminate redundant FDs (implied by other FDs, trivial FDs) 4. Combine FDs with same LHS 22

Canonical Cover Example: F = {StudentID → Name, {StudentID, Course} → {Classroom, ISSN}, ISSN → Instructor} 23 This is already a canonical cover!

Canonical Cover Example: F = {StudentID → Name, {StudentID, Course, Name} → {Classroom, ISSN}, ISSN → Instructor, {StudentID, Course} → Instructor} 24 Step1 StudentID → Name {StudentID, Course, Name} → Classroom {StudentID, Course, Name} → ISSN ISSN → Instructor {StudentID, Course} → Instructor Steps: 1.Standardization of RHS: 2.Minimization of LHS 3.Eliminate redundant FDs 4.Combine FDs with same LHS

Canonical Cover Example: F = {StudentID → Name, {StudentID, Course, Name} → {Classroom, ISSN}, ISSN → Instructor, {StudentID, Course} → Instructor} 25 Step2 StudentID → Name {StudentID, Course, Name} → Classroom {StudentID, Course, Name} → ISSN ISSN → Instructor {StudentID, Course} → Instructor Steps: 1.Standardization of RHS: 2.Minimization of LHS 3.Eliminate redundant FDs 4.Combine FDs with same LHS

Canonical Cover Example: F = {StudentID → Name, {StudentID, Course, Name} → {Classroom, ISSN}, ISSN → Instructor, {StudentID, Course} → Instructor} 26 Step3 StudentID → Name {StudentID, Course} → Classroom {StudentID, Course} → ISSN ISSN → Instructor {StudentID, Course} → Instructor Steps: 1.Standardization of RHS: 2.Minimization of LHS 3.Eliminate redundant FDs 4.Combine FDs with same LHS

Canonical Cover Example: F = {StudentID → Name, {StudentID, Course, Name} → {Classroom, ISSN}, ISSN → Instructor, {StudentID, Course} → Instructor} 27 Step4 StudentID → Name {StudentID, Course} → Classroom {StudentID, Course} → ISSN ISSN → Instructor {StudentID, Course} → {Classroom, ISSN} Steps: 1.Standardization of RHS: 2.Minimization of LHS 3.Eliminate redundant FDs 4.Combine FDs with same LHS

Topics  Functional Dependencies Closure  Attribute Set Closure  Canonical Cover  BCNF  3NF 28

BCNF X → Y is a trivial functional dependency (Y ⊆ X) or X is a super key for schema R 29

Decomposing a table into BCNF How to decompose a schema into BCNF 1. Find a non trivial FD X → Y that violates BCNF condition (X is not a superkey) 2. Split table into two tables: a.one with attributes XY (all attributes from the FD) b.one with X U {R – Y} 30

Decomposing a table into BCNF Non trivial FDs: Author → Nationality Book title → {Genre, Pages} Key is {Author, Book title} 31 AuthorNationalityBook titleGenrePages HenryDutchSerendipityFiction400 JeffEnglishAutomataTextbook300 DavidAmericanDBMSTextbook500 JohnEnglishDBMSTextbook500 Books

Decomposing a table into BCNF Book title → {Genre, Pages} violates BCNF 32 AuthorNationalityBook title HenryDutchSerendipity JeffEnglishAutomata DavidAmericanDBMS JohnEnglishDBMS Book titleGenrePages SerendipityFiction400 AutomataTextbook300 DBMSTextbook500

Decomposing a table into BCNF 33 AuthorNationality HenryDutch JeffEnglish DavidAmerican JohnEnglish AuthorBook title HenrySerendipity JeffAutomata DavidDBMS JohnDBMS Author → Nationality violates BCNF Key is {Author, Book title} AuthorNationalityBook title HenryDutchSerendipity JeffEnglishAutomata DavidAmericanDBMS JohnEnglishDBMS

Decomposing a table into BCNF 34 Final schema AuthorNationality HenryDutch JeffEnglish DavidAmerican JohnEnglish AuthorBook title HenrySerendipity JeffAutomata DavidDBMS JohnDBMS Book titleGenrePages SerendipityFiction400 AutomataTextbook300 DBMSTextbook500

Topics  Functional Dependencies Closure  Attribute Set Closure  Canonical Cover  BCNF  3NF 35

3NF Given a relation schema R and a set of FDs F, we say R is in 3NF if for every FD X → A in F (X is a subset of R’s attributes and A is a single attribute), we have: X → A is a trivial FD or X is a superkey for R or A is part of some key for R 36

Decompose a schema into 3NF Consider relation R: Advisor {StudentID, AdvisorID, SDept, ADept} F = {StudentID → SDept, AdvisorID → ADept} Key is {StudentID, AdvisorID} R is not in 3NF 37 3NF Conditions: X → A is a trivial FD or X is a superkey for R or A is part of some key for R

Decompose a schema into 3NF Consider relation R: Advisor {StudentID, AdvisorID, SDept, ADept} F = {StudentID → SDept, AdvisorID → ADept} Key is {StudentID, AdvisorID} R is not in 3NF How to decompose? Follow the same algorithm as BCNF R1 = {StudentID, SDept} and R2 = {AdvisorID, ADept}, R3 = {StudentID, AdvisorID} 38 3NF Conditions: X → A is a trivial FD or X is a superkey for R or A is part of some key for R

Decompose a schema into 3NF Tennis Key is {Tournament, Year} Winner → Winner D.O.B. Winner D.O.B. is not a part of Key and Winner is not a super key, so it’s not in 3NF 39 TournamentYearWinnerWinner D.O.B French Open2010Rafael Nadal3 June 1986 Wimbledon2015Novak Djokovic22 May 1987 US Open2013Rafael Nadal3 June 1986 French Open2009Roger Federer8 August 1981

Decompose a schema into 3NF 40 TournamentYearWinner French Open2010Rafael Nadal Wimbeldeon2015Novak Djokovic US Open2013Rafael Nadal French Open2009Roger Federer WinnerWinner D.O.B Rafael Nadal3 June 1986 Novak Djokovic22 May 1987 Roger Federer8 August 1981 TournamentYearWinnerWinner D.O.B French Open2010Rafael Nadal3 June 1986 Wimbeldeon2015Novak Djokovic22 May 1987 US Open2013Rafael Nadal3 June 1986 French Open2009Roger Federer8 August 1981

Decompose a schema into 3NF 41 TournamentYearWinner French Open2010Rafael Nadal Wimbeldeon2015Novak Djokovic US Open2013Rafael Nadal French Open2009Roger Federer WinnerWinner D.O.B Rafael Nadal3 June 1986 Novak Djokovic22 May 1987 Roger Federer8 August 1981 Verify this is also in BCNF

3NF but not BCNF Example Set of attributes = {A, B, C, D} FDs: {A, B, C} → D and D → A Candidate Keys : {A, B, C} and {B, C, D} BCNF check: {A, B, C} → D : {A, B, C} is a candidate key, so it’s fine D → A : D is not a super key, so it is not in BCNF 42

3NF but not BCNF Example Set of attributes = {A, B, C, D} FDs: {A, B, C} → D and D → A Candidate Keys : {A, B, C} and {B, C, D} 3NF check: {A, B, C} → D : {A, B, C} is a candidate key. D → A : D is not a super key, but A is a part of super key {A, B, C}, so it is ok. Since both FDs are fine, this relation is in 3NF There is no way to decompose it into BCNF with dependency preservation 43