Armstrong - CompleteSound

advertisement
CS 319: Theory of Databases: C3
Dr. Alexandra I. Cristea
http://www.dcs.warwick.ac.uk/~acristea/
(provisionary) Content
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Generalities DB
Integrity constraints (FD revisited)
Relational Algebra (revisited)
Query optimisation
Tuple calculus
Domain calculus
Query equivalence
LLJ, DP and applications
Temporal Data
The Askew Wall
2
… previous
Proving with Armstrong axioms
(non)Redundancy of FDs
3
FD Part 3
• Soundness and Completeness of
Armstrong’s axioms
4
Armstrong’s Axioms:
Sound & Complete
Ingredients:
• Functional Dependency (reminder)
– Definition
– Inference rules
– Closure of F : F+
F+: Set of all FDs obtained by applying inferences rules on a basic set
of FDs
– Issues and resolutions
• Armstrong’s Axioms (reminder)
– 3 inferences rules for obtaining the closure of F
– Properties of the Armstrong’s Axioms
They are a sound an complete set of inference rules
• Proof of the completeness
5
Functional Dependency
- A functional dependency (FD) has the form X  Y
where X and Y are sets of attributes in a relation R
X  Y if and only if:
for any instance r of R
for any tuples t1 and t2 of r
t1(X) = t2(X)  t1(Y) = t2(Y)
X  Y iff any two tuples that agree on X value also agree on Y value
6
Inference of Functional
Dependencies
• Suppose R is a relation scheme, and F is a set of functional
dependencies for R
• If X, Y are subsets of attributes of Attr(R) and if all instances r of
R which satisfy the FDs in F also satisfy X  Y, then we say
that F entails (logically implies) X  Y, written F |- X  Y
• In other words:
there is no instance r of R that does not satisfy X  Y
• Example
if F = { A  B, B  C } then F |- A  C
if F = { S  A, SI  P } then
F |- S I  AP, F |- SP  SAP etc.
A
B
I
S
P
A
C
7
Functional Dependency
• Issue:
– How to represent set of ALL FD’s for a relation R?
• Solution
– Find a basic set of FD’s ((canonical) cover)
– Use axioms for inferring
– Represent the set of all FD’s as the set of FD’s that can be
inferred from a basic set of FD’s
• Axioms
– they must be a sound and complete set of inference rules
8
Set of Functional Dependencies F*
• Formal Definition of F*, the cover of F:
if F is a set of FD’s, then F* { X  Y  F ├ X  Y }
• Informal Definitions
– F* is the set of all FD’s logically implied by F
(entailed)
• ... usually F* is much too large even to
enumerate!
9
F*
• Usually F* is much too large even to
enumerate!
• Example (3 attributes, 2 FD’s and 43 entailed
dependencies)
A
Attr(R)=ABC and F ={ A  B, B  C } then F* is
A  S for all [subset of ABC]
B  BC, B  B, B  C, B  
C  C, C  ,   
AB  S for all subsets S of ABC
AC  S for all subsets S of ABC
BC  BC, BC  B, BC  C, BC  
ABC  S for all subsets S of ABC
B
C
8 FDs
4 FDs
3 FDs
8 FDs
8 FDs
4 FDs
8 FDs
10
Armstrong’s Axioms
• Axioms for reasoning about FD’s
F1: reflexivity
if Y  X then X  Y
F2: augmentation
if X  Y then XZ  YZ
F3: transitivity
if X  Y and Y  Z then X  Z
11
+
F
• Informal Definition
F + (the closure of F) is the set of dependencies which can
be deduced from F by applying Armstrong’s axioms
• Formal Definition
if F is a set of FD’s, then F+ { X  Y F |= X  Y }
12
Armstrong’s Axioms
Theorem:
Armstrong’s axioms are a sound and complete
set of inference rules
– Sound: all Armstrong axioms are valid (correct / hold)
– Complete: all fds that are entailed can be deduced with
the help of the Armstrong axioms
• How to:
– Prove the soundness?
13
Armstrong’s Axioms
• Theorem: Armstrong’s axioms are a sound
and complete set of inference rules
– Sound: the Armstrong’s rules generate only FDs in
F*
F+  F*
– Complete: the Armstrong’s rules generate all FDs
in F*
F*  F +
– If complete and sound then F+ = F*
• Here
– Proof of the completeness
14
For the proof, we can use:
Armstrong’s Theorems
• Additional rules derived from axioms
– Union
if A  B and A  C, then A  BC
A
– Decomposition
if A BC, then A  B and A  C
B
C
B
A
C
15
Completeness of the
Armstrong’s Axioms
• Proving that Armstrong’s axioms are a
complete set of inference rules
Armstrong’s axioms generate all FDs in F*
F*  F +
16
Completeness of the
Armstrong’s Axioms
• First define X+, the closure of X with respect to F:
X+ is the set of attributes A such that X  A can be deduced
from F with Armstrong’s axioms
• Note that we can deduce that X  Y for some set Y by
applying Armstrong’s axioms if and only if Y  X+
Example:
Attr(R)=LMNO
X=L
F={L  M , M  N, O  N}
then X+ = L+ = LMN
L
M
N
O
17
XY
+
F <=> Y  X+
• Proof: We can deduce that X  Y for some set Y by applying
Armstrong’s axioms if and only if Y  X+
Y  X+  X  Y  F+
• Y  X+ and suppose that A Y then X  A  F+ (definition of X+)
•  A Y: X  A  F+
• X  Y  F+ (union rule)
X  Y  F+  Y  X+
• X  Y  F+ and suppose that A Y then X  A  F+
(decomposition rule)
• A  X+ (definition of X+)
•  A Y: A  X+
• Y  X+
18
Completeness (F*  F +) of the
Armstrong’s Axioms
•
Completeness:
(R,  X,Y Attr(R), F true in R : : X  Y  F* => X  Y  F +)
•
Idea: (A => B) ≡ (A v B) ≡ (B v A) ≡ (B =>A)
To establish completeness, it is sufficient to show:
if X  Y cannot be deduced from F using Armstrong’s axioms then also X  Y is not
logically implied by F:
(R,  X,Y Attr(R), F true in R : : X  Y  F+ => X  Y  F*)
X  Y  F* enough:
(In other words) there is a relational instance r in R (rR) in which all the
dependencies in F are true, but X  Y does not hold
Counter example!!
19
Completeness of the
Armstrong’s Axioms
• Example for the proof idea for a given R, F, X:
If X  Y cannot be deduced using Armstrong’s axioms: then there
is a relational instance for R in which all the dependencies in F are
true, but X  Y does not hold
R=LMNO
X=L
F={L  M , M  N, O  N}
then X+ = LMN
Counter example:
L
M
O
N
L  O cannot be
deduced (so not in F+)
but also does not hold
(not in F*)
20
What we want to prove thus:
(R,  X,Y Attr(R), F true in R : : X  Y  F+ => X  Y  F*)
(In other words) Counterexample
– by construction:
– for any R, any X, Y, any F true in R,
– with X->Y not inferable from the axioms
– there is a relational instance r in R (rR)
– in which all the dependencies in F are true
(F true in R ),
– but X  Y does not hold
21
Completeness of the
Armstrong’s Axioms
• Suppose one can not deduce X  Y from Armstrong’s
axioms for an arbitrary R, F, X,Y; construct counter-ex.
• Consider the instance r0 for R with 2 tuples
Relational instance r0 for R with 2 tuples
Attributes of
X+
Other
Attributes
11…1
1 1 …. 1
Example:
L+ = LMN
L
M
N
O
11…1
1
1
1
1
00…0
1
1
1
0
R=LMNO
X=L
then X+ = L+
L  O cannot
be deduced
(assuming Boolean attributes, or more generally, that the two
tuples agree on X+ but disagree elsewhere)
22
Completeness of the
Armstrong’s Axioms
• Check that all the dependencies in F are true in R:
– Suppose that V  W is a dependency in F
• If V is not a subset of X+, the dependency holds in r0
• If V is a subset of X+, then both X  V, and then X  W can be
deduced by Armstrong’s axioms. This means that W is a
subset of X+, and thus V  W holds in r0
Relational instance r0 for R with 2 tuples
Attributes of X+
Other Attributes
11…1
11…1
1 1 …. 1
00…0
23
Completeness of the
Armstrong’s Axioms
• Check that all the dependencies in F are true
– Extended Example (more tuples)
• O  N is a dependency in F but O is not a subset of X+,
the dependency holds in r0
• M  N is a dependency in F and M is a subset of X+,
then both L  M, and L  N can be deduced by
Armstrong’s axioms. This means that N is a subset of
X+, and thus M  N holds in r0
R=LMNO
X=L
24
F={L  M , M  N, O  N}
then X+ = LMN
Completeness of the
Armstrong’s Axioms
(R,  X,Y Attr(R), F true in R : : X -> Y  F+ => X -> Y  F*)
• Proof that X  Y does not hold in r0:
– Recall that we can deduce that X  Y for some set Y by
applying Armstrong’s axioms if and only if Y  X+
– By assumption, we can’t deduce that X  Y holds in r0
– Hence Y contains (at least) an attribute not in the subset X+,
confirming that X  Y does not hold in r0
Relational instance r0 for R with 2 tuples
Attributes of
X+
Other
Attributes
11…1
11…1
1 1 …. 1
00…0
25
Completeness of the
Armstrong’s Axioms
• We have proved the correctness (last module)
and here, the completeness of Armstrong’s
Axioms:
– How can we prove the completeness of another
set of rules?
• Repeat the proof for this set
• Deduce the Armstrong’s Axioms from this set
– How can we disprove the completeness of another
set of rules?
• By showing (via a counterexample) that some
consequence of Armstrong's rules cannot be deduced
from them (see the proof technique for non-redundancy)
26
Completeness of the
Armstrong’s Axioms
• Exercise
– Are the following set of rules a sound and complete set of
inference rules? (X, Y, Z, W  R)
S1: X  X
S2: if X  Y then XZ  Y
S3: if X  Y, Y  Z then XW  ZW
(This is a typical exam question )
27
Solution (soundness)
XX
if X  Y
Y  YZ
so by F1
then by F2
S1
X Y
XZ  Y
S2
X  Y ,Y  Z
XW  ZW
S3
XZ  YZ
so by F1
YZ  Y
XZ  YZ , YZ  Y so by F3
XZ  Y
if X  Y , Y  Z then by F3
so by F2
XX
X Z
XW  ZW
28
Solution (completeness)
if Y  X then
Z :: YZ  X so {S1} Y  Y,
{S2}YZ  Y
if X  Y then {S1} X  X, X  Y, so
{S3} XZ  YZ
if X  Y , Y  Z
  Z 0

then {S3} X  0
hence X  Y
X Y
XZ  YZ
A2
X  Y ,Y  Z
X Z
A3
hence
hence
A1
29
Completeness of the
Armstrong’s Axioms
• Exercises
– Are the following set of rules a complete set of inference rules?
R1: X  X
R2: X  Y then XZ  Y
R3: X  Y, Y  Z then X  Z
Ø
A
Ø A
1
1
1
1
B AB
1
1
1
1
1
1
Suppose
Att( R)  {A, B}, F  {0  A}
Apply above rules exhaustively
B  AB obtained from F1-3
but not from R1-3
Hence: answer is NO
B
AB
1
30
Summary
• We have learned how to prove that the
Armstrong axiom set is complete (and
we already knew it is sound)
• We can now prove the soundness and
completeness of any other set of
axioms
31
• Extra Question:
– Can we have a sound and complete set of
inference rules consisting of only 2 rules?
– What about 1 rule?
32
… to follow
Dependency preserving, Lossless join,
Normal forms algorithms
33
Download