Basics of FDs Manipulating FDs Closures and Keys Minimal Bases

Functional Dependencies

T. M. Murali

October 19, 21 2009

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies Students(Id, Name) Advisors(Id, Name) Advises(StudentId, AdvisorId) Favourite(StudentId, AdvisorId)

I Suppose we perversely decide to convert Students, Advises, and Favourite into one . Students(Id, Name, AdvisorId, AdvisorName, FavouriteAdvisorId)

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Example

Name Id Name Id

Students Advises Advisors

Favourite

I Convert to relations:

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I Suppose we perversely decide to convert Students, Advises, and Favourite into one relation. Students(Id, Name, AdvisorId, AdvisorName, FavouriteAdvisorId)

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Example

Name Id Name Id

Students Advises Advisors

Favourite

I Convert to relations: Students(Id, Name) Advisors(Id, Name) Advises(StudentId, AdvisorId) Favourite(StudentId, AdvisorId)

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Example

Name Id Name Id

Students Advises Advisors

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, and Favourite into one relation. Students(Id, Name, AdvisorId, AdvisorName, FavouriteAdvisorId)

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 other attributes?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 other attributes? Name and FavouriteAdvisorId.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 other attributes? Name and FavouriteAdvisorId. Id → Name Id → FavouriteAdvisorId

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 other attributes? Name and FavouriteAdvisorId. Id → Name Id → FavouriteAdvisorId AdvisorId →

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 other attributes? Name and FavouriteAdvisorId. Id → Name Id → FavouriteAdvisorId AdvisorId → AdvisorName

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 other attributes? Name and FavouriteAdvisorId. Id → Name Id → FavouriteAdvisorId AdvisorId → AdvisorName

I Can we say Id → AdvisorId?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I What is the key for the Students? {Id, AdvisorId}.

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

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 other attributes? 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.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies {Id, AdvisorId}.

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

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 other attributes? 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?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I Why is this relation “bad?” Parts of the key determine other attributes.

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 other attributes? 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}.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies Parts of the key determine other attributes.

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 other attributes? 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?”

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 other attributes? 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 19, 21 2009 CS 4604: Functional Dependencies 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 19, 21 2009 CS 4604: Functional Dependencies I The FD AdvisorId → AdvisorName holds in R if in every instance of R, for every pair of t and u

if tAdvisorId = uAdvisorId, then tAdvisorName = uAdvisorName.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Definition of Functional Dependency

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies if tAdvisorId = uAdvisorId, then tAdvisorName = uAdvisorName.

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 the value of attribute A in tuple t.

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 the value of attribute A in tuple t.

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

if tAdvisorId = uAdvisorId, then tAdvisorName = uAdvisorName.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I FD says that for every pair of tuples t and u in any instance of R, if

tA1 = uA1 and tA2 = uA2 and ... tAn = uAn , then tB = uB . I The set of attributes A1, A2,... An functionally determineB .

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

I You cannot deduce an FD from a relation instance.

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 agree on attribute B.

I Notation: A1A2 ... An → B

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies if

tA1 = uA1 and tA2 = uA2 and ... tAn = uAn , then tB = uB . I The set of attributes A1, A2,... An functionally determineB .

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

I You cannot deduce an FD from a relation instance.

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 agree on attribute B.

I Notation: A1A2 ... An → B

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 agree on attribute B.

I Notation: A1A2 ... An → B

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

tA1 = uA1 and tA2 = uA2 and ... tAn = uAn , then tB = uB . I The set of attributes A1, A2,... An functionally determineB .

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

I You cannot deduce an FD from a relation instance.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies Number DeptName → CourseName Number DeptName → Classroom Number DeptName → Enrollment Number DeptName → CourseName Classroom Enrollment

I Is Number → Enrollment an FD?

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 45 4604 Dance Tree Dancing Drillfield 45 4604 English The Basis of Data Williams 44 45 2604 CS Data Structures MCB 114 100 2604 Physics Dark Matter Williams 44 100

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies Number DeptName → CourseName Classroom Enrollment

I Is Number → Enrollment an FD?

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 45 4604 Dance Tree Dancing Drillfield 45 4604 English The Basis of Data Williams 44 45 2604 CS Data Structures MCB 114 100 2604 Physics Dark Matter Williams 44 100

Number DeptName → CourseName Number DeptName → Classroom Number DeptName → Enrollment

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I Is Number → Enrollment an FD?

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 45 4604 Dance Tree Dancing Drillfield 45 4604 English The Basis of Data Williams 44 45 2604 CS Data Structures MCB 114 100 2604 Physics Dark Matter Williams 44 100

Number DeptName → CourseName Number DeptName → Classroom Number DeptName → Enrollment Number DeptName → CourseName Classroom Enrollment

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 45 4604 Dance Tree Dancing Drillfield 45 4604 English The Basis of Data Williams 44 45 2604 CS Data Structures MCB 114 100 2604 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 19, 21 2009 CS 4604: Functional Dependencies I “Keyness” of attributes.

I Domain and application constraints.

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

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Where do FDs come from?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 19, 21 2009 CS 4604: Functional Dependencies I A is a set of attributes that has the uniqueness property but is 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 the primary key.

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

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 other attributes of R and Minimality no proper of {A1, A2,... An} functionally determines all the other attributes of R.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 other attributes of R and Minimality no proper subset of {A1, A2,... An} functionally determines all the other attributes of R.

I A superkey is a set of attributes that has the uniqueness property but is 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 the primary key.

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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?

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)?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I What is the key for Teach(, , ProfessorName, Classroom)?

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

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.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I The key is {Number, DepartmentName}. Why?

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)?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 19, 21 2009 CS 4604: Functional Dependencies I If the relation comes from a binary relationship R between entity sets E and F :

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

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

I R is one-one: key attributes of the relation are the key attributes of E or of F . I If the relationship R is multiway, we need to reason about the FDs that 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.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Keys in the Conversion from E/R to Relational Designs

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I R is many-many: key attributes of the relation are the key attributes of E and of F .

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

I R is one-one: key attributes of the relation are the key attributes of E or of F . I If the relationship R is multiway, we need to reason about the FDs that 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.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Keys in the Conversion from E/R to Relational Designs

I If the relation comes from an entity set, the key attributes of the relation are precisely the key attributes of the entity set. I If the relation comes from a binary relationship R between entity sets E and F :

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies key attributes of the relation are the key attributes of E and of F .

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

I R is one-one: key attributes of the relation are the key attributes of E or of F . I If the relationship R is multiway, we need to reason about the FDs that 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.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Keys in the Conversion from E/R to Relational Designs

I If the relation comes from an entity set, the key attributes of the relation are precisely the key attributes of the entity set. I If the relation comes from a binary relationship R between entity sets E and F :

I R is many-many:

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I R is many-one from E to F : key attributes of the relation are the key attributes of E.

I R is one-one: key attributes of the relation are the key attributes of E or of F . I If the relationship R is multiway, we need to reason about the FDs that 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.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Keys in the Conversion from E/R to Relational Designs

I If the relation comes from an entity set, the key attributes of the relation are precisely the key attributes of the entity set. I If the relation comes from a binary relationship R between entity sets E and F :

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies key attributes of the relation are the key attributes of E.

I R is one-one: key attributes of the relation are the key attributes of E or of F . I If the relationship R is multiway, we need to reason about the FDs that 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.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Keys in the Conversion from E/R to Relational Designs

I If the relation comes from an entity set, the key attributes of the relation are precisely the key attributes of the entity set. I If the relation comes from a binary relationship R between entity sets E and F :

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

I R is many-one from E to F :

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I R is one-one: key attributes of the relation are the key attributes of E or of F . I If the relationship R is multiway, we need to reason about the FDs that 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.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Keys in the Conversion from E/R to Relational Designs

I If the relation comes from an entity set, the key attributes of the relation are precisely the key attributes of the entity set. I If the relation comes from a binary relationship R between entity sets E and F :

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

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies key attributes of the relation are the key attributes of E or of F . I If the relationship R is multiway, we need to reason about the FDs that 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.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Keys in the Conversion from E/R to Relational Designs

I If the relation comes from an entity set, the key attributes of the relation are precisely the key attributes of the entity set. I If the relation comes from a binary relationship R between entity sets E and F :

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

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

I R is one-one:

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I If the relationship R is multiway, we need to reason about the FDs that 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.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Keys in the Conversion from E/R to Relational Designs

I If the relation comes from an entity set, the key attributes of the relation are precisely the key attributes of the entity set. I If the relation comes from a binary relationship R between entity sets E and F :

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

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

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies , we need to reason about the FDs that 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.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Keys in the Conversion from E/R to Relational Designs

I If the relation comes from an entity set, the key attributes of the relation are precisely the key attributes of the entity set. I If the relation comes from a binary relationship R between entity sets E and F :

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

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

I R is one-one: key attributes of the relation are the key attributes of E or of F . I If the relationship R is multiway

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Keys in the Conversion from E/R to Relational Designs

I If the relation comes from an entity set, the key attributes of the relation are precisely the key attributes of the entity set. I If the relation comes from a binary relationship R between entity sets E and F :

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

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

I R is one-one: key attributes of the relation are the key attributes of E or of F . I If the relationship R is multiway, we need to reason about the FDs that 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 19, 21 2009 CS 4604: Functional Dependencies I Example: A relation R with attributes A, B, and C, satisfies the FDs A → 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.

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 relational designs.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies A → C.

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

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 relational designs.

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I What is the key for R? A, because A → B and A → C.

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 relational designs.

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies A, because A → B and A → C.

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 relational designs.

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

I What is the key for R?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 relational designs.

I Example: A relation R with attributes A, B, and C, satisfies the FDs A → 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 19, 21 2009 CS 4604: Functional Dependencies I Two sets of FDs S and T are equivalent if each FD in S follows from T and each FD in T follows from S.

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

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

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 that satisfies all the FDs in T also satisfies F .

I A → C follows from T = {A → B, B → C}.

I Does T follow from S?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I These notions are useful in deriving new FDs from a given set of FDs.

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 that satisfies 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 from T and each FD in T follows from S.

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 that satisfies 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 from T and each FD in T follows from S.

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

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 rule I Combining rule

I These rules work because all the FDs in S and T have identical left hand sides.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I For the relation Courses, is the FD Number DeptName → CourseName equivalent to the set of FDs {Number → CourseName, DeptName → CourseName}? NO!

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?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies NO!

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}?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 19, 21 2009 CS 4604: Functional Dependencies 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 is equivalent to the FD A1A2 ... An → C1C2 ... Ck , where the C’s are those B’s that are not A’s, i.e., {C1, C2,..., Ck } = {B1, B2,..., Bm} − {A1, A2,..., An}.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Triviality of FDs

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 is equivalent to the FD A1A2 ... An → C1C2 ... Ck , where the C’s are those B’s that are not A’s, i.e., {C1, C2,..., Ck } = {B1, B2,..., Bm} − {A1, A2,..., An}.

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,

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 is equivalent to the FD A1A2 ... An → C1C2 ... Ck , where the C’s are those B’s that are not A’s, i.e., {C1, C2,..., Ck } = {B1, B2,..., Bm} − {A1, A2,..., An}.

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}.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 is equivalent to the FD A1A2 ... An → C1C2 ... Ck , where the C’s are those B’s that are not A’s, i.e., {C1, C2,..., Ck } = {B1, B2,..., Bm} − {A1, A2,..., An}.

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,

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 is equivalent to the FD A1A2 ... An → C1C2 ... Ck , where the C’s are those B’s that are not A’s, i.e., {C1, C2,..., Ck } = {B1, B2,..., Bm} − {A1, A2,..., An}.

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 ∅.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 is equivalent to the FD A1A2 ... An → C1C2 ... Ck , where the C’s are those B’s that are not A’s, i.e., {C1, C2,..., Ck } = {B1, B2,..., Bm} − {A1, A2,..., An}.

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,

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 is equivalent to the FD A1A2 ... An → C1C2 ... Ck , where the C’s are those B’s that are not A’s, i.e., {C1, C2,..., Ck } = {B1, B2,..., Bm} − {A1, A2,..., An}.

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} = ∅.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I Trivial dependency rule: The FD A1A2 ... An → B1B2 ... Bm is equivalent to the FD A1A2 ... An → C1C2 ... Ck , where the C’s are those B’s that are not A’s, i.e., {C1, C2,..., Ck } = {B1, B2,..., Bm} − {A1, A2,..., An}.

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.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 is equivalent to the FD A1A2 ... An → C1C2 ... Ck , where the C’s are those B’s that are not A’s, i.e., {C1, C2,..., Ck } = {B1, B2,..., Bm} − {A1, A2,..., An}.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 → ADD → E, CF → B Given these FDs,

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 → ADD → 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.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 → ADD → 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?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 → ADD → 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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 → ADD → 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?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 → ADD → 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 .

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I {B, C, F } is a superkey.

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 → ADD → 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.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies superkey.

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 → ADD → 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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 → ADD → 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 19, 21 2009 CS 4604: Functional Dependencies + I Which attributes must {A1, A2,..., An} contain at a minimum? {A1, A2,..., An}. Why? A1A2 ... An → Ai is a trivial FD.

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, the FD A1A2 ... An → Bi follows from S. + I the closure is denoted by {A1, A2,..., An} .

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies {A1, A2,..., An}. Why? A1A2 ... An → Ai is a trivial FD.

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, the FD 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?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies A1A2 ... An → Ai is a trivial FD.

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, the FD 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?

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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, the FD 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 19, 21 2009 CS 4604: Functional Dependencies 1. Use the splitting rule so that each FD in S has one attribute on the right.

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 Chapter 3.2.5 of the textbook.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Closures of Attributes: Algorithm Given

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I Why does the algorithm compute the closure correctly? Read Chapter 3.2.5 of the textbook.

Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Closures of Attributes: Algorithm Given

I a set of attributes {A1, A2,..., An} and I 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 the right.

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.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies Basics of FDs Manipulating FDs Closures and Keys Minimal Bases Closures of Attributes: Algorithm Given

I a set of attributes {A1, A2,..., An} and I 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 the right.

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 Chapter 3.2.5 of the textbook.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies For example,

I Transitive rule: if A1A2 ... An → B1B2 ... Bm and B1B2 ... Bm → C1C2 ... Ck then A1A2 ... 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 relation R if and only if + I {X } is the set of all attributes of R and + I for no attribute A ∈ X is {X − {A}} the set of all attributes of R.

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.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 relation R if and only if + I {X } is the set of all attributes of R and + I for no attribute A ∈ X is {X − {A}} the set of all attributes of R.

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 and B1B2 ... Bm → C1C2 ... Ck then A1A2 ... An → C1C2 ... Ck .

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 relation R if and only if + I {X } is the set of all attributes of R and + I for no attribute A ∈ X is {X − {A}} the set of all attributes of R.

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 and B1B2 ... Bm → C1C2 ... Ck then A1A2 ... An → C1C2 ... Ck . I To prove this rule, simply check if + {C1, C2,..., Ck } ⊆{ A1, A2,..., An} .

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 3. Procedurally define keys. A set of attributes X is a key for a relation R if and only if + I {X } is the set of all attributes of R and + I for no attribute A ∈ X is {X − {A}} the set of all attributes of R.

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 and B1B2 ... Bm → C1C2 ... Ck then A1A2 ... 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.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies A set of attributes X is a key for a relation R if and only if + I {X } is the set of all attributes of R and + I for no attribute A ∈ X is {X − {A}} the set of all attributes of R.

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 and B1B2 ... Bm → C1C2 ... Ck then A1A2 ... 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.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 and B1B2 ... Bm → C1C2 ... Ck then A1A2 ... 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 relation R if and only if + I {X } is the set of all attributes of R and + I for no attribute A ∈ X is {X − {A}} the set of all attributes of R.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 19, 21 2009 CS 4604: Functional Dependencies + 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 of attributes.

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.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I Running time of the algorithm is exponential in the number of attributes.

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.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 of attributes.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies Reflexivity If {B1, B2,..., Bm} ⊆ {A1, A2,..., An}, then A1A2 ... Am → B1B2 ... Bm (Trivial FDs). Augmentation If A1A2 ... Am → B1B2 ... Bm, then A1A2 ... AmC1C2 ... Ck → B1B2 ... BmC1C2 ... Ck , for any set of attributes {C1, C2,..., Ck }. Transitivity If A1A2 ... An → B1B2 ... Bm and B1B2 ... Bm → C1C2 ... Ck then A1A2 ... An → C1C2 ... Ck .

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 from a given set of FDs.

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies Augmentation If A1A2 ... Am → B1B2 ... Bm, then A1A2 ... AmC1C2 ... Ck → B1B2 ... BmC1C2 ... Ck , for any set of attributes {C1, C2,..., Ck }. Transitivity If A1A2 ... An → B1B2 ... Bm and B1B2 ... Bm → C1C2 ... Ck then A1A2 ... An → C1C2 ... Ck .

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 from a given set of FDs.

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

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies Transitivity If A1A2 ... An → B1B2 ... Bm and B1B2 ... Bm → C1C2 ... Ck then A1A2 ... An → C1C2 ... Ck .

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 from a given set of FDs.

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

Reflexivity If {B1, B2,..., Bm} ⊆ {A1, A2,..., An}, then A1A2 ... Am → B1B2 ... Bm (Trivial FDs). Augmentation If A1A2 ... Am → B1B2 ... Bm, then A1A2 ... AmC1C2 ... Ck → B1B2 ... BmC1C2 ... Ck , for any set of attributes {C1, C2,..., Ck }.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 from a given set of FDs.

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

Reflexivity If {B1, B2,..., Bm} ⊆ {A1, A2,..., An}, then A1A2 ... Am → B1B2 ... Bm (Trivial FDs). Augmentation If A1A2 ... Am → B1B2 ... Bm, then A1A2 ... AmC1C2 ... Ck → B1B2 ... BmC1C2 ... Ck , for any set of attributes {C1, C2,..., Ck }. Transitivity If A1A2 ... An → B1B2 ... Bm and B1B2 ... Bm → C1C2 ... Ck then A1A2 ... An → C1C2 ... Ck .

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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, attributes separated by commas.

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

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I We will limit ourselves to bases in which each FD has only one attribute 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.

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 equivalent to S is called a basis of S.

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 equivalent to S is called a basis of S.

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 equivalent to S is called a basis of S.

I We will limit ourselves to bases in which each FD has only one attribute 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 19, 21 2009 CS 4604: Functional Dependencies 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.

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 functionally determines 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-trivial FDs)

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 functionally determines 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-trivial FDs)

I FDs:

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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.

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 functionally determines 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-trivial FDs)

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies I Minimal bases: {A → B, B → A, B → C, C → B}, {A → B, B → C, C → A}, and others.

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 functionally determines 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-trivial FDs)

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

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies {A → B, B → A, B → C, C → B}, {A → B, B → C, C → A}, and others.

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 functionally determines 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-trivial FDs)

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

I Minimal bases:

T. M. Murali October 19, 21 2009 CS 4604: Functional Dependencies 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 functionally determines 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-trivial FDs)

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 19, 21 2009 CS 4604: Functional Dependencies