115
Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Functional Dependencies T. M. Murali October 18, 25, 2010 T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Functional Dependencies - Undergraduate Courses | Computer Science

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Functional Dependencies

T. M. Murali

October 18, 25, 2010

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 2: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Midterm Review

I The database server set up is driving me NUTS!

I The class is slow (no 3NF yet). Why are we doing design beforelearning normalisation? It seems odd to teach relational models afterSQL.

I Homework grading is strict/uneven.

I Increase amount of examples/hands-on work.

I Make the lectures more interactive.

I Office hours change a lot.

I Wish the project was free form.

I It would be nice to have a table of RA symbols and E/R diagramshapes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 3: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Midterm Review

I The database server set up is driving me NUTS!

I The class is slow (no 3NF yet). Why are we doing design beforelearning normalisation? It seems odd to teach relational models afterSQL.

I Homework grading is strict/uneven.

I Increase amount of examples/hands-on work.

I Make the lectures more interactive.

I Office hours change a lot.

I Wish the project was free form.

I It would be nice to have a table of RA symbols and E/R diagramshapes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 4: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Midterm Review

I The database server set up is driving me NUTS!

I The class is slow (no 3NF yet). Why are we doing design beforelearning normalisation? It seems odd to teach relational models afterSQL.

I Homework grading is strict/uneven.

I Increase amount of examples/hands-on work.

I Make the lectures more interactive.

I Office hours change a lot.

I Wish the project was free form.

I It would be nice to have a table of RA symbols and E/R diagramshapes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 5: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Midterm Review

I The database server set up is driving me NUTS!

I The class is slow (no 3NF yet). Why are we doing design beforelearning normalisation? It seems odd to teach relational models afterSQL.

I Homework grading is strict/uneven.

I Increase amount of examples/hands-on work.

I Make the lectures more interactive.

I Office hours change a lot.

I Wish the project was free form.

I It would be nice to have a table of RA symbols and E/R diagramshapes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 6: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Midterm Review

I The database server set up is driving me NUTS!

I The class is slow (no 3NF yet). Why are we doing design beforelearning normalisation? It seems odd to teach relational models afterSQL.

I Homework grading is strict/uneven.

I Increase amount of examples/hands-on work.

I Make the lectures more interactive.

I Office hours change a lot.

I Wish the project was free form.

I It would be nice to have a table of RA symbols and E/R diagramshapes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 7: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Midterm Review

I The database server set up is driving me NUTS!

I The class is slow (no 3NF yet). Why are we doing design beforelearning normalisation? It seems odd to teach relational models afterSQL.

I Homework grading is strict/uneven.

I Increase amount of examples/hands-on work.

I Make the lectures more interactive.

I Office hours change a lot.

I Wish the project was free form.

I It would be nice to have a table of RA symbols and E/R diagramshapes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 8: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Midterm Review

I The database server set up is driving me NUTS!

I The class is slow (no 3NF yet). Why are we doing design beforelearning normalisation? It seems odd to teach relational models afterSQL.

I Homework grading is strict/uneven.

I Increase amount of examples/hands-on work.

I Make the lectures more interactive.

I Office hours change a lot.

I Wish the project was free form.

I It would be nice to have a table of RA symbols and E/R diagramshapes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 9: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Midterm Review

I The database server set up is driving me NUTS!

I The class is slow (no 3NF yet). Why are we doing design beforelearning normalisation? It seems odd to teach relational models afterSQL.

I Homework grading is strict/uneven.

I Increase amount of examples/hands-on work.

I Make the lectures more interactive.

I Office hours change a lot.

I Wish the project was free form.

I It would be nice to have a table of RA symbols and E/R diagramshapes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 10: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Midterm Review

I The database server set up is driving me NUTS!

I The class is slow (no 3NF yet). Why are we doing design beforelearning normalisation? It seems odd to teach relational models afterSQL.

I Homework grading is strict/uneven.

I Increase amount of examples/hands-on work.

I Make the lectures more interactive.

I Office hours change a lot.

I Wish the project was free form.

I It would be nice to have a table of RA symbols and E/R diagramshapes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 11: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example

IdId

Students

NameName

AdvisorsAdvises

Favourite

I Convert to relations:

Students(Id, Name)

Advisors(Id, Name)

Advises(StudentId, AdvisorId)

Favourite(StudentId, AdvisorId)

I Suppose we perversely decide to convert Students, Advises, andFavourite into one relation.

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 12: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example

IdId

Students

NameName

AdvisorsAdvises

Favourite

I Convert to relations:

Students(Id, Name)

Advisors(Id, Name)

Advises(StudentId, AdvisorId)

Favourite(StudentId, AdvisorId)

I Suppose we perversely decide to convert Students, Advises, andFavourite into one relation.

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 13: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example

IdId

Students

NameName

AdvisorsAdvises

Favourite

I Convert to relations:

Students(Id, Name)

Advisors(Id, Name)

Advises(StudentId, AdvisorId)

Favourite(StudentId, AdvisorId)

I Suppose we perversely decide to convert Students, Advises, andFavourite into one relation.

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 14: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of a Bad Relation

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

I If you know a student’s Id, can you determine the values of any otherattributes?

Name and FavouriteAdvisorId.

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→ AdvisorName

I Can we say Id→ AdvisorId? NO! Id is not a key for the Students

relation.

I What is the key for the Students? {Id, AdvisorId}.I Why is this relation “bad?” Parts of the key determine other

attributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 15: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of a Bad Relation

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

I If you know a student’s Id, can you determine the values of any otherattributes? Name and FavouriteAdvisorId.

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→ AdvisorName

I Can we say Id→ AdvisorId? NO! Id is not a key for the Students

relation.

I What is the key for the Students? {Id, AdvisorId}.I Why is this relation “bad?” Parts of the key determine other

attributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 16: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of a Bad Relation

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

I If you know a student’s Id, can you determine the values of any otherattributes? Name and FavouriteAdvisorId.

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→ AdvisorName

I Can we say Id→ AdvisorId? NO! Id is not a key for the Students

relation.

I What is the key for the Students? {Id, AdvisorId}.I Why is this relation “bad?” Parts of the key determine other

attributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 17: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of a Bad Relation

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

I If you know a student’s Id, can you determine the values of any otherattributes? Name and FavouriteAdvisorId.

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→

AdvisorName

I Can we say Id→ AdvisorId? NO! Id is not a key for the Students

relation.

I What is the key for the Students? {Id, AdvisorId}.I Why is this relation “bad?” Parts of the key determine other

attributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 18: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of a Bad Relation

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

I If you know a student’s Id, can you determine the values of any otherattributes? Name and FavouriteAdvisorId.

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→ AdvisorName

I Can we say Id→ AdvisorId? NO! Id is not a key for the Students

relation.

I What is the key for the Students? {Id, AdvisorId}.I Why is this relation “bad?” Parts of the key determine other

attributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 19: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of a Bad Relation

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

I If you know a student’s Id, can you determine the values of any otherattributes? Name and FavouriteAdvisorId.

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→ AdvisorName

I Can we say Id→ AdvisorId?

NO! Id is not a key for the Students

relation.

I What is the key for the Students? {Id, AdvisorId}.I Why is this relation “bad?” Parts of the key determine other

attributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 20: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of a Bad Relation

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

I If you know a student’s Id, can you determine the values of any otherattributes? Name and FavouriteAdvisorId.

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→ AdvisorName

I Can we say Id→ AdvisorId? NO! Id is not a key for the Students

relation.

I What is the key for the Students? {Id, AdvisorId}.I Why is this relation “bad?” Parts of the key determine other

attributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 21: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of a Bad Relation

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

I If you know a student’s Id, can you determine the values of any otherattributes? Name and FavouriteAdvisorId.

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→ AdvisorName

I Can we say Id→ AdvisorId? NO! Id is not a key for the Students

relation.

I What is the key for the Students?

{Id, AdvisorId}.I Why is this relation “bad?” Parts of the key determine other

attributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 22: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of a Bad Relation

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

I If you know a student’s Id, can you determine the values of any otherattributes? Name and FavouriteAdvisorId.

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→ AdvisorName

I Can we say Id→ AdvisorId? NO! Id is not a key for the Students

relation.

I What is the key for the Students? {Id, AdvisorId}.

I Why is this relation “bad?” Parts of the key determine otherattributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 23: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of a Bad Relation

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

I If you know a student’s Id, can you determine the values of any otherattributes? Name and FavouriteAdvisorId.

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→ AdvisorName

I Can we say Id→ AdvisorId? NO! Id is not a key for the Students

relation.

I What is the key for the Students? {Id, AdvisorId}.I Why is this relation “bad?”

Parts of the key determine otherattributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 24: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of a Bad Relation

Students(Id, Name, AdvisorId, AdvisorName,

FavouriteAdvisorId)

I If you know a student’s Id, can you determine the values of any otherattributes? Name and FavouriteAdvisorId.

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→ AdvisorName

I Can we say Id→ AdvisorId? NO! Id is not a key for the Students

relation.

I What is the key for the Students? {Id, AdvisorId}.I Why is this relation “bad?” Parts of the key determine other

attributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 25: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Motivation for Functional Dependencies

I Reason about constraints on attributes in a relation.

I Procedurally determine the keys of a relation.

I Detect when a relation has redundant information.

I Improve database designs systematically using normalisation.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 26: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Definition of Functional Dependency

I If t is a tuple in a relation R and A is an attribute of R, then tA is thevalue of attribute A in tuple t.

I The FD AdvisorId→ AdvisorName holds in R if in every instanceof R, for every pair of tuples t and u

if tAdvisorId = uAdvisorId, then tAdvisorName = uAdvisorName.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 27: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Definition of Functional Dependency

I If t is a tuple in a relation R and A is an attribute of R, then tA is thevalue of attribute A in tuple t.

I The FD AdvisorId→ AdvisorName holds in R if in every instanceof R, for every pair of tuples t and u

if tAdvisorId = uAdvisorId, then tAdvisorName = uAdvisorName.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 28: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Definition of Functional Dependency

I If t is a tuple in a relation R and A is an attribute of R, then tA is thevalue of attribute A in tuple t.

I The FD AdvisorId→ AdvisorName holds in R if in every instanceof R, for every pair of tuples t and u

if tAdvisorId = uAdvisorId, then tAdvisorName = uAdvisorName.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 29: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Definition of Functional Dependencies

A functional dependency (FD) on a relation R is a statement

I If two tuples in R agree on attributes A1,A2, . . .An then they agreeon attribute B.

I Notation: A1A2 . . .An → B

I FD says that for every pair of tuples t and u in any instance of R, iftA1 = uA1 and tA2 = uA2 and . . . tAn = uAn , then tB = uB .

I The set of attributes A1,A2, . . .An functionally determine B.

I An FD is a constraint on a single relation schema. It must hold onevery instance of the relation.

I You cannot deduce an FD from a relation instance.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 30: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Definition of Functional Dependencies

A functional dependency (FD) on a relation R is a statement

I If two tuples in R agree on attributes A1,A2, . . .An then they agreeon attribute B.

I Notation: A1A2 . . .An → B

I FD says that for every pair of tuples t and u in any instance of R,

iftA1 = uA1 and tA2 = uA2 and . . . tAn = uAn , then tB = uB .

I The set of attributes A1,A2, . . .An functionally determine B.

I An FD is a constraint on a single relation schema. It must hold onevery instance of the relation.

I You cannot deduce an FD from a relation instance.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 31: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Definition of Functional Dependencies

A functional dependency (FD) on a relation R is a statement

I If two tuples in R agree on attributes A1,A2, . . .An then they agreeon attribute B.

I Notation: A1A2 . . .An → B

I FD says that for every pair of tuples t and u in any instance of R, iftA1 = uA1 and tA2 = uA2 and . . . tAn = uAn , then tB = uB .

I The set of attributes A1,A2, . . .An functionally determine B.

I An FD is a constraint on a single relation schema. It must hold onevery instance of the relation.

I You cannot deduce an FD from a relation instance.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 32: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Examples of FDs

I What FDs can we assert for the relation

Courses(Number, DeptName, CourseName, Classroom, Enrollment)

Number DeptName CourseName Classroom Enrollment

4604 CS Databases TORG 1020 454604 Dance Tree Dancing Drillfield 454604 English The Basis of Data Williams 44 452604 CS Data Structures MCB 114 1002604 Physics Dark Matter Williams 44 100

Number DeptName→ CourseName

Number DeptName→ Classroom

Number DeptName→ Enrollment

Number DeptName→ CourseName Classroom Enrollment

I Is Number→ Enrollment an FD?

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 33: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Examples of FDs

I What FDs can we assert for the relation

Courses(Number, DeptName, CourseName, Classroom, Enrollment)

Number DeptName CourseName Classroom Enrollment

4604 CS Databases TORG 1020 454604 Dance Tree Dancing Drillfield 454604 English The Basis of Data Williams 44 452604 CS Data Structures MCB 114 1002604 Physics Dark Matter Williams 44 100

Number DeptName→ CourseName

Number DeptName→ Classroom

Number DeptName→ Enrollment

Number DeptName→ CourseName Classroom Enrollment

I Is Number→ Enrollment an FD?

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 34: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Examples of FDs

I What FDs can we assert for the relation

Courses(Number, DeptName, CourseName, Classroom, Enrollment)

Number DeptName CourseName Classroom Enrollment

4604 CS Databases TORG 1020 454604 Dance Tree Dancing Drillfield 454604 English The Basis of Data Williams 44 452604 CS Data Structures MCB 114 1002604 Physics Dark Matter Williams 44 100

Number DeptName→ CourseName

Number DeptName→ Classroom

Number DeptName→ Enrollment

Number DeptName→ CourseName Classroom Enrollment

I Is Number→ Enrollment an FD?

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 35: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Examples of FDs

I What FDs can we assert for the relation

Courses(Number, DeptName, CourseName, Classroom, Enrollment)

Number DeptName CourseName Classroom Enrollment

4604 CS Databases TORG 1020 454604 Dance Tree Dancing Drillfield 454604 English The Basis of Data Williams 44 452604 CS Data Structures MCB 114 1002604 Physics Dark Matter Williams 44 100

Number DeptName→ CourseName

Number DeptName→ Classroom

Number DeptName→ Enrollment

Number DeptName→ CourseName Classroom Enrollment

I Is Number→ Enrollment an FD?

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 36: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Where do FDs come from?

I “Keyness” of attributes.

I Domain and application constraints.

I Real world constraints, e.g., ProfessorID Time→ Classroom

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 37: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Where do FDs come from?

I “Keyness” of attributes.

I Domain and application constraints.

I Real world constraints, e.g., ProfessorID Time→ Classroom

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 38: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Definition of Keys

I FDs allow us to formally define keys.

I A set of attributes {A1,A2, . . .An} is a key for a relation R if

Uniqueness {A1,A2, . . .An} functionally determine all the otherattributes of R and

Minimality no proper subset of {A1,A2, . . .An} functionallydetermines all the other attributes of R.

I A superkey is a set of attributes that has the uniqueness property butis not necessarily minimal.

I If a relation has multiple keys, specify one to be the primary key.

I Convention: in a relational schema, underline the attributes of theprimary key.

I If a key has only one attribute A, we say that A rather than {A} is akey.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 39: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Definition of Keys

I FDs allow us to formally define keys.

I A set of attributes {A1,A2, . . .An} is a key for a relation R if

Uniqueness {A1,A2, . . .An} functionally determine all the otherattributes of R and

Minimality no proper subset of {A1,A2, . . .An} functionallydetermines all the other attributes of R.

I A superkey is a set of attributes that has the uniqueness property butis not necessarily minimal.

I If a relation has multiple keys, specify one to be the primary key.

I Convention: in a relational schema, underline the attributes of theprimary key.

I If a key has only one attribute A, we say that A rather than {A} is akey.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 40: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of Keys

I What is the key for

Courses(Number, DeptName, CourseName, Classroom,

Enrollment)?

I The key is {Number, DeptName}.I These attributes functionally determine every other attribute.I No proper subset of {Number, DeptName} has this property.

I What is the key for

Teach(, , ProfessorName, Classroom)?

I The key is {Number, DepartmentName}. Why?

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 41: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of Keys

I What is the key for

Courses(Number, DeptName, CourseName, Classroom,

Enrollment)?

I The key is {Number, DeptName}.I These attributes functionally determine every other attribute.I No proper subset of {Number, DeptName} has this property.

I What is the key for

Teach(, , ProfessorName, Classroom)?

I The key is {Number, DepartmentName}. Why?

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 42: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of Keys

I What is the key for

Courses(Number, DeptName, CourseName, Classroom,

Enrollment)?

I The key is {Number, DeptName}.I These attributes functionally determine every other attribute.I No proper subset of {Number, DeptName} has this property.

I What is the key for

Teach(Number, DepartmentName, ProfessorName,

Classroom)?

I The key is {Number, DepartmentName}. Why?

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 43: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of Keys

I What is the key for

Courses(Number, DeptName, CourseName, Classroom,

Enrollment)?

I The key is {Number, DeptName}.I These attributes functionally determine every other attribute.I No proper subset of {Number, DeptName} has this property.

I What is the key for

Teach(Number, DepartmentName, ProfessorName,

Classroom)?

I The key is {Number, DepartmentName}. Why?

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 44: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Keys in the Conversion from E/R to RelationalDesigns

I If the relation comes from an entity set, the key attributes of therelation are precisely the key attributes of the entity set.

I If the relation comes from a binary relationship R between entity setsE and F :

I R is many-many: key attributes of the relation are the key attributes ofE and of F .

I R is many-one from E to F : key attributes of the relation are the keyattributes of E .

I R is one-one: key attributes of the relation are the key attributes of Eor of F .

I If the relationship R is multiway, we need to reason about the FDsthat R satisfies.

I There is no simple rule.I If R has an arrow towards entity set E , at least one key for the relation

for R excludes the key for E .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 45: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Keys in the Conversion from E/R to RelationalDesigns

I If the relation comes from an entity set, the key attributes of therelation are precisely the key attributes of the entity set.

I If the relation comes from a binary relationship R between entity setsE and F :

I R is many-many: key attributes of the relation are the key attributes ofE and of F .

I R is many-one from E to F : key attributes of the relation are the keyattributes of E .

I R is one-one: key attributes of the relation are the key attributes of Eor of F .

I If the relationship R is multiway, we need to reason about the FDsthat R satisfies.

I There is no simple rule.I If R has an arrow towards entity set E , at least one key for the relation

for R excludes the key for E .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 46: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Keys in the Conversion from E/R to RelationalDesigns

I If the relation comes from an entity set, the key attributes of therelation are precisely the key attributes of the entity set.

I If the relation comes from a binary relationship R between entity setsE and F :

I R is many-many:

key attributes of the relation are the key attributes ofE and of F .

I R is many-one from E to F : key attributes of the relation are the keyattributes of E .

I R is one-one: key attributes of the relation are the key attributes of Eor of F .

I If the relationship R is multiway, we need to reason about the FDsthat R satisfies.

I There is no simple rule.I If R has an arrow towards entity set E , at least one key for the relation

for R excludes the key for E .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 47: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Keys in the Conversion from E/R to RelationalDesigns

I If the relation comes from an entity set, the key attributes of therelation are precisely the key attributes of the entity set.

I If the relation comes from a binary relationship R between entity setsE and F :

I R is many-many: key attributes of the relation are the key attributes ofE and of F .

I R is many-one from E to F : key attributes of the relation are the keyattributes of E .

I R is one-one: key attributes of the relation are the key attributes of Eor of F .

I If the relationship R is multiway, we need to reason about the FDsthat R satisfies.

I There is no simple rule.I If R has an arrow towards entity set E , at least one key for the relation

for R excludes the key for E .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 48: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Keys in the Conversion from E/R to RelationalDesigns

I If the relation comes from an entity set, the key attributes of therelation are precisely the key attributes of the entity set.

I If the relation comes from a binary relationship R between entity setsE and F :

I R is many-many: key attributes of the relation are the key attributes ofE and of F .

I R is many-one from E to F :

key attributes of the relation are the keyattributes of E .

I R is one-one: key attributes of the relation are the key attributes of Eor of F .

I If the relationship R is multiway, we need to reason about the FDsthat R satisfies.

I There is no simple rule.I If R has an arrow towards entity set E , at least one key for the relation

for R excludes the key for E .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 49: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Keys in the Conversion from E/R to RelationalDesigns

I If the relation comes from an entity set, the key attributes of therelation are precisely the key attributes of the entity set.

I If the relation comes from a binary relationship R between entity setsE and F :

I R is many-many: key attributes of the relation are the key attributes ofE and of F .

I R is many-one from E to F : key attributes of the relation are the keyattributes of E .

I R is one-one: key attributes of the relation are the key attributes of Eor of F .

I If the relationship R is multiway, we need to reason about the FDsthat R satisfies.

I There is no simple rule.I If R has an arrow towards entity set E , at least one key for the relation

for R excludes the key for E .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 50: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Keys in the Conversion from E/R to RelationalDesigns

I If the relation comes from an entity set, the key attributes of therelation are precisely the key attributes of the entity set.

I If the relation comes from a binary relationship R between entity setsE and F :

I R is many-many: key attributes of the relation are the key attributes ofE and of F .

I R is many-one from E to F : key attributes of the relation are the keyattributes of E .

I R is one-one:

key attributes of the relation are the key attributes of Eor of F .

I If the relationship R is multiway, we need to reason about the FDsthat R satisfies.

I There is no simple rule.I If R has an arrow towards entity set E , at least one key for the relation

for R excludes the key for E .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 51: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Keys in the Conversion from E/R to RelationalDesigns

I If the relation comes from an entity set, the key attributes of therelation are precisely the key attributes of the entity set.

I If the relation comes from a binary relationship R between entity setsE and F :

I R is many-many: key attributes of the relation are the key attributes ofE and of F .

I R is many-one from E to F : key attributes of the relation are the keyattributes of E .

I R is one-one: key attributes of the relation are the key attributes of Eor of F .

I If the relationship R is multiway, we need to reason about the FDsthat R satisfies.

I There is no simple rule.I If R has an arrow towards entity set E , at least one key for the relation

for R excludes the key for E .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 52: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Keys in the Conversion from E/R to RelationalDesigns

I If the relation comes from an entity set, the key attributes of therelation are precisely the key attributes of the entity set.

I If the relation comes from a binary relationship R between entity setsE and F :

I R is many-many: key attributes of the relation are the key attributes ofE and of F .

I R is many-one from E to F : key attributes of the relation are the keyattributes of E .

I R is one-one: key attributes of the relation are the key attributes of Eor of F .

I If the relationship R is multiway

, we need to reason about the FDsthat R satisfies.

I There is no simple rule.I If R has an arrow towards entity set E , at least one key for the relation

for R excludes the key for E .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 53: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Keys in the Conversion from E/R to RelationalDesigns

I If the relation comes from an entity set, the key attributes of therelation are precisely the key attributes of the entity set.

I If the relation comes from a binary relationship R between entity setsE and F :

I R is many-many: key attributes of the relation are the key attributes ofE and of F .

I R is many-one from E to F : key attributes of the relation are the keyattributes of E .

I R is one-one: key attributes of the relation are the key attributes of Eor of F .

I If the relationship R is multiway, we need to reason about the FDsthat R satisfies.

I There is no simple rule.I If R has an arrow towards entity set E , at least one key for the relation

for R excludes the key for E .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 54: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Rules for Manipulating FDs

I Learn how to reason about FDs.

I Define rules for deriving new FDs from a given set of FDs.

I Next class: use these rules to remove “anomalies” from relationaldesigns.

I Example: A relation R with attributes A, B, and C , satisfies the FDsA→ B and B → C . What other FDs does it satisfy? A→ C .

I What is the key for R? A, because A→ B and A→ C .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 55: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Rules for Manipulating FDs

I Learn how to reason about FDs.

I Define rules for deriving new FDs from a given set of FDs.

I Next class: use these rules to remove “anomalies” from relationaldesigns.

I Example: A relation R with attributes A, B, and C , satisfies the FDsA→ B and B → C . What other FDs does it satisfy?

A→ C .

I What is the key for R? A, because A→ B and A→ C .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 56: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Rules for Manipulating FDs

I Learn how to reason about FDs.

I Define rules for deriving new FDs from a given set of FDs.

I Next class: use these rules to remove “anomalies” from relationaldesigns.

I Example: A relation R with attributes A, B, and C , satisfies the FDsA→ B and B → C . What other FDs does it satisfy? A→ C .

I What is the key for R? A, because A→ B and A→ C .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 57: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Rules for Manipulating FDs

I Learn how to reason about FDs.

I Define rules for deriving new FDs from a given set of FDs.

I Next class: use these rules to remove “anomalies” from relationaldesigns.

I Example: A relation R with attributes A, B, and C , satisfies the FDsA→ B and B → C . What other FDs does it satisfy? A→ C .

I What is the key for R?

A, because A→ B and A→ C .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 58: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Rules for Manipulating FDs

I Learn how to reason about FDs.

I Define rules for deriving new FDs from a given set of FDs.

I Next class: use these rules to remove “anomalies” from relationaldesigns.

I Example: A relation R with attributes A, B, and C , satisfies the FDsA→ B and B → C . What other FDs does it satisfy? A→ C .

I What is the key for R? A, because A→ B and A→ C .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 59: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Equivalence of FDs

I An FD F follows from a set of FDs T if every relation instance thatsatisfies all the FDs in T also satisfies F .

I A→ C follows from T = {A→ B,B → C}.I Does T follow from S?

I Two sets of FDs S and T are equivalent if each FD in S follows fromT and each FD in T follows from S .

I S = {A→ B,B → C ,A→ C} and T = {A→ B,B → C} areequivalent.

I These notions are useful in deriving new FDs from a given set of FDs.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 60: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Equivalence of FDs

I An FD F follows from a set of FDs T if every relation instance thatsatisfies all the FDs in T also satisfies F .

I A→ C follows from T = {A→ B,B → C}.I Does T follow from S?

I Two sets of FDs S and T are equivalent if each FD in S follows fromT and each FD in T follows from S .

I S = {A→ B,B → C ,A→ C} and T = {A→ B,B → C} areequivalent.

I These notions are useful in deriving new FDs from a given set of FDs.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 61: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Equivalence of FDs

I An FD F follows from a set of FDs T if every relation instance thatsatisfies all the FDs in T also satisfies F .

I A→ C follows from T = {A→ B,B → C}.I Does T follow from S?

I Two sets of FDs S and T are equivalent if each FD in S follows fromT and each FD in T follows from S .

I S = {A→ B,B → C ,A→ C} and T = {A→ B,B → C} areequivalent.

I These notions are useful in deriving new FDs from a given set of FDs.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 62: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Splitting and Combining FDs

I The set of FDs

A1A2 . . .An → B1

A1A2 . . .An → B2

...

A1A2 . . .An → Bm

is equivalent to the FD

A1A2 . . .An → B1B2 . . .Bm.I This equivalence implies two rules.

I Splitting ruleI Combining ruleI These rules work because all the FDs in S and T have identical left

hand sides.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 63: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Splitting and Combining FDs

I Can we split and combine left hand sides of FDs?

I For the relation Courses, is the FD

Number DeptName→ CourseName

equivalent to the set of FDs

{Number→ CourseName, DeptName→ CourseName}? NO!

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 64: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Splitting and Combining FDs

I Can we split and combine left hand sides of FDs?

I For the relation Courses, is the FD

Number DeptName→ CourseName

equivalent to the set of FDs

{Number→ CourseName, DeptName→ CourseName}?

NO!

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 65: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Splitting and Combining FDs

I Can we split and combine left hand sides of FDs?

I For the relation Courses, is the FD

Number DeptName→ CourseName

equivalent to the set of FDs

{Number→ CourseName, DeptName→ CourseName}? NO!

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 66: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Triviality of FDs

An FD A1A2 . . .An → B1B2 . . .Bm is

I trivial if the B’s are a subset of the A’s, i.e.,{B1,B2, . . .Bn} ⊆ {A1,A2, . . .An}.

I non-trivial if at least one B is not among the A’s, i.e.,{B1,B2, . . .Bn} − {A1,A2, . . .An} 6= ∅.

I completely non-trivial if none of the B’s are among the A’s, i.e.,{B1,B2, . . .Bn} ∩ {A1,A2, . . .An} = ∅.

I What good are trivial and non-trivial dependencies?I Trivial dependencies are always true.I They help simplify reasoning about FDs.

I Trivial dependency rule: The FD A1A2 . . .An → B1B2 . . .Bm isequivalent to the FD A1A2 . . .An → C1C2 . . .Ck , where the C ’s arethose B’s that are not A’s, i.e.,{C1,C2, . . . ,Ck} = {B1,B2, . . . ,Bm} − {A1,A2, . . . ,An}.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 67: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Triviality of FDs

An FD A1A2 . . .An → B1B2 . . .Bm is

I trivial if the B’s are a subset of the A’s,

i.e.,{B1,B2, . . .Bn} ⊆ {A1,A2, . . .An}.

I non-trivial if at least one B is not among the A’s, i.e.,{B1,B2, . . .Bn} − {A1,A2, . . .An} 6= ∅.

I completely non-trivial if none of the B’s are among the A’s, i.e.,{B1,B2, . . .Bn} ∩ {A1,A2, . . .An} = ∅.

I What good are trivial and non-trivial dependencies?I Trivial dependencies are always true.I They help simplify reasoning about FDs.

I Trivial dependency rule: The FD A1A2 . . .An → B1B2 . . .Bm isequivalent to the FD A1A2 . . .An → C1C2 . . .Ck , where the C ’s arethose B’s that are not A’s, i.e.,{C1,C2, . . . ,Ck} = {B1,B2, . . . ,Bm} − {A1,A2, . . . ,An}.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 68: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Triviality of FDs

An FD A1A2 . . .An → B1B2 . . .Bm is

I trivial if the B’s are a subset of the A’s, i.e.,{B1,B2, . . .Bn} ⊆ {A1,A2, . . .An}.

I non-trivial if at least one B is not among the A’s, i.e.,{B1,B2, . . .Bn} − {A1,A2, . . .An} 6= ∅.

I completely non-trivial if none of the B’s are among the A’s, i.e.,{B1,B2, . . .Bn} ∩ {A1,A2, . . .An} = ∅.

I What good are trivial and non-trivial dependencies?I Trivial dependencies are always true.I They help simplify reasoning about FDs.

I Trivial dependency rule: The FD A1A2 . . .An → B1B2 . . .Bm isequivalent to the FD A1A2 . . .An → C1C2 . . .Ck , where the C ’s arethose B’s that are not A’s, i.e.,{C1,C2, . . . ,Ck} = {B1,B2, . . . ,Bm} − {A1,A2, . . . ,An}.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 69: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Triviality of FDs

An FD A1A2 . . .An → B1B2 . . .Bm is

I trivial if the B’s are a subset of the A’s, i.e.,{B1,B2, . . .Bn} ⊆ {A1,A2, . . .An}.

I non-trivial if at least one B is not among the A’s,

i.e.,{B1,B2, . . .Bn} − {A1,A2, . . .An} 6= ∅.

I completely non-trivial if none of the B’s are among the A’s, i.e.,{B1,B2, . . .Bn} ∩ {A1,A2, . . .An} = ∅.

I What good are trivial and non-trivial dependencies?I Trivial dependencies are always true.I They help simplify reasoning about FDs.

I Trivial dependency rule: The FD A1A2 . . .An → B1B2 . . .Bm isequivalent to the FD A1A2 . . .An → C1C2 . . .Ck , where the C ’s arethose B’s that are not A’s, i.e.,{C1,C2, . . . ,Ck} = {B1,B2, . . . ,Bm} − {A1,A2, . . . ,An}.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 70: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Triviality of FDs

An FD A1A2 . . .An → B1B2 . . .Bm is

I trivial if the B’s are a subset of the A’s, i.e.,{B1,B2, . . .Bn} ⊆ {A1,A2, . . .An}.

I non-trivial if at least one B is not among the A’s, i.e.,{B1,B2, . . .Bn} − {A1,A2, . . .An} 6= ∅.

I completely non-trivial if none of the B’s are among the A’s, i.e.,{B1,B2, . . .Bn} ∩ {A1,A2, . . .An} = ∅.

I What good are trivial and non-trivial dependencies?I Trivial dependencies are always true.I They help simplify reasoning about FDs.

I Trivial dependency rule: The FD A1A2 . . .An → B1B2 . . .Bm isequivalent to the FD A1A2 . . .An → C1C2 . . .Ck , where the C ’s arethose B’s that are not A’s, i.e.,{C1,C2, . . . ,Ck} = {B1,B2, . . . ,Bm} − {A1,A2, . . . ,An}.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 71: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Triviality of FDs

An FD A1A2 . . .An → B1B2 . . .Bm is

I trivial if the B’s are a subset of the A’s, i.e.,{B1,B2, . . .Bn} ⊆ {A1,A2, . . .An}.

I non-trivial if at least one B is not among the A’s, i.e.,{B1,B2, . . .Bn} − {A1,A2, . . .An} 6= ∅.

I completely non-trivial if none of the B’s are among the A’s,

i.e.,{B1,B2, . . .Bn} ∩ {A1,A2, . . .An} = ∅.

I What good are trivial and non-trivial dependencies?I Trivial dependencies are always true.I They help simplify reasoning about FDs.

I Trivial dependency rule: The FD A1A2 . . .An → B1B2 . . .Bm isequivalent to the FD A1A2 . . .An → C1C2 . . .Ck , where the C ’s arethose B’s that are not A’s, i.e.,{C1,C2, . . . ,Ck} = {B1,B2, . . . ,Bm} − {A1,A2, . . . ,An}.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 72: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Triviality of FDs

An FD A1A2 . . .An → B1B2 . . .Bm is

I trivial if the B’s are a subset of the A’s, i.e.,{B1,B2, . . .Bn} ⊆ {A1,A2, . . .An}.

I non-trivial if at least one B is not among the A’s, i.e.,{B1,B2, . . .Bn} − {A1,A2, . . .An} 6= ∅.

I completely non-trivial if none of the B’s are among the A’s, i.e.,{B1,B2, . . .Bn} ∩ {A1,A2, . . .An} = ∅.

I What good are trivial and non-trivial dependencies?I Trivial dependencies are always true.I They help simplify reasoning about FDs.

I Trivial dependency rule: The FD A1A2 . . .An → B1B2 . . .Bm isequivalent to the FD A1A2 . . .An → C1C2 . . .Ck , where the C ’s arethose B’s that are not A’s, i.e.,{C1,C2, . . . ,Ck} = {B1,B2, . . . ,Bm} − {A1,A2, . . . ,An}.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 73: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Triviality of FDs

An FD A1A2 . . .An → B1B2 . . .Bm is

I trivial if the B’s are a subset of the A’s, i.e.,{B1,B2, . . .Bn} ⊆ {A1,A2, . . .An}.

I non-trivial if at least one B is not among the A’s, i.e.,{B1,B2, . . .Bn} − {A1,A2, . . .An} 6= ∅.

I completely non-trivial if none of the B’s are among the A’s, i.e.,{B1,B2, . . .Bn} ∩ {A1,A2, . . .An} = ∅.

I What good are trivial and non-trivial dependencies?I Trivial dependencies are always true.I They help simplify reasoning about FDs.

I Trivial dependency rule: The FD A1A2 . . .An → B1B2 . . .Bm isequivalent to the FD A1A2 . . .An → C1C2 . . .Ck , where the C ’s arethose B’s that are not A’s, i.e.,{C1,C2, . . . ,Ck} = {B1,B2, . . . ,Bm} − {A1,A2, . . . ,An}.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 74: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Triviality of FDs

An FD A1A2 . . .An → B1B2 . . .Bm is

I trivial if the B’s are a subset of the A’s, i.e.,{B1,B2, . . .Bn} ⊆ {A1,A2, . . .An}.

I non-trivial if at least one B is not among the A’s, i.e.,{B1,B2, . . .Bn} − {A1,A2, . . .An} 6= ∅.

I completely non-trivial if none of the B’s are among the A’s, i.e.,{B1,B2, . . .Bn} ∩ {A1,A2, . . .An} = ∅.

I What good are trivial and non-trivial dependencies?I Trivial dependencies are always true.I They help simplify reasoning about FDs.

I Trivial dependency rule: The FD A1A2 . . .An → B1B2 . . .Bm isequivalent to the FD A1A2 . . .An → C1C2 . . .Ck , where the C ’s arethose B’s that are not A’s, i.e.,{C1,C2, . . . ,Ck} = {B1,B2, . . . ,Bm} − {A1,A2, . . . ,An}.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 75: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Example

Suppose a relation with attributes A,B,C ,D,E , and F satisfies the FDs

AB → C BC → AD D → E , CF → B

Given these FDs,

I what is the set X of attributes such that AB → X is true?

X = {A,B,C ,D,E}, i.e., AB → ABCDE .

I what is the set Y of attributes such that BCF → Y is true?Y = {A,B,C ,D,E ,F}, i.e., BCF → ABCDEF

I what is the set Z of attributes such that AF → Z is true?Z = {A,F}, i.e., AF → AF .

I X ,Y , and Z are the closures of {A,B}, {B,C ,F}, and {A,F},respectively.

I {B,C ,F} is a superkey.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 76: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Example

Suppose a relation with attributes A,B,C ,D,E , and F satisfies the FDs

AB → C BC → AD D → E , CF → B

Given these FDs,

I what is the set X of attributes such that AB → X is true?X = {A,B,C ,D,E}, i.e., AB → ABCDE .

I what is the set Y of attributes such that BCF → Y is true?Y = {A,B,C ,D,E ,F}, i.e., BCF → ABCDEF

I what is the set Z of attributes such that AF → Z is true?Z = {A,F}, i.e., AF → AF .

I X ,Y , and Z are the closures of {A,B}, {B,C ,F}, and {A,F},respectively.

I {B,C ,F} is a superkey.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 77: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Example

Suppose a relation with attributes A,B,C ,D,E , and F satisfies the FDs

AB → C BC → AD D → E , CF → B

Given these FDs,

I what is the set X of attributes such that AB → X is true?X = {A,B,C ,D,E}, i.e., AB → ABCDE .

I what is the set Y of attributes such that BCF → Y is true?

Y = {A,B,C ,D,E ,F}, i.e., BCF → ABCDEF

I what is the set Z of attributes such that AF → Z is true?Z = {A,F}, i.e., AF → AF .

I X ,Y , and Z are the closures of {A,B}, {B,C ,F}, and {A,F},respectively.

I {B,C ,F} is a superkey.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 78: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Example

Suppose a relation with attributes A,B,C ,D,E , and F satisfies the FDs

AB → C BC → AD D → E , CF → B

Given these FDs,

I what is the set X of attributes such that AB → X is true?X = {A,B,C ,D,E}, i.e., AB → ABCDE .

I what is the set Y of attributes such that BCF → Y is true?Y = {A,B,C ,D,E ,F}, i.e., BCF → ABCDEF

I what is the set Z of attributes such that AF → Z is true?Z = {A,F}, i.e., AF → AF .

I X ,Y , and Z are the closures of {A,B}, {B,C ,F}, and {A,F},respectively.

I {B,C ,F} is a superkey.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 79: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Example

Suppose a relation with attributes A,B,C ,D,E , and F satisfies the FDs

AB → C BC → AD D → E , CF → B

Given these FDs,

I what is the set X of attributes such that AB → X is true?X = {A,B,C ,D,E}, i.e., AB → ABCDE .

I what is the set Y of attributes such that BCF → Y is true?Y = {A,B,C ,D,E ,F}, i.e., BCF → ABCDEF

I what is the set Z of attributes such that AF → Z is true?

Z = {A,F}, i.e., AF → AF .

I X ,Y , and Z are the closures of {A,B}, {B,C ,F}, and {A,F},respectively.

I {B,C ,F} is a superkey.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 80: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Example

Suppose a relation with attributes A,B,C ,D,E , and F satisfies the FDs

AB → C BC → AD D → E , CF → B

Given these FDs,

I what is the set X of attributes such that AB → X is true?X = {A,B,C ,D,E}, i.e., AB → ABCDE .

I what is the set Y of attributes such that BCF → Y is true?Y = {A,B,C ,D,E ,F}, i.e., BCF → ABCDEF

I what is the set Z of attributes such that AF → Z is true?Z = {A,F}, i.e., AF → AF .

I X ,Y , and Z are the closures of {A,B}, {B,C ,F}, and {A,F},respectively.

I {B,C ,F} is a superkey.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 81: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Example

Suppose a relation with attributes A,B,C ,D,E , and F satisfies the FDs

AB → C BC → AD D → E , CF → B

Given these FDs,

I what is the set X of attributes such that AB → X is true?X = {A,B,C ,D,E}, i.e., AB → ABCDE .

I what is the set Y of attributes such that BCF → Y is true?Y = {A,B,C ,D,E ,F}, i.e., BCF → ABCDEF

I what is the set Z of attributes such that AF → Z is true?Z = {A,F}, i.e., AF → AF .

I X ,Y , and Z are the closures of {A,B}, {B,C ,F}, and {A,F},respectively.

I {B,C ,F} is a superkey.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 82: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Example

Suppose a relation with attributes A,B,C ,D,E , and F satisfies the FDs

AB → C BC → AD D → E , CF → B

Given these FDs,

I what is the set X of attributes such that AB → X is true?X = {A,B,C ,D,E}, i.e., AB → ABCDE .

I what is the set Y of attributes such that BCF → Y is true?Y = {A,B,C ,D,E ,F}, i.e., BCF → ABCDEF

I what is the set Z of attributes such that AF → Z is true?Z = {A,F}, i.e., AF → AF .

I X ,Y , and Z are the closures of {A,B}, {B,C ,F}, and {A,F},respectively.

I {B,C ,F} is a

superkey.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 83: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Example

Suppose a relation with attributes A,B,C ,D,E , and F satisfies the FDs

AB → C BC → AD D → E , CF → B

Given these FDs,

I what is the set X of attributes such that AB → X is true?X = {A,B,C ,D,E}, i.e., AB → ABCDE .

I what is the set Y of attributes such that BCF → Y is true?Y = {A,B,C ,D,E ,F}, i.e., BCF → ABCDEF

I what is the set Z of attributes such that AF → Z is true?Z = {A,F}, i.e., AF → AF .

I X ,Y , and Z are the closures of {A,B}, {B,C ,F}, and {A,F},respectively.

I {B,C ,F} is a superkey.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 84: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Definition

Given

I a set of attributes {A1,A2, . . . ,An} and

I a set of FDs S ,

the closure of {A1,A2, . . . ,An} under the FDs in S is

I the set of attributes {B1,B2, . . . ,Bm} such that for 1 ≤ i ≤ m, theFD A1A2 . . .An → Bi follows from S .

I the closure is denoted by {A1,A2, . . . ,An}+.

I Which attributes must {A1,A2, . . . ,An}+ contain at a minimum?{A1,A2, . . . ,An}. Why? A1A2 . . .An → Ai is a trivial FD.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 85: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Definition

Given

I a set of attributes {A1,A2, . . . ,An} and

I a set of FDs S ,

the closure of {A1,A2, . . . ,An} under the FDs in S is

I the set of attributes {B1,B2, . . . ,Bm} such that for 1 ≤ i ≤ m, theFD A1A2 . . .An → Bi follows from S .

I the closure is denoted by {A1,A2, . . . ,An}+.

I Which attributes must {A1,A2, . . . ,An}+ contain at a minimum?

{A1,A2, . . . ,An}. Why? A1A2 . . .An → Ai is a trivial FD.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 86: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Definition

Given

I a set of attributes {A1,A2, . . . ,An} and

I a set of FDs S ,

the closure of {A1,A2, . . . ,An} under the FDs in S is

I the set of attributes {B1,B2, . . . ,Bm} such that for 1 ≤ i ≤ m, theFD A1A2 . . .An → Bi follows from S .

I the closure is denoted by {A1,A2, . . . ,An}+.

I Which attributes must {A1,A2, . . . ,An}+ contain at a minimum?{A1,A2, . . . ,An}. Why?

A1A2 . . .An → Ai is a trivial FD.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 87: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Definition

Given

I a set of attributes {A1,A2, . . . ,An} and

I a set of FDs S ,

the closure of {A1,A2, . . . ,An} under the FDs in S is

I the set of attributes {B1,B2, . . . ,Bm} such that for 1 ≤ i ≤ m, theFD A1A2 . . .An → Bi follows from S .

I the closure is denoted by {A1,A2, . . . ,An}+.

I Which attributes must {A1,A2, . . . ,An}+ contain at a minimum?{A1,A2, . . . ,An}. Why? A1A2 . . .An → Ai is a trivial FD.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 88: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Algorithm

Given

I a set of attributes {A1,A2, . . . ,An} andI a set of FDs S ,I compute X = {A1,A2, . . . ,An}+.

1. Use the splitting rule so that each FD in S has one attribute on theright.

2. Set X ← {A1,A2, . . . ,An}.3. Find an FD B1B2 . . .Bk → C in S such that {B1,B2, . . .Bk} ⊆ X but

C 6∈ X .

4. Add C to X .

5. Repeat the last two steps until you cannot find such an attribute C .

6. The final value of X is the desired closure.

I Why does the algorithm compute the closure correctly? Read Chapter3.2.5 of the textbook.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 89: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Algorithm

Given

I a set of attributes {A1,A2, . . . ,An} andI a set of FDs S ,I compute X = {A1,A2, . . . ,An}+.

1. Use the splitting rule so that each FD in S has one attribute on theright.

2. Set X ← {A1,A2, . . . ,An}.3. Find an FD B1B2 . . .Bk → C in S such that {B1,B2, . . .Bk} ⊆ X but

C 6∈ X .

4. Add C to X .

5. Repeat the last two steps until you cannot find such an attribute C .

6. The final value of X is the desired closure.

I Why does the algorithm compute the closure correctly? Read Chapter3.2.5 of the textbook.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 90: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Closures of Attributes: Algorithm

Given

I a set of attributes {A1,A2, . . . ,An} andI a set of FDs S ,I compute X = {A1,A2, . . . ,An}+.

1. Use the splitting rule so that each FD in S has one attribute on theright.

2. Set X ← {A1,A2, . . . ,An}.3. Find an FD B1B2 . . .Bk → C in S such that {B1,B2, . . .Bk} ⊆ X but

C 6∈ X .

4. Add C to X .

5. Repeat the last two steps until you cannot find such an attribute C .

6. The final value of X is the desired closure.

I Why does the algorithm compute the closure correctly? Read Chapter3.2.5 of the textbook.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 91: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Why is the Concept of Closures Useful?

1. Prove correctness of rules for manipulating FDs.

For example,I Transitive rule: if

A1A2 . . .An → B1B2 . . .Bm

andB1B2 . . .Bm → C1C2 . . .Ck

thenA1A2 . . .An → C1C2 . . .Ck .

I To prove this rule, simply check if{C1,C2, . . . ,Ck} ⊆ {A1,A2, . . . ,An}+.

2. Check if a “new” FD A1A2 . . .An → B follows from a set of FDs S :simply check if B is in {A1,A2, . . .An}+ under S .

3. Procedurally define keys. A set of attributes X is a key for a relationR if and only if

I {X}+ is the set of all attributes of R andI for no attribute A ∈ X is {X − {A}}+ the set of all attributes of R.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 92: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Why is the Concept of Closures Useful?

1. Prove correctness of rules for manipulating FDs. For example,I Transitive rule: if

A1A2 . . .An → B1B2 . . .Bm

andB1B2 . . .Bm → C1C2 . . .Ck

thenA1A2 . . .An → C1C2 . . .Ck .

I To prove this rule, simply check if{C1,C2, . . . ,Ck} ⊆ {A1,A2, . . . ,An}+.

2. Check if a “new” FD A1A2 . . .An → B follows from a set of FDs S :simply check if B is in {A1,A2, . . .An}+ under S .

3. Procedurally define keys. A set of attributes X is a key for a relationR if and only if

I {X}+ is the set of all attributes of R andI for no attribute A ∈ X is {X − {A}}+ the set of all attributes of R.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 93: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Why is the Concept of Closures Useful?

1. Prove correctness of rules for manipulating FDs. For example,I Transitive rule: if

A1A2 . . .An → B1B2 . . .Bm

andB1B2 . . .Bm → C1C2 . . .Ck

thenA1A2 . . .An → C1C2 . . .Ck .

I To prove this rule, simply check if{C1,C2, . . . ,Ck} ⊆ {A1,A2, . . . ,An}+.

2. Check if a “new” FD A1A2 . . .An → B follows from a set of FDs S :simply check if B is in {A1,A2, . . .An}+ under S .

3. Procedurally define keys. A set of attributes X is a key for a relationR if and only if

I {X}+ is the set of all attributes of R andI for no attribute A ∈ X is {X − {A}}+ the set of all attributes of R.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 94: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Why is the Concept of Closures Useful?

1. Prove correctness of rules for manipulating FDs. For example,I Transitive rule: if

A1A2 . . .An → B1B2 . . .Bm

andB1B2 . . .Bm → C1C2 . . .Ck

thenA1A2 . . .An → C1C2 . . .Ck .

I To prove this rule, simply check if{C1,C2, . . . ,Ck} ⊆ {A1,A2, . . . ,An}+.

2. Check if a “new” FD A1A2 . . .An → B follows from a set of FDs S :simply check if B is in {A1,A2, . . .An}+ under S .

3. Procedurally define keys. A set of attributes X is a key for a relationR if and only if

I {X}+ is the set of all attributes of R andI for no attribute A ∈ X is {X − {A}}+ the set of all attributes of R.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 95: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Why is the Concept of Closures Useful?

1. Prove correctness of rules for manipulating FDs. For example,I Transitive rule: if

A1A2 . . .An → B1B2 . . .Bm

andB1B2 . . .Bm → C1C2 . . .Ck

thenA1A2 . . .An → C1C2 . . .Ck .

I To prove this rule, simply check if{C1,C2, . . . ,Ck} ⊆ {A1,A2, . . . ,An}+.

2. Check if a “new” FD A1A2 . . .An → B follows from a set of FDs S :simply check if B is in {A1,A2, . . .An}+ under S .

3. Procedurally define keys.

A set of attributes X is a key for a relationR if and only if

I {X}+ is the set of all attributes of R andI for no attribute A ∈ X is {X − {A}}+ the set of all attributes of R.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 96: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Why is the Concept of Closures Useful?

1. Prove correctness of rules for manipulating FDs. For example,I Transitive rule: if

A1A2 . . .An → B1B2 . . .Bm

andB1B2 . . .Bm → C1C2 . . .Ck

thenA1A2 . . .An → C1C2 . . .Ck .

I To prove this rule, simply check if{C1,C2, . . . ,Ck} ⊆ {A1,A2, . . . ,An}+.

2. Check if a “new” FD A1A2 . . .An → B follows from a set of FDs S :simply check if B is in {A1,A2, . . .An}+ under S .

3. Procedurally define keys. A set of attributes X is a key for a relationR if and only if

I {X}+ is the set of all attributes of R andI for no attribute A ∈ X is {X − {A}}+ the set of all attributes of R.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 97: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Examples of Closure Computations

I Consider the “bad” relation Students(Id, Name, AdvisorId,

AdvisorName, FavouriteAdvisorId).

I What are the FDs that hold in this relation?

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→ AdvisorName

I To compute the key for this relation,

1. Compute the closures for all sets of attributes.2. Find the minimal set of attributes whose closure is the set of all

attributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 98: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Examples of Closure Computations

I Consider the “bad” relation Students(Id, Name, AdvisorId,

AdvisorName, FavouriteAdvisorId).

I What are the FDs that hold in this relation?

Id→ Name

Id→ FavouriteAdvisorId

AdvisorId→ AdvisorName

I To compute the key for this relation,

1. Compute the closures for all sets of attributes.2. Find the minimal set of attributes whose closure is the set of all

attributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 99: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Algorithm for Computing Keys

Given

I a relation R(A1,A2, . . . ,An) and

I the set of all FDs S that hold in R,

I compute all the keys of R.

1. For every subset K ⊆ {A1,A2, . . . ,An}, compute {K}+.

2. If {K}+ = {A1,A2, . . . ,An} and for every attribute A,{K − {A}}+ 6= {A1,A2, . . . ,An}, then output K as a key.

I Running time of the algorithm is exponential in the number ofattributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 100: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Algorithm for Computing Keys

Given

I a relation R(A1,A2, . . . ,An) and

I the set of all FDs S that hold in R,

I compute all the keys of R.

1. For every subset K ⊆ {A1,A2, . . . ,An}, compute {K}+.

2. If {K}+ = {A1,A2, . . . ,An} and for every attribute A,{K − {A}}+ 6= {A1,A2, . . . ,An}, then output K as a key.

I Running time of the algorithm is exponential in the number ofattributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 101: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Algorithm for Computing Keys

Given

I a relation R(A1,A2, . . . ,An) and

I the set of all FDs S that hold in R,

I compute all the keys of R.

1. For every subset K ⊆ {A1,A2, . . . ,An}, compute {K}+.

2. If {K}+ = {A1,A2, . . . ,An} and for every attribute A,{K − {A}}+ 6= {A1,A2, . . . ,An}, then output K as a key.

I Running time of the algorithm is exponential in the number ofattributes.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 102: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Armstrong’s Axioms

I We can use closures of attributes to determine if any FD follows froma given set of FDs.

I Armstrong’s axioms: complete set of inference rules from which it ispossible to derive every FD that follows from a given set:

Reflexivity If {B1,B2, . . . ,Bm} ⊆ {A1,A2, . . . ,An}, thenA1A2 . . .Am → B1B2 . . .Bm (Trivial FDs).

Augmentation If A1A2 . . .Am → B1B2 . . .Bm, thenA1A2 . . .AmC1C2 . . .Ck → B1B2 . . .BmC1C2 . . .Ck , forany set of attributes {C1,C2, . . . ,Ck}.

Transitivity If A1A2 . . .An → B1B2 . . .Bm andB1B2 . . .Bm → C1C2 . . .Ck thenA1A2 . . .An → C1C2 . . .Ck .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 103: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Armstrong’s Axioms

I We can use closures of attributes to determine if any FD follows froma given set of FDs.

I Armstrong’s axioms: complete set of inference rules from which it ispossible to derive every FD that follows from a given set:

Reflexivity If {B1,B2, . . . ,Bm} ⊆ {A1,A2, . . . ,An}, thenA1A2 . . .Am → B1B2 . . .Bm (Trivial FDs).

Augmentation If A1A2 . . .Am → B1B2 . . .Bm, thenA1A2 . . .AmC1C2 . . .Ck → B1B2 . . .BmC1C2 . . .Ck , forany set of attributes {C1,C2, . . . ,Ck}.

Transitivity If A1A2 . . .An → B1B2 . . .Bm andB1B2 . . .Bm → C1C2 . . .Ck thenA1A2 . . .An → C1C2 . . .Ck .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 104: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Armstrong’s Axioms

I We can use closures of attributes to determine if any FD follows froma given set of FDs.

I Armstrong’s axioms: complete set of inference rules from which it ispossible to derive every FD that follows from a given set:

Reflexivity If {B1,B2, . . . ,Bm} ⊆ {A1,A2, . . . ,An}, thenA1A2 . . .Am → B1B2 . . .Bm (Trivial FDs).

Augmentation If A1A2 . . .Am → B1B2 . . .Bm, thenA1A2 . . .AmC1C2 . . .Ck → B1B2 . . .BmC1C2 . . .Ck , forany set of attributes {C1,C2, . . . ,Ck}.

Transitivity If A1A2 . . .An → B1B2 . . .Bm andB1B2 . . .Bm → C1C2 . . .Ck thenA1A2 . . .An → C1C2 . . .Ck .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 105: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Armstrong’s Axioms

I We can use closures of attributes to determine if any FD follows froma given set of FDs.

I Armstrong’s axioms: complete set of inference rules from which it ispossible to derive every FD that follows from a given set:

Reflexivity If {B1,B2, . . . ,Bm} ⊆ {A1,A2, . . . ,An}, thenA1A2 . . .Am → B1B2 . . .Bm (Trivial FDs).

Augmentation If A1A2 . . .Am → B1B2 . . .Bm, thenA1A2 . . .AmC1C2 . . .Ck → B1B2 . . .BmC1C2 . . .Ck , forany set of attributes {C1,C2, . . . ,Ck}.

Transitivity If A1A2 . . .An → B1B2 . . .Bm andB1B2 . . .Bm → C1C2 . . .Ck thenA1A2 . . .An → C1C2 . . .Ck .

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 106: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Differences in Notation

Relation schema R(A1,A2,A3): parentheses surround attributes,attributes separated by commas.

Set of attributes {A1,A2,A3}: curly braces surround attributes, attributesseparated by commas.

FD A1A2 → A3: no parentheses or curly braces, attributesseparated by spaces, arrows separates left hand side and righthand side.

Set of FDs {A1A2 → A3,A2 → A1}: curly braces surround FDs, FDsseparated by commas.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 107: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Minimal Basis

I A relation may have a large set of equivalent sets of FDs.

I If we are given a set S of FDs, then any set of FDs that is equivalentto S is called a basis of S .

I We will limit ourselves to bases in which each FD has only oneattribute on the right hand side.

I A set B of FDs is a minimal basis for a relation R if

1. Every FD in B has one attribute on the right hand side.2. If we remove any FD from B, then the result is not a basis.3. If for any FD in B, we remove one or more attributes from the left

hand side of the FD, then the result is not a basis.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 108: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Minimal Basis

I A relation may have a large set of equivalent sets of FDs.

I If we are given a set S of FDs, then any set of FDs that is equivalentto S is called a basis of S .

I We will limit ourselves to bases in which each FD has only oneattribute on the right hand side.

I A set B of FDs is a minimal basis for a relation R if

1. Every FD in B has one attribute on the right hand side.2. If we remove any FD from B, then the result is not a basis.3. If for any FD in B, we remove one or more attributes from the left

hand side of the FD, then the result is not a basis.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 109: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Minimal Basis

I A relation may have a large set of equivalent sets of FDs.

I If we are given a set S of FDs, then any set of FDs that is equivalentto S is called a basis of S .

I We will limit ourselves to bases in which each FD has only oneattribute on the right hand side.

I A set B of FDs is a minimal basis for a relation R if

1. Every FD in B has one attribute on the right hand side.2. If we remove any FD from B, then the result is not a basis.3. If for any FD in B, we remove one or more attributes from the left

hand side of the FD, then the result is not a basis.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 110: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of Minimal Basis

I R(A,B,C ) is a relation such that each attribute functionallydetermines the other two attributes.

I What are the FDs that hold in R and what are the minimal bases?(Assume only one attribute on the right-hand side, only non-trivialFDs)

I FDs: A→ B, A→ C , B → A, B → C , C → A, C → B, AB → C ,BC → A, AC → B.

I Minimal bases: {A→ B,B → A,B → C ,C → B},{A→ B,B → C ,C → A}, and others.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 111: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of Minimal Basis

I R(A,B,C ) is a relation such that each attribute functionallydetermines the other two attributes.

I What are the FDs that hold in R and what are the minimal bases?(Assume only one attribute on the right-hand side, only non-trivialFDs)

I FDs:

A→ B, A→ C , B → A, B → C , C → A, C → B, AB → C ,BC → A, AC → B.

I Minimal bases: {A→ B,B → A,B → C ,C → B},{A→ B,B → C ,C → A}, and others.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 112: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of Minimal Basis

I R(A,B,C ) is a relation such that each attribute functionallydetermines the other two attributes.

I What are the FDs that hold in R and what are the minimal bases?(Assume only one attribute on the right-hand side, only non-trivialFDs)

I FDs: A→ B, A→ C , B → A, B → C , C → A, C → B,

AB → C ,BC → A, AC → B.

I Minimal bases: {A→ B,B → A,B → C ,C → B},{A→ B,B → C ,C → A}, and others.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 113: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of Minimal Basis

I R(A,B,C ) is a relation such that each attribute functionallydetermines the other two attributes.

I What are the FDs that hold in R and what are the minimal bases?(Assume only one attribute on the right-hand side, only non-trivialFDs)

I FDs: A→ B, A→ C , B → A, B → C , C → A, C → B, AB → C ,BC → A, AC → B.

I Minimal bases: {A→ B,B → A,B → C ,C → B},{A→ B,B → C ,C → A}, and others.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 114: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of Minimal Basis

I R(A,B,C ) is a relation such that each attribute functionallydetermines the other two attributes.

I What are the FDs that hold in R and what are the minimal bases?(Assume only one attribute on the right-hand side, only non-trivialFDs)

I FDs: A→ B, A→ C , B → A, B → C , C → A, C → B, AB → C ,BC → A, AC → B.

I Minimal bases:

{A→ B,B → A,B → C ,C → B},{A→ B,B → C ,C → A}, and others.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies

Page 115: Functional Dependencies - Undergraduate Courses | Computer Science

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Example of Minimal Basis

I R(A,B,C ) is a relation such that each attribute functionallydetermines the other two attributes.

I What are the FDs that hold in R and what are the minimal bases?(Assume only one attribute on the right-hand side, only non-trivialFDs)

I FDs: A→ B, A→ C , B → A, B → C , C → A, C → B, AB → C ,BC → A, AC → B.

I Minimal bases: {A→ B,B → A,B → C ,C → B},{A→ B,B → C ,C → A}, and others.

T. M. Murali October 18, 25, 2010 CS 4604: Functional Dependencies