0% found this document useful (0 votes)
225 views10 pages

Exercise08 Solution

This document contains an exercise sheet on functional dependencies for a course on Data Modelling and Databases. It includes multiple questions to practice identifying functional dependencies, candidate keys, closures, and decomposing relations. The questions cover concepts like determining functional dependencies and candidate keys for sample relations, finding closures of attributes, identifying whether statements about functional dependencies are true or false, finding a minimal basis for sets of functional dependencies, and decomposing a relation. The exercise sheet is intended as practice for an exam on these concepts of functional dependency theory and decomposition.

Uploaded by

Charles Colin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
225 views10 pages

Exercise08 Solution

This document contains an exercise sheet on functional dependencies for a course on Data Modelling and Databases. It includes multiple questions to practice identifying functional dependencies, candidate keys, closures, and decomposing relations. The questions cover concepts like determining functional dependencies and candidate keys for sample relations, finding closures of attributes, identifying whether statements about functional dependencies are true or false, finding a minimal basis for sets of functional dependencies, and decomposing a relation. The exercise sheet is intended as practice for an exam on these concepts of functional dependency theory and decomposition.

Uploaded by

Charles Colin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Data Modelling and Databases (DMDB) ETH Zurich

Spring Semester 2017 Systems Group


Lecturer(s): Gustavo Alonso, Ce Zhang Date: April 28, 2017
Assistant(s): Claude Barthels, Eleftherios Sidirourgos, Eliza Last update: August 16, 2017
Wszola, Ingo Müller, Kaan Kara, Renato Marroquín, Zsolt
István

Exercise 8: Functional Dependencies


Solution

The exercises marked with * will be discussed in the exercise session. You can solve the other
exercises as practice, ask questions about them in the session, and hand them in for feedback.
All exercises may be relevant for the exam.

Ask Ingo (ingo.mueller@inf.ethz.ch) for feedback on this week’s exercise sheet or give it
to the TA of your session (preferably stapled and with your e-mail address).

1 Functional Dependencies and Keys*


1.1 Order Relation
Consider the following relation:

Order (Product_Id, Product_Name, Customer_Id, Customer_Name, Order_Date,


Item_Price, Amount, VAT, Gross_Total, Net_Total)

Assumptions:
• The sales tax (VAT) value can vary from product to product (e.g. 8% for books, 16% for
luxury items).

• The gross total is the net total price plus the sales tax.
• Customer orders on the same day are combined. We only have one order per customer and
per day.
• Properties do not change over time – everything is “write-once”.
Data Modelling and Databases (DMDB), Spring Semester 2017, Exercise 8: Functional
Dependencies, April 28, 2017 Legi-Nr:

Questions:
1. Determine all functional dependencies of the relation Order.

Solution:

• P roduct_Id → P roduct_N ame, Item_P rice, V AT

• Customer_Id → Customer_N ame


• P roduct_Id, Customer_Id, Order_Date → Amount
• Item_P rice, Amount → N et_T otal
• N et_T otal, V AT → Gross_T otal

Note: If the product/customer names are unique, one could also consider the following
functional dependencies:

• P roduct_N ame → P roduct_Id

• Customer_N ame → Customer_Id

Note: Because of the correlation between Net_Total, VAT and Gross_Total, one could
also consider the following functional dependencies:

• Gross_T otal, V AT → N et_T otal

• Gross_T otal, N et_T otal → V AT

Note: Because of the correlation between Net_Total, Amount and Item_Price, one
could also consider the following functional dependencies:

• N et_T otal, Amount → Item_P rice


• N et_T otal, Item_P rice → Amount

Note: More functional dependencies are in the closure of the ones given above, but have
been omitted for sake of brevity.

2. Find all the candidate keys.

Solution:

• {P roduct_Id, Customer_Id, Date}

Note: If product/customer names are unique, we have the following additional key
candidates:
Data Modelling and Databases (DMDB), Spring Semester 2017, Exercise 8: Functional
Dependencies, April 28, 2017 Legi-Nr:

• {P roduct_Id, Customer_N ame, Date}


• {P roduct_N ame, Customer_N ame, Date}

• {P roduct_N ame, Customer_Id, Date}

1.2 Student – Lecture Relation


Consider the following database:

Student_Id Student_Address Lecture Teaching_Assisant


1234 Rämistrasse 72 Data Modelling and Databases Bob
1280 Rennweg 19 Concepts of Concurrent Computation Scott
1234 Rämistrasse 72 Visual Computing Sarah
1299 Börsenstrasse 42 Concepts of Concurrent Computation Benjamin
1356 Klusplatz 45 Concepts of Concurrent Computation Benjamin

Note:

• Assume that there is exactly one teaching assistant assigned to each student for every
course.
Questions:
1. Determine all functional dependencies of the relation above.

Solution:

• Student_Id → Address
• Student_Id, Course → T eaching_Assistant

Note: Formally, it is not possible to deduce functional dependencies from a database


as they must hold for all possible databases, not just the given one. In this exercise, the
sample database serves as illustration of the assumed world.

2. Give an example of a super key and a candidate key.

Solution:

• The set of all the attributes is a trivial super key.

• Student_Id, Course is a candidate (i.e., minimal) key.


Data Modelling and Databases (DMDB), Spring Semester 2017, Exercise 8: Functional
Dependencies, April 28, 2017 Legi-Nr:

1.3 Closures and Keys


Given a relation R (A,B,C,D,E,F,G) with the following five functional dependencies F :

(1) A → BC (2) E → CF (3) B → E (4) CD → EF (5) A → G

Questions:

1. Find the closure of A.

Solution:

• (6) A → B (because (1))


• (7) A → C (because (1))
• (8) A → E (transitive property (6) and (3))

• (9) A → CF (transitive property from (8) and (2))


• (10) A → G (because (5))

Therefore, {A}+ = {A, B, C, E, F, G}

2. Find a candidate key for R.

Solution: {A, D}

3. What is the closure of G?

Solution: {G}+ = {G}

1.4 Multiple Choice


Given a relation R (A,B,C,D,E,G) with the following eight functional dependencies F :

AB → C D → EG C→A BE → C
BC → D CG → BD ACD → B CE → AG

For the following statements, decide whether they are true or false. For false statements, explain
why you think that they are wrong.
Data Modelling and Databases (DMDB), Spring Semester 2017, Exercise 8: Functional
Dependencies, April 28, 2017 Legi-Nr:

Id Statement True False Explanation


1 The closure of BC is {A, D, E, G} X
2 All attributes of R are in the closure of BC. X
3 The closure of AC is {A, C} X
4 ABC is a super key of R X
5 ABC is a candidate key of R. X
6 BC is the only candidate key of R. X

Explanation:
1. The closure of BC includes the elements themselves. It is {A, B, C, D, E, G}.

2. From the previous question we know that the closure of BC is {A, B, C, D, E, G}.
3. C → A is the only functional dependency that can be used.
4. Since the closure of BC includes all elements, ABC is a super key.
5. ABC is not minimal, hence it is not a candidate key. BC is a candidate key.

6. There are other candidate keys, e.g., BD and CE.

2 Minimal Basis*
Find a minimal basis of the following sets of functional dependencies.

1. (1) A → BC (2) B → C (3) A → B (4) AB → C

Solution:

• Reduction of the left side: AB → C can be reduced to A → C because {C} ⊆


Closure(F, A) = (A), (AB), (ABC)

• Reduction of the right side: A → BC can be reduced to A → B because {C} ⊆


Closure(F \{A → BC} ∪ {A → B}, A) = (A), (AB), (ABC)
• We now have twice the same functional dependency (A → B). One can be removed.
• A → C can be reduced to A → because {C} ⊆ Closure(F \{A → C}, A) =
(A), (AB), (ABC)
• As minimal basis remains: {A → B, B → C}
Data Modelling and Databases (DMDB), Spring Semester 2017, Exercise 8: Functional
Dependencies, April 28, 2017 Legi-Nr:

2. (1) AB → C (2) C → A (3) BC → D (4) ACD → B


(5) BE → C (6) CE → F A (7) CF → BD (8) D → EF

Solution:

• Reduction of the left side: ACD → B can be reduced to CD → B because


{B} ⊆ Closure(F, CD) = (CD), (CDEF ), (CDEF B)
• Reduction of the right side: CD → B can be reduced to CD → because
{B} ⊆ Closure(F \{CD → B}, CD) = (CD), (CDEF ), (CDEF B)
• Reduction of the right side: CE → F A can be reduced to CE → F because
{A} ⊆ Closure(F \{CE → F A} ∪ {CE → F }, CE) = (CE), (CEF ), (CEF A)

• Reduction of the right side: CF → BD can be reduced to CF → B because


{D} ⊆ Closure(F \{CF → BD} ∪ {CF → B}, CF ) = (CF ), (CF B), (CF BD)
• As minimal basis remains:

AB → C, C → A, BC → D, BE → C,
CE → F , CF → B, D → EF

• An alternative solution would be to right-reduce CF → BD instead of CD → B

3 Decomposition*
3.1 Student – Lecture Relation
Consider the following relation S and its decomposition into S1 and S2 .

Relation Name Attributes


S Student_Id, Date_Enrolled, Course_Id, Room_Nr, Professor
S1 Student_Id, Date_Enrolled, Course_Id
S2 Date_Enrolled, Room_Nr, Professor

Note:
• Assume that each course is always taught only by the same professor and takes place in
the same room.

Questions:
1. Determine all functional dependencies of S.

Solution:

• Course_Id → Room_N r, P rof essor


Data Modelling and Databases (DMDB), Spring Semester 2017, Exercise 8: Functional
Dependencies, April 28, 2017 Legi-Nr:

• Student_Id, Course_Id → Date_Enrolled

Note: The functional dependencies of S also hold in S1 and S2 .

2. Why is the decomposition of S to S1 and S2 a lossy decomposition? Prove it formally.

Solution: The decomposition of S into S1 and S2 is lossless iff S = S1 ∪ S2 (which is


given) and S = S1 ./ S2 . We show by counter-example that the latter equality does not
hold. Let S contain the following tuples:

Stud’_Id Date_Enr’d Course_Id Room_Nr Professor


12345 2016-02-03 252-0063-00L CAB G 61 Alonso
54321 2016-02-03 252-0817-00L NULL Alonso, Mattern, Roscoe

Then S1 = ΠStudent_Id, Date_Enrolled, Course_Id (S) contains the following tu-


ples:

Stud’_Id Date_Enr’d Course_Id


12345 2016-02-03 252-0063-00L
54321 2016-02-03 252-0817-00L

S2 = ΠDate_Enrolled, Room_Nr, Professor (S) contains the following:

Date_Enrolled Room_Nr Professor


2016-02-03 CAB G 61 Alonso
2016-02-03 NULL Alonso, Mattern, Roscoe

and S1 ./ S2 contains the following:

Stud’_Id Date_Enr’d Course_Id Room_Nr Professor


12345 2016-02-03 252-0063-00L CAB G 61 Alonso
54321 2016-02-03 252-0063-00L CAB G 61 Alonso
12345 2016-02-03 252-0817-00L NULL Alonso, Mattern, Roscoe
54321 2016-02-03 252-0817-00L NULL Alonso, Mattern, Roscoe

This is different from S. 

Note: Using the decomposition lemma is not correct. Its condition, R1 ∩ R2 → Ri ,


i ∈ {1, 2}, is a sufficient condition, but not a nessecary one, i.e., the lemma says that
if the condition holds, then the decomposition is lossless, but it does not say anything
about the other direction.

3. Show a lossless decomposition of the same relation, and prove that it is lossless.
Data Modelling and Databases (DMDB), Spring Semester 2017, Exercise 8: Functional
Dependencies, April 28, 2017 Legi-Nr:

Solution: S can be decomposed into:

• S1 (Student_Id, Date_Enrolled, Course_Id)


• S2 (Course_Id, Room_N r, P rof essor)

S1 ∩ S2 = Course_Id and Course_Id → R2

3.2 Decomposition Lemma


Q Q
Given a relation R = R1 ∪ R2 and its decomposition into R1 = R1 (R) and R2 = R2 (R).
Assuming R1 ∩ R2 → R1 , prove that R = R1 ./ R2 .

Hints:
• Assume the elements of R1 and R2 have the forms (α, β) and (α, γ) with α = {A1 , ..., Ai },
β = {B1 , ..., Bj }, and γ = {C1 , ..., Ck }, respectively.
• First prove R ⊆ R1 ./ R2

• Next, prove R1 ./ R2 ⊆ R

Solution: For a, b, c instances of α, β, γ.

Direction 1: R ⊆ R1 ./ R2
Q Q
If (a, b, c) ∈ R ⇒ (a, b) ∈ R1 (R) = R1 and (a, c) ∈ R2 (R) = R2
⇒ (a, b, c) ∈ R1 ./ R2
Direction 2: R1 ./ R2 ⊆ R
If (a, b, c) ∈ R1 ./ R2 ⇒ (a, b) ∈ R1 and (a, c) ∈ Q
R2
⇒ (a, b, c0 ) ∈ R such that R1 Q
((a, b, c0 )) = (a, b),
and (a, b , c) ∈ R such that R2 ((a, b0 , c)) = (a, c)
0

α→β ⇒ b = b0
⇒ (a, b0 , c) = (a, b, c) ∈ R

4 Functional Dependencies and ER*


Consider the following ER model:
Data Modelling and Databases (DMDB), Spring Semester 2017, Exercise 8: Functional
Dependencies, April 28, 2017 Legi-Nr:

father mother
man woman
1 1

father 1 N son daughter N 1 mother

isSon isDaughter

1. Which functional dependencies are given by the model?

Solution:

mother, daughter → father


father, daughter → mother
mother, son → father
father, son → mother

2. Which additional functional dependencies would you add to represent the real world more
accurately?

Solution:

daughter → mother, father


son → mother, father

3. Determine the minimal basis of all functional dependencies (including the ones you added).

Solution: With the right-reduction rule, the right side of each functional dependency
of Part 1 can be made empty because it is already implied by a functional dependency of
Part 2. The reduced functional dependency can then be removed and only the following
remain:

daughter → mother, father


son → mother, father

4. Discuss what this means for the expressiveness of entity-relationship models.


Data Modelling and Databases (DMDB), Spring Semester 2017, Exercise 8: Functional
Dependencies, April 28, 2017 Legi-Nr:

Solution: As we have discussed in Exercise Sheets 1 and 2, ER cannot express every-


thing we might want to express. The functionalities in ER allow us to express some
contraints, but none fit the needs of the example in this exercise. However, we under-
stand better what the functionalities express: If an entity has a functionality of “1”, such
as “mother”, then this entity functionally depends on all other entities of the relation-
ship, e.g., “father, son → mother”. Futhermore, functional dependencies are a tool with
which we can express constraints that we could not have with ER, such as “daughter →
mother, father”.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy