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.

Slides:



Advertisements
Similar presentations
1 Lecture 7 Design Theory for Relational Databases (part 1) Slides based on
Advertisements

Manipulating Functional Dependencies Zaki Malik September 30, 2008.
Functional Dependencies
1 Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms.
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.
Database Management COP4540, SCS, FIU Functional Dependencies (Chapter 14)
Database Management Systems Chapter 3 The Relational Data Model (II) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Functional Dependencies - Example
Topics to be discusses Functional Dependency Key
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 227 Database Systems I Design Theory for Relational Databases.
Functional Dependencies
Functional Dependencies. Babies At a birth, there is one baby (twins would be represented by two births), one mother, any number of nurses, and a doctor.
1 The Relational Data Model Functional Dependencies.
1 Multivalued Dependencies Fourth Normal Form. 2 Definition of MVD uA multivalued dependency (MVD) on R, X ->->Y, says that if two tuples of R agree on.
Functional Dependencies Definition: If two tuples agree on the attributes A, A, … A 12n then they must also agree on the attributes B, B, … B 12m Formally:
1 Functional Dependencies Meaning of FD’s Keys and Superkeys Inferring FD’s.
1 Functional Dependencies Meaning of FD’s Keys and Superkeys Inferring FD’s Source: slides by Jeffrey Ullman.
The principal problem that we encounter is redundancy, where a fact is repeated in more than one tuple. Most common cause: attempts to group into one relation.
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 9.
1 Multivalued Dependencies Fourth Normal Form. 2 A New Form of Redundancy uMultivalued dependencies (MVD’s) express a condition among tuples of a relation.
1 Normalization Anomalies Boyce-Codd Normal Form 3 rd Normal Form.
Fall 2001Arthur Keller – CS 1803–1 Schedule Today Oct. 2 (T) Relational Model. u Read Sections Assignment 1 due. Personal Letter of Introduction.
1 Functional Dependencies Why FD's Meaning of FD’s Keys and Superkeys Inferring FD’s Source: slides by Jeffrey Ullman.
Winter 2002Arthur Keller – CS 1803–1 Schedule Today: Jan. 10 (TH) u Relational Model, Functional Dependencies. u Read Sections Jan. 15 (T) u Normal.
Bad DB Design Duplicate of data Duplicate of data Updating Updating Deleting Deleting.
Fall 2001Arthur Keller – CS 1804–1 Schedule Today Oct. 4 (TH) Functional Dependencies and Normalization. u Read Sections Project Part 1 due. Oct.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
Database Systems Normal Forms. Decomposition Suppose we have a relation R[U] with a schema U={A 1,…,A n } – A decomposition of U is a set of schemas.
Decompositions uDo we need to decompose a relation? wSeveral normal forms for relations. If schema in these normal forms certain problems don’t.
Database Management Systems Chapter 3 The Relational Data Model (III) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Databases 1 Seventh lecture. Topics of the lecture Extended relational algebra Normalization Normal forms 2.
Normalization Goal = BCNF = Boyce-Codd Normal Form = all FD’s follow from the fact “key  everything.” Formally, R is in BCNF if for every nontrivial FD.
Databases 2 Storage optimization: functional dependencies, normal forms, data ware houses.
Normal Forms1. 2 The Problems of Redundancy Redundancy is at the root of several problems associated with relational schemas: Wastes storage Causes problems.
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.
Functional Dependencies. FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides.
1 IT 244 Database Management System Topic 7 The Relational Data Model Functional Dependencies Ref : -A First Course in Database System (Jeffrey D Ullman,
IST 210 Normalization 2 Todd Bacastow IST 210. Normalization Methods Inspection Closure Functional dependencies are key.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
1 Functional Dependencies. 2 Motivation v E/R  Relational translation problems : –Often discover more “detailed” constraints after translation (upcoming.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
Santa Clara UniversityHolliday – COEN 1783–1 Today’s Topic Today: u Relational Model, Functional Dependencies. u Read Sections Next time u Normal.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Functional Dependencies.
1 Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms.
CS542 1 Schema Refinement Chapter 19 (part 1) Functional Dependencies.
Functional Dependencies Zaki Malik September 25, 2008.
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
Functional Dependencies. Babies Exercise 2.2.5: At a birth, there is one baby (twins would be represented by two births), one mother, any number of nurses,
© 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.
1 CS 430 Database Theory Winter 2005 Lecture 8: Functional Dependencies Second, Third, and Boyce-Codd Normal Forms.
Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms: BCNF, Third Normal Form Introduction to Multivalued Dependencies.
1 Lecture 8 Design Theory for Relational Databases (part 2) Slides from
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
4NF & MULTIVALUED DEPENDENCY By Kristina Miguel. Review  Superkey – a set of attributes which will uniquely identify each tuple in a relation  Candidate.
1 Database Design: DBS CB, 2 nd Edition Physical RDBMS Model: Schema Design and Normalization Ch. 3.
Formal definition of a key A key is a set of attributes A 1,..., A n such that for any other attribute B: A 1,..., A n  B A minimal key is a set of attributes.
Design Theory for Relational Databases
Cushing, Keller, UlmanJudy Cushing
CPSC-310 Database Systems
Schema Refinement & Normalization Theory
CPSC-310 Database Systems
Multivalued Dependencies & Fourth Normal Form (4NF)
Functional Dependencies
Functional Dependencies
Multivalued Dependencies
Presentation transcript:

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 of X, then they must also agree on the attribute A. ▫Say “X -> A holds in R.” ▫Notice convention: …,X, Y, Z represent sets of attributes; A, B, C,… represent single attributes. ▫Convention: no set formers in sets of attributes, just ABC, rather than {A,B,C }.

3 Example Drinkers(name, addr, beersLiked, manf, favBeer). Reasonable FD’s to assert: 1.name -> addr (the name determine the address) 2.name -> favBeer (the name determine the favourite beer) 3.beersLiked -> manf (every beer has only one manufacturer)

Example 4 nameaddrBeersLikedmanfFavBeer JanewayVoyagerBudA.B.WickedAle JanewayVoyagerWickedAlePete’sWickedAle SpockEnterpriseBudA.B.Bud name -> addr name -> FavBeerBeersLiked -> manf

5 FD’s With Multiple Attributes No need for FD’s with more than one attribute on right. ▫But sometimes convenient to combine FD’s as a shorthand. ▫Example: name -> addr and name -> favBeer become name -> addr favBeer More than one attribute on left may be essential. ▫Example: bar beer -> price

6 Keys of Relations K is a key for relation R if: 1.Set K functionally determines all attributes of R 2.For no proper subset of K is (1) true. wIf K satisfies (1), but perhaps not (2), then K is a superkey. wConsequence: there are no two tuples having the same value in every attribute of the key. wNote E/R keys have no requirement for minimality, as in (2) for relational keys.

7 Example Consider relation Drinkers(name, addr, beersLiked, manf, favBeer). {name, beersLiked} is a superkey because together these attributes determine all the other attributes. ▫name -> addr favBeer ▫beersLiked -> manf

Example 8 nameaddrBeersLikedmanfFavBeer JanewayVoyagerBudA.B.WickedAle JanewayVoyagerWickedAlePete’sWickedAle SpockEnterpriseBudA.B.Bud Every pair is different => rest of the attributes are determined

9 Example, Cont. {name, beersLiked} is a key because neither {name} nor {beersLiked} is a superkey. ▫name doesn’t -> manf; beersLiked doesn’t -> addr. In this example, there are no other keys, but lots of superkeys. ▫Any superset of {name, beersLiked}.

Example 10 nameaddrBeersLikedmanfFavBeer JanewayVoyagerBudA.B.WickedAle JanewayVoyagerWickedAlePete’sWickedAle SpockEnterpriseBudA.B.Bud name doesn’t -> manf BeersLiked doesn’t -> addr

11 E/R and Relational Keys Keys in E/R are properties of entities Keys in relations are properties of tuples. Usually, one tuple corresponds to one entity, so the ideas are the same. But --- in poor relational designs, one entity can become several tuples, so E/R keys and Relational keys are different.

Example 12 nameaddrBeersLikedmanfFavBeer JanewayVoyagerBudA.B.WickedAle JanewayVoyagerWickedAlePete’sWickedAle SpockEnterpriseBudA.B.Bud nameaddr JanewayVoyager SpockEnterprise beermanf BudA.B. WickedAlePete’s BeersDrinkers name, Beersliked relational key In E/R name is a key for Drinkers, and beersLiked is a key for Beers

13 Where Do Keys Come From? 1.We could simply assert a key K. Then the only FD’s are K -> A for all atributes A, and K turns out to be the only key obtainable from the FD’s. 2.We could assert FD’s and deduce the keys by systematic exploration. uE/R gives us FD’s from entity-set keys and many-one relationships.

Armstrong’s axioms Let X,Y,Z  R (i.e. X,Y,Z are attribute sets of R) Armstrong’s axioms: Reflexivity: if Y  X then X -> Y Augmentation: if X -> Y then for every Z: XZ -> YZ Transitivity: if X -> Y and Y -> Z then X -> Z 14

15 FD’s From “Physics” While most FD’s come from E/R keyness and many-one relationships, some are really physical laws. Example: “no two courses can meet in the same room at the same time” tells us: hour room -> course.

16 Inferring FD’s: Motivation In order to design relation schemas well, we often need to tell what FD’s hold in a relation. We are given FD’s X 1 -> A 1, X 2 -> A 2,…, X n -> A n, and we want to know whether an FD Y -> B must hold in any relation that satisfies the given FD’s. ▫Example: If A -> B and B -> C hold, surely A -> C holds, even if we don’t say so.

17 Inference Test To test if Y -> B, start assuming two tuples agree in all attributes of Y. Use the given FD’s to infer that these tuples must also agree in certain other attributes. If B is eventually found to be one of these attributes, then Y -> B is true; otherwise, the two tuples, with any forced equalities form a two- tuple relation that proves Y -> B does not follow from the given FD’s.

18 Closure Test An easier way to test is to compute the closure of Y, denoted Y +. Basis: Y + = Y. Induction: Look for an FD’s left side X that is a subset of the current Y +. If the FD is X -> A, add A to Y +.

19 Y+Y+ new Y + XA

20 Finding All Implied FD’s Motivation: “normalization,” the process where we break a relation schema into two or more schemas. Example: ABCD with FD’s AB ->C, C ->D, and D ->A. ▫Decompose into ABC, AD. What FD’s hold in ABC ? ▫Not only AB ->C, but also C ->A !

21 Basic Idea To know what FD’s hold in a projection, we start with given FD’s and find all FD’s that follow from given ones. Then, restrict to those FD’s that involve only attributes of the projected schema.

22 Simple, Exponential Algorithm 1.For each set of attributes X, compute X +. 2.Add X ->A for all A in X + - X. 3.However, drop XY ->A whenever we discover X ->A. uBecause XY ->A follows from X ->A. 4.Finally, use only FD’s involving projected attributes.

23 A Few Tricks Never need to compute the closure of the empty set or of the set of all attributes: ▫ ∅ + = ∅ ▫R + =R If we find X + = all attributes, don’t bother computing the closure of any supersets of X: ▫X + = R and X  Y => Y + = R

24 Example ABC with FD’s A ->B and B ->C. Project onto AC. ▫A + =ABC ; yields A ->B, A ->C.  We do not need to compute AB + or AC +. ▫B + =BC ; yields B ->C. ▫C + =C ; yields nothing. ▫BC + =BC ; yields nothing.

25 Example, Continued Resulting FD’s: A ->B, A ->C, and B ->C. Projection onto AC : A ->C. ▫Only FD that involves a subset of {A,C }.

26 A Geometric View of FD’s Imagine the set of all instances of a particular relation. That is, all finite sets of tuples that have the proper number of components. Each instance is a point in this space.

27 Example: R(A,B) {(1,2), (3,4)} {} {(1,2), (3,4), (1,3)} {(5,1)}

28 An FD is a Subset of Instances For each FD X -> A there is a subset of all instances that satisfy the FD. We can represent an FD by a region in the space. Trivial FD : an FD that is represented by the entire space. ▫Example: A -> A.

29 Example: A -> B for R(A,B) {(1,2), (3,4)} {} {(1,2), (3,4), (1,3)} {(5,1)} A -> B

30 Representing Sets of FD’s If each FD is a set of relation instances, then a collection of FD’s corresponds to the intersection of those sets. ▫Intersection = all instances that satisfy all of the FD’s.

31 Example A->B B->C CD->A Instances satisfying A->B, B->C, and CD->A

32 Implication of FD’s If an FD Y -> B follows from FD’s X 1 -> A 1,…, X n -> A n, then the region in the space of instances for Y -> B must include the intersection of the regions for the FD’s X i -> A i. ▫That is, every instance satisfying all the FD’s X i -> A i surely satisfies Y -> B. ▫But an instance could satisfy Y -> B, yet not be in this intersection.

33 Example A->B B->C A->C