Professional Documents
Culture Documents
Unctional Ependencies: CS 564-Fall 2020
Unctional Ependencies: CS 564-Fall 2020
• Functional Dependencies
• Armstrong’s rules
• The Closure Algorithm
• Keys and Superkeys
• Pick an application
• Figure out what to model (ER model)
– Output: ER diagram
• Transform the ER diagram to a relational schema
Problems:
• redundant storage
• update: change the age of Paris?
• insert: what if a person has no phone number?
• delete: what if Arun deletes his phone number?
• An FD is domain knowledge:
– an inherent property of the application & data
– not something we can infer from a set of tuples
Reflexivity
For any subset 𝑋 ⊆ 𝐴! , . . , 𝐴" :
𝐴! , 𝐴# , … , 𝐴" ⟶ 𝑋
• Examples
– 𝐴, 𝐵 ⟶ 𝐵
– 𝐴, 𝐵, 𝐶 ⟶ 𝐴, 𝐵
– 𝐴, 𝐵, 𝐶 ⟶ 𝐴, 𝐵, 𝐶
Augmentation
For any attribute sets X, Y, Z :
if 𝑋 ⟶ 𝑌 then 𝑋, 𝑍 ⟶ 𝑌, 𝑍
• Examples
– 𝐴 ⟶ 𝐵 implies 𝐴, 𝐶 ⟶ 𝐵, 𝐶
– 𝐴, 𝐵 ⟶ 𝐶 implies 𝐴, 𝐵, 𝐶 ⟶ 𝐶
Transitivity
For any attribute sets X, Y, Z :
if 𝑋 ⟶ 𝑌 and 𝑌 ⟶ 𝑍 then 𝑋 ⟶ 𝑍
• Examples
– 𝐴 ⟶ 𝐵 and 𝐵 ⟶ 𝐶 imply 𝐴 ⟶ 𝐶
– 𝐴 ⟶ 𝐶, 𝐷 and 𝐶, 𝐷 ⟶ 𝐸 imply 𝐴 ⟶ 𝐸
FD Closure
If F is a set of FDs, the closure 𝐹 3 is the set of
all FDs logically implied by F
Attribute Closure
If X is an attribute set, the closure 𝑋 3 is the
set of all attributes B such that:
𝑋 ⟶𝐵
Attribute Closure:
• {𝑛𝑎𝑚𝑒}% = {𝑛𝑎𝑚𝑒, 𝑐𝑜𝑙𝑜𝑟}
• 𝑛𝑎𝑚𝑒, 𝑐𝑎𝑡𝑒𝑔𝑜𝑟𝑦 % =
{𝑛𝑎𝑚𝑒, 𝑐𝑜𝑙𝑜𝑟, 𝑐𝑎𝑡𝑒𝑔𝑜𝑟𝑦, 𝑑𝑒𝑝𝑎𝑟𝑡𝑚𝑒𝑛𝑡, 𝑝𝑟𝑖𝑐𝑒}
R(A, B, C, D, E, F)
• 𝐴, 𝐵 ⟶ 𝐶
• 𝐴, 𝐷 ⟶ 𝐸
• 𝐵⟶𝐷
• 𝐴, 𝐹 ⟶ 𝐵
1. Does 𝑋 ⟶ 𝑌 hold?
– we can check if Y ⊆ 𝑋 3
2. To compute the closure 𝐹 3 of FDs
– for each subset of attributes X, compute 𝑋 3
– for each subset of attributes Y ⊆ 𝑋 3 , output the
FD 𝑋 ⟶ 𝑌
Superkeys:
• 𝑛𝑎𝑚𝑒, 𝑐𝑎𝑡𝑒𝑔𝑜𝑟𝑦 , 𝑛𝑎𝑚𝑒, 𝑐𝑎𝑡𝑒𝑔𝑜𝑟𝑦, 𝑝𝑟𝑖𝑐𝑒
𝑛𝑎𝑚𝑒, 𝑐𝑎𝑡𝑒𝑔𝑜𝑟𝑦, 𝑐𝑜𝑙𝑜𝑟 , {𝑛𝑎𝑚𝑒, 𝑐𝑎𝑡𝑒𝑔𝑜𝑟𝑦, 𝑝𝑟𝑖𝑐𝑒, 𝑐𝑜𝑙𝑜𝑟}
Keys:
• 𝑛𝑎𝑚𝑒, 𝑐𝑎𝑡𝑒𝑔𝑜𝑟𝑦
Example:
• 𝐴 ⟶ 𝐵
• 𝐴, 𝐵, 𝐶, 𝐷 ⟶ 𝐸
• 𝐸, 𝐹 ⟶ 𝐺, 𝐻
• 𝐴, 𝐶, 𝐷, 𝐹 ⟶ 𝐸, 𝐺
• 𝐴 ⟶ 𝐵
• 𝐴, 𝐵, 𝐶, 𝐷 ⟶ 𝐸
• 𝐸, 𝐹 ⟶ 𝐺
• 𝐸, 𝐹 ⟶ 𝐻
• 𝐴, 𝐶, 𝐷, 𝐹 ⟶ 𝐸
• 𝐴, 𝐶, 𝐷, 𝐹 ⟶ 𝐺
• 𝐴 ⟶ 𝐵
• 𝐴, 𝐵, 𝐶, 𝐷 ⟶ 𝐸
• 𝐸, 𝐹 ⟶ 𝐺 can be removed, since these
• 𝐸, 𝐹 ⟶ 𝐻 FDs are logically implied
by the remaining FDs
• 𝐴, 𝐶, 𝐷, 𝐹 ⟶ 𝐸
• 𝐴, 𝐶, 𝐷, 𝐹 ⟶ 𝐺
• 𝐴 ⟶ 𝐵
• 𝐴, 𝐵, 𝐶, 𝐷 ⟶ 𝐸
• 𝐸, 𝐹 ⟶ 𝐺 B can be safely removed
because of the first FD
• 𝐸, 𝐹 ⟶ 𝐻
• 𝐴 ⟶ 𝐵
• 𝐴, 𝐶, 𝐷 ⟶ 𝐸
• 𝐸, 𝐹 ⟶ 𝐺
• 𝐸, 𝐹 ⟶ 𝐻