20 db formal design
TRANSCRIPT
-
7/29/2019 20 DB Formal Design
1/13
Theory I: Database Foundations 20. Formal Design 20.
Theory I: Database Foundations
Jan-Georg Smaus (Georg Lausen)
2.8.2011
1. Formal DesignMotivationFunctional DependenciesDecomposition
Jan-Georg Smaus (Georg Lausen) 1
http://find/ -
7/29/2019 20 DB Formal Design
2/13
Theory I: Database Foundations 20. Formal Design 20.
Formal Design
We want to distinguish good from bad database design.
What kind of additional information do we need?
Can we transform a bad into a good design?
(At which cost?)
Jan-Georg Smaus (Georg Lausen) 2
http://find/ -
7/29/2019 20 DB Formal Design
3/13
Theory I: Database Foundations 20. Formal Design 20.1. Motivation
20.1 Motivation
Relations and anomalies
City
CityNo CityName CCode CSurface
7 Freiburg D 357
9 Berlin D 357
40 Moscow RU 17075
43 St.Petersburg RU 17075
Continent
ConName CCode ConSurface Percent
Europe D 3234 100
Europe RU 3234 20
Asia RU 44400 80
Jan-Georg Smaus (Georg Lausen) 3
http://find/ -
7/29/2019 20 DB Formal Design
4/13
Theory I: Database Foundations 20. Formal Design 20.1. Motivation
Having removed anomalies
City
CityNo CityName CCode
7 Freiburg D
9 Berlin D
40 Moscow RU
43 St.Petersburg RU
Country
CCode CSurface
D 357
RU 17075
Location
CCode ConName Percent
D Europe 100RU Europe 20
RU Asia 80
Continent
ConName ConSurface
Europe 3234Asia 44400
Jan-Georg Smaus (Georg Lausen) 4
http://find/ -
7/29/2019 20 DB Formal Design
5/13
Theory I: Database Foundations 20. Formal Design 20.2. Functional Dependencies
20.2 Functional Dependencies
Definition
Let a relation schema be given by its format X and let Y,Z X.
Let r Rel(X). r fulfills a functional dependency Y Z, if for all , r:
[Y] = [Y] [Z] = [Z].
Let F be a set of functional dependencies over X. The set of all relationsr Rel(X), which fulfill all functional dependencies in F, is calledSat(X, F).
Jan-Georg Smaus (Georg Lausen) 5
http://find/ -
7/29/2019 20 DB Formal Design
6/13
Theory I: Database Foundations 20. Formal Design 20.2. Functional Dependencies
20.2.2 Membership Test
The functional dependency Y Z, is implied by F, written F |= Y Z,
if for each relation r, whenever r Sat(X, F) then r fulfills Y Z.
The set F+ = {Y Z | F |= Y Z} is called closure of F.
The question Y Z F+? is called membership test.
Jan-Georg Smaus (Georg Lausen) 6
http://find/ -
7/29/2019 20 DB Formal Design
7/13
Theory I: Database Foundations 20. Formal Design 20.2. Functional Dependencies
Key
Let X = {A1, . . . ,An}. Y X is called key ofX (wrt. F), if
Y A1 . . .An F+
,Z Y Z A1 . . .An / F
+.
Jan-Georg Smaus (Georg Lausen) 7
Th I D t b F d ti 20 F l D i 20 2 F ti l D d i
http://find/ -
7/29/2019 20 DB Formal Design
8/13
Theory I: Database Foundations 20. Formal Design 20.2. Functional Dependencies
Armstrong axioms
Let r Sat(X, F).
(A1) Reflexivity: IfZ Y X, then r fulfills functional dependencyY Z.
(A2) Augmentation: IfY Z F, V X, then r fulfills functionaldependency YV ZV.
(A3) Transitivity: IfY Z,Z V F, then r fulfills functionaldependency Y V.
(A1): trivial functional dependencies.
Jan-Georg Smaus (Georg Lausen) 8
Theory I: Database Foundations 20 Formal Design 20 2 Functional Dependencies
http://find/ -
7/29/2019 20 DB Formal Design
9/13
Theory I: Database Foundations 20. Formal Design 20.2. Functional Dependencies
Correctness and Completeness
Every functional dependency derivable by the Armstrong axioms is anelement of the closure (correctness).
Every functional dependency in F+ is derivable by the Armstrong axioms(completeness)
Jan-Georg Smaus (Georg Lausen) 9
Theory I: Database Foundations 20 Formal Design 20 2 Functional Dependencies
http://find/ -
7/29/2019 20 DB Formal Design
10/13
Theory I: Database Foundations 20. Formal Design 20.2. Functional Dependencies
Membership test
Starting from F apply (A1)(A3) until Y Z is derived, or F+ is derived andY Z F+.
In practice this test is too complex and therefore other tests have beendeveloped.
Jan-Georg Smaus (Georg Lausen) 10
Theory I: Database Foundations 20 Formal Design 20 3 Decomposition
http://find/ -
7/29/2019 20 DB Formal Design
11/13
Theory I: Database Foundations 20. Formal Design 20.3. Decomposition
20.3 Decomposition
Let = {Y1, . . . ,Yk} a decomposition ofX, i.e., Y1 . . . Yk = X. Let F be aset of functional dependencies.
Let r Sat(X, F) and let ri = [Yi]r, 1 i k.
is called lossless, if for any r Sat(X, F) it holds that:
r = [Y1]r . . . [Yk]r.
Jan-Georg Smaus (Georg Lausen) 11
Theory I: Database Foundations 20. Formal Design 20.3. Decomposition
http://find/ -
7/29/2019 20 DB Formal Design
12/13
Theory I: Database Foundations 20. Formal Design 20.3. Decomposition
Example
X = {A, B, C} and F= {A B, A C}.
r Sat(X,F):
r =A B C
a1 b1 c1
a2 b1 c2
1 = {AB, BC} and 2 = {AB, AC}.
r [AB]r [BC]r,
r [AB]r [AC]r.
Jan-Georg Smaus (Georg Lausen) 12
Theory I: Database Foundations 20. Formal Design 20.3. Decomposition
http://find/ -
7/29/2019 20 DB Formal Design
13/13
y g p
TheoremLet a format X and set F of functional dependencies. Let = (Y1,Y2) be adecomposition ofX.
is lossless, iff
(Y1 Y2) (Y1 \ Y2) F+, or (Y1 Y2) (Y2 \ Y1) F+.
There is a similar notion called dependency-preserving.
The aim of good database design is to decompose relations to remove
redundancies.
Jan-Georg Smaus (Georg Lausen) 13
http://find/http://goback/