Docsity

Understanding Functional Dependencies and Lossless Decompositions in Database Design - Pro, Study notes of Principles of Database Management

Partial preview of the text

Download Understanding Functional Dependencies and Lossless Decompositions in Database Design - Pro and more Study notes Principles of Database Management in PDF only on Docsity!

CMSC 424 โ€“ Database design

Lecture 10

Normalization

Mihai Pop

Midterm...

โ€ข Graded A & B โ€“ disappointing

โ€ข Outline of what I expected for A & B

Combine Schemas?

โ—

Suppose we combine borrower and loan to get

bor_loan = ( customer_id , loan_number , amount )

โ€ข Result is possible repetition of information (L-100 in

example below)

A Lossy Decomposition

FDs continued

  • trivial dependencies:
  • closure
    • need all FDs
    • (^) some logically implied by others e.g. if A โ†’ B & B โ†’ C then A โ†’ C is implied
  • given F = set of FDs, find F+ (the closure) of all logically implied by F
  • Why?
  • See: http://www.schneier.com/blog/archives/2007/12/anonymity_and_t_2.html
  • Given a userโ€™s public IMDb ratings, which the user posted voluntarily to selectively reveal some of his (or her; but weโ€™ll use the male pronoun without loss of generality) movie likes and dislikes, we discover all the ratings that he entered privately into the Netflix system, presumably expecting that they will remain private.

๎‚ท ๎‚Œ ๎‚ธ if ๎‚ธโІ๎‚ท

FD formalism

Amstrongโ€™s axioms

  • reflexivity:
  • (^) augmentation:
  • (^) transitivity: More rules (can be inferred from Amstrong's axioms)
  • (^) union rule:
  • (^) decomposition rule:
  • (^) pseudotransitivity rule:

if ๎‚ธโІ๎‚ท then ๎‚ท ๎‚Œ ๎‚ธ (trivial FD)

if ๎‚ท ๎‚Œ ๎‚ธ then ๎‚น ๎‚ท ๎‚Œ ๎‚น ๎‚ธ

if ๎‚ท ๎‚Œ ๎‚ธโˆง๎‚ธ ๎‚Œ ๎‚น then ๎‚ท ๎‚Œ ๎‚น

if ๎‚ท ๎‚Œ ๎‚ธโˆง๎‚ท ๎‚Œ ๎‚น then ๎‚ท ๎‚Œ ๎‚ธ ๎‚น

if ๎‚ท ๎‚Œ ๎‚ธ ๎‚น then ๎‚ท ๎‚Œ ๎‚ธ and ๎‚ท ๎‚Œ ๎‚น

if ๎‚ท ๎‚Œ ๎‚ธโˆง๎‚น ๎‚ธ ๎‚Œ ๎‚บ then ๎‚ท ๎‚น ๎‚Œ๎‚บ

Closure of Attribute Sets

  • (^) useful to find if a set of attributes is a superkey
  • (^) the closure ฮฑ+ of a set of attributes ฮฑ under F is the set of all attributes that are functionally determined by ฮฑ
  • (^) there is an algorithm that computes the closure Example: Note that since G is not on any right hand side, no subset of the attributes can be a superkey unless it contains G for there is no FD to generate it. R(A,B,C,G,H,I) F={ A โ†’ B, A โ†’ C, CG โ†’ H, CG โ†’ I, B โ†’ H } Algorithm to Compute (AG)+ start with result=(AG) A โ†’ B expands result=(AGB) A โ†’ C expands result=(AGBC) CG โ†’ H โ€œ-โ€ result=(AGBCH) CG โ†’ I โ€œ-โ€ result=(AGBCHI) B โ†’ H no more expansion

Uses of Attribute Closure

There are several uses of the attribute closure algorithm:

  • Testing for superkey:
    • (^) To test if ฮฑ is a superkey, we compute ฮฑ+,^ and check if ฮฑ+ contains all attributes of R.
  • (^) Testing functional dependencies
    • (^) To check if a functional dependency ฮฑ โ†’ ฮฒ holds (or, in other words, is in F+ ), just check if ฮฒ โІ ฮฑ+.
    • (^) That is, we compute ฮฑ+ by using attribute closure, and then check if it contains ฮฒ.
    • (^) Is a simple and cheap test, and very useful

Dependency Preservation

In a decomposition

  • (^) dependencies are preserved if
    • (^) we do not need to join in order to enforce FDs
    • (^) all FDs remain intra-relational and do not become inter-relational constraints
  • (^) to check if a decomposition is dependency preserving
    • (^) we need to examine all FDs in F+
  • (^) there is an algorithm for testing dependency preservation
    • (^) requires the computation of F+

The Normal Forms

  • 1NF: every attribute has an atomic value (not a set value)
  • 2NF: we will not be concerned in this course
  • (^) 3NF: if for each FD Xโ†’Y either
    • it is trivial or
    • X is a superkey
    • Y-X is a proper subset of a candidate key
  • (^) BCNF: if for each FD Xโ†’Y either
    • it is trivial or
    • X is a superkey
  • 4NF,โ€ฆ: we are not concerned in this course. 1NF 2NF 3NF BCNF 4NF,..