CS457 Syllabus & Progress

## Heuristic 2 for finding keys

• Heuristic 2: Find all keys - find the necessary attributes first

• Problem:

Find all keys in the following relations:

 ``` R(A, B, C, D, E, F) ℉ = { A → BC BD → EF F → A } ```

• Heuristic

 Find the irreplaceable attributes An attribute is replaceable if it appears in the RHS of some functional dependency A key must include every irreplaceable attribute The base set is the set of all irreplaceable attributes Add other attributes to the base set until you have a key

• Example:

 ``` R(A, B, C, D, E, F) ℉ = { A → BC BD → EF F → A } ```

• Find the irreplaceable attributes

 ``` Irreplaceable: D ```

• The base set is the set of all irreplaceable attributes

 ``` Base set = { D } ```

• Add other attributes to the base set until you have a key

 ``` Add 1 attribute from: A, B, C, E, F +A: AD+ = ABCDEF ... key ! +B: BD+ = ABCDEF ... key ! +C: CD+ = CD +E: DE+ = DE +F: DF+ = ABCDEF ... key ! Conclusion: AD, BD, DF are keys Add 2 attributes (do NOT expand with a KNOWN key I.e.: Do NOT include A, B, F) ) Select 2 attributes from: C, E CDE+ = CDE Add 3 attributes (do NOT expand a KNOWN key I.e.: Do NOT include A, B, F) ) Select 3 attributes from: C, E Impossible - DONE. ```

• The keys of relation R are: