+ All Categories
Home > Documents > FunctionalDependencies-1

FunctionalDependencies-1

Date post: 18-Dec-2015
Category:
Upload: nicencool78
View: 5 times
Download: 0 times
Share this document with a friend
Description:
Functional Dependencies Database Systems
Popular Tags:
22
miniworld Requirements & collection analysis Conceptual Design Data Model Mapping Database Requirements Conceptual Schema ( ER diagram ) DBMS independent DBMS specific Conceptual Schema ( Relations ) refinemen t primary key constraint foreign key constraint
Transcript

PowerPoint Presentation

miniworldRequirements & collection analysisConceptual DesignData Model MappingDatabase RequirementsConceptual Schema ( ER diagram )DBMS independentDBMS specificConceptual Schema ( Relations )refinement primary key constraint foreign key constraint1Schema Refinement and Normal FormsConceptual database design gives us a set of relation schemas and integrity constraintsGiven a design, how do we know it is good or not? A design can be evaluated from various perspectives, our focus is on data redundancyConceptual designSchemasICsThe Evils of RedundancyRedundancy is at the root of several problems associated with relational schemas:redundant storageInsertion/update/deletion anomalies

3ExampleSchemaHourly_Emps (ssn, name, lot, rating, hrly_wages, hrs_worked)Constraints: ssn is the primary key If two tuples have the same value on rating, they have the same value on hrly_wages

4Solution: Decomposition

If we break Hourly_Emps into Hourly_Emps2 and Wages, then we dont have updates, insertion, deletion anomalies.Hourly_Emps2Wages

5Should a relation be decomposed?If a relation is not in certain form, some problems (e.g., redundancy) will arise, are these problems tolerable? Aforementioned anomaliesPotential performance loss: Queries over the original relation may required to join the decomposed relationsHow to decompose a relation? Two properties must be preserved:lossless-join: the data in the original relation can be recovered from the smaller relationsdependency-preservation: all constraints on the original relation must still hold by enforcing some constraints on each of the small relationsDecomposition Concerns6Functional Dependencies (FDs)In a relation schema R, a set of attributes X functionally determines a set of attributes Y if and only if whenever two tuples of R agree on X value, they must necessarily agree on the Y value.

XY

XY: Y is functionally dependent on X, or X uniquely determines Y orX functionally determines Y, or X determines Y

where r(R) is an instance of R,

7XYZX1Y2Z1X1Y2Z2X2Y2Z3Does this data set violate X->Y?Does this data set violate Z->Y?XYZX1Y1Z1X1Y1Z2X1Y2Z1Does this data set violate X->Y?Does this data set violate XY->Z?Does this data set violate Z->X?8No, No, Yes, Yes, NoAn FD is a statement about all allowable relations.Must be identified based on semantics of application.Given some allowable instance r1 of R, we can check if it violates some FD f, but we cannot tell if f holds over R!A primary key constraint is a special case of an FDThe attributes in the key play the role of X, and the set of all attributes in the relation plays the role of Y

9K is a candidate key for R means that KR.However, KR does not require K to be minimal!

Example 1Hourly_Emps (ssn, name, lot, rating, hrly_wages, hrs_worked)

Notation: We will denote this relation schema by listing the attributes: SNLRWHThis is really the set of attributes {S,N,L,R,W,H}.Sometimes, we will refer to all attributes of a relation by using the relation name. (e.g., Hourly_Emps for SNLRWH)

Some FDs on Hourly_Emps:ssn is the key: SSNLRWH (or {S}{S,N,L,R,W,H})rating determines hrly_wages : RW10dnamebudgetdidsincelotnamessnWorks_forEmployeesDepartmentsFD: did->lot

Works_for(ssn,name,did,since)Department (did,dname,budget,lot);Additional Constraints: Employees are assigned parking lots based on their department. All employees in the same department is given the same lot.Example 2A set of dependencies may imply some additional dependencies.Dependency ReasoningEMP_DEPT(ENAME,SSN,BDATE,ADDRESS,DNUMBER,DNAME,DMGRSSN)F={SSN->{ENAME,BDATE,ADDRESS,DNUMBER},DNUMBER->{DNAME,DMGRSSN} }F infers the following additional functional dependencies:

F{SSN}->{DNAME,DMGRSSN}F{SSN}->{SSN}F{DNUMBER}->{DNAME}A set of dependencies may imply some additional dependencies.Dependency ReasoningSome important questions

Given a set of attributes X, what attributes can be determined by XGiven an FD set, what other dependencies are impliedGiven an FD set F, what is the minimum set of dependencies that is equivalent to F13Armstrongs Axioms where X, Y, Z are sets of attributes:Reflexivity: If X Y, then XY. Augmentation: If XY, then XZ YZ for any Z.Transitivity: If X Y and YZ, then XZ.

Armstrongs Axioms14PROOFSReflexive rule: If X Y, then XY.

Let {t1,t2}

r(R) such that t1[X]=t2[X]Since Y X, t1[X]=t2[X] t1[Y]=t2[Y]

XY.

15PROOFS (Contd)Transitive rule: If XY and YZ, then XZ.Let XY and (1) YZ (2)

such that t1[X]=t2[X], (3)we have:(1) t1[Y]=t2[Y] (4)(2)&(4) t1[Z]=t2[Z] (5)(3)&(5) XZ16Augmentation rule: If XY, then XZYZ.Assume that the Augmentation rule is not true.

PROOFS (Contd)t1[X] = t2[X] (1)t1[Y] = t2[Y] (2)t1[XZ] = t2[XZ] (3)t1[YZ] != t2[YZ] (4)(1)&(3)

t1[Z]=t2[Z] (5)(2)&(5)

t1[YZ]=t2[YZ] (6)(6) Contradicts (4)17Union: If X Y and X Z, then X YZ.Decomposition: If XYZ, then XY and XZ.Pseudotransitive Rule: If XY and WYZ then WXZ.Additional Inference Rules for Functional Dependencies18PROOFS (Contd)Union rule: If XY and XZ, then XYZ.Given XY and (1) XZ. (2)

Applying Augmentation rule on (1), we have XXXY XXY. (3)

Applying Augmentation rule on (2), we have XYZY XYYZ . (4)

Applying Transitive rule on (3) and (4), we have XYZ.

19PROOFS (Contd)Decomposition rule: If XYZ then XY and XZ.Given XYZ. (1)Since Y YZ, reflexive rule gives YZY. (2)

Applying Transitive rule on (1) and (2), we have XY.XZ is derived in a similar way.

20PROOFS (Contd)Pseudotransitive rule: If XY and WYZ, then WXZ.Given XY (1)and WYZ. (2)

Applying Augmentation rule on (1), we have WXWY. (3)

Applying Transitive rule on (3)&(2), we have WXZ.21ExerciseProve or disprove the following inference rules{WY,XZ} |= {WXY}{XY,XW,WYZ} |= {XZ}{XY} |= {XYZ}{XY, Z Y} |= {XZY}Prove using inference rulesDisprove by showing a counter example22SSNNameLotRddWH

123-22-3666Attishoo4881040

231-31-5368Smiley2281030

131-24-3650Smethurst355730

434-26-3751Guldu355732

612-67-4134Madayan3581040

SNLRH

123-22-3666Attishoo48840

231-31-5368Smiley22830

131-24-3650Smethurst35530

434-26-3751Guldu35532

612-67-4134Madayan35840

RW81057


Recommended