Download presentation
Presentation is loading. Please wait.
Published byBrook Jones Modified over 9 years ago
1
CS 564 Database Management Systems: Design and Implementation Discussion Session Friday, Sept 18, 2015 1 Apul Jain
2
Topics Functional Dependencies Closure Attribute Set Closure Canonical Cover BCNF 3NF 2
3
Functional Dependencies Constraint between two sets of attributes A → B Attributes {A1, A2, …., An} uniquely determine set {B1, B2,….., Bk} Enrollment StudentIDNameCourseCreditsSSN 111AliceCS564412345 112BobCS532413124 113CharlieCS564432123 114DanielCS760345415 3
4
Functional Dependencies FDs: StudentID → Name {StudentID, Course} → {Name, Credits, SSN} SSN → Name {SSN, Course} → {StudentID, Name, Credits} StudentIDNameCourseCreditsSSN 111AliceCS564412345 112BobCS532413124 113CharlieCS564432123 114DanielCS760345415 4
5
Functional Dependencies: Armstrong’s Axioms Reflexivity Given X ⊆ {A1, A2, ……, An} then FD {A1, A2, …. An} → X is a valid FD 5
6
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 111AliceCS564412345 112BobCS532413124 113CharlieCS564432123 114DanielCS760345415 6 Reflexivity Example:
7
Functional Dependencies: Armstrong’s Axioms Augmentation Given sets of attributes A, B, C If A → B then {A, C} → {B, C} 7
8
Functional Dependencies: Armstrong’s Axioms Given StudentID → Name then {StudentID, Course} → {Name, Course} StudentIDNameCourseCreditsSSN 111AliceCS564412345 112BobCS532413124 113CharlieCS564432123 114DanielCS760345415 8 Augmentation Example
9
Functional Dependencies: Armstrong’s Axioms Transitivity Given two sets of attributes A, B. If A → B B → C then A → C 9
10
Functional Dependencies: Armstrong’s Axioms If StudentID → SSN and SSN → Name then StudentID → Name StudentIDNameCourseCreditsSSN 111AliceCS564412345 112BobCS532413124 113CharlieCS564432123 114DanielCS760345415 10 Transitivity Example
11
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
12
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
13
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
14
Functional Dependencies Closure Given FDs: F = {StudentID → Name, {StudentID, Course} → {Classroom, ISSN}, ISSN → Instructor} 14 StudentIDNameCourseInstructorClassroomISSN 111AliceCS564Arun1210657-989 112BobCS532Rob1351878-090 113CharlieCS564Paris1325667-989 114DanielCS532Marc1214456-878
15
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
16
Topics Functional Dependencies Closure Attribute Set Closure Canonical Cover BCNF 3NF 16
17
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
18
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
19
Attribute Set Closure Example: 19 StudentIDNameCourseInstructorClassroomISSN 111AliceCS564Arun1210657-989 112BobCS532Rob1351878-090 113CharlieCS564Paris1325667-989 114DanielCS532Marc1214456-878 F = {StudentID → Name, {StudentID, Course} → {Classroom, ISSN}, ISSN → Instructor}
20
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
21
Topics Functional Dependencies Closure Attribute Set Closure Canonical Cover BCNF 3NF 21
22
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
23
Canonical Cover Example: F = {StudentID → Name, {StudentID, Course} → {Classroom, ISSN}, ISSN → Instructor} 23 This is already a canonical cover!
24
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
25
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
26
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
27
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
28
Topics Functional Dependencies Closure Attribute Set Closure Canonical Cover BCNF 3NF 28
29
BCNF X → Y is a trivial functional dependency (Y ⊆ X) or X is a super key for schema R 29
30
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
31
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
32
Decomposing a table into BCNF Book title → {Genre, Pages} violates BCNF 32 AuthorNationalityBook title HenryDutchSerendipity JeffEnglishAutomata DavidAmericanDBMS JohnEnglishDBMS Book titleGenrePages SerendipityFiction400 AutomataTextbook300 DBMSTextbook500
33
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
34
Decomposing a table into BCNF 34 Final schema AuthorNationality HenryDutch JeffEnglish DavidAmerican JohnEnglish AuthorBook title HenrySerendipity JeffAutomata DavidDBMS JohnDBMS Book titleGenrePages SerendipityFiction400 AutomataTextbook300 DBMSTextbook500
35
Topics Functional Dependencies Closure Attribute Set Closure Canonical Cover BCNF 3NF 35
36
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
37
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
38
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
39
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
40
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
41
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
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} 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
43
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.