[Database Principles] Relational Database Theory (2)

Functional dependency.

The interdependence and mutual restraint between the attributes in the relational model are called data dependence. Data dependence is divided into functional dependence and multi-value dependence, among which functional dependence is the most important.

Function Dependency (FD) is a logical dependency between attributes in the relational model.

For example, in the SCD table in relational database theory (1), there is a logical dependency between [SNo] and [SN, Age, Dept]. When an SNo is determined, the corresponding student is determined, his name SN, age, and department Dept are all determined. This is similar to the function definition y=f(x) in mathematics. X can uniquely determine the value of y. For the same x value, there will be no multiple y values ​​corresponding to it. Now the independent variable is [SNo] and the dependent variable is [SN, Age, Dept], we say that the value of SNo uniquely determines the value of the function (SN, Age, Dept). The formal definition of functional dependency is as follows:
Insert picture description here
The following points about functional dependency need to be explained:

  • [Trivial functional dependence] In the definition, if the attribute set Y is a subset of the attribute set X, there must be functional dependence X→Y, and such functional dependence is called trivial functional dependence. Correspondingly, if Y is not a subset of X, it is a non-trivial functional dependency. The former has no practical meaning, so we are discussing non-trivial functional dependencies. Only it is related to the integrity constraint.
  • [Semantic category] It should be noted that functional dependency is a concept of semantic category. It cannot be formalized to prove whether a functional dependency is established. It is essentially an assertion about things in the real world and their relevance. . For example, in the student relationship table S, if we think that students will not have the same name, we can get the functional dependencies of SN→Age and SN→Dept, but such functional dependencies are only established when there is no student with the same name.
  • [Relation type] Functional dependency is related to the type of connection between attributes. If X and Y have a 1:1 connection, then X→Y and Y→X exist; if X and Y have an m:1 connection, only There is a functional dependency X→Y. For example, SNo and Age have a many-to-one relationship, so there is SNo→Age; if X and Y are m:n, then there is no functional dependency between X and Y.
  • [About the definition] In the definition: it Insert picture description here
    means that for any two tuples of r t 1 t_1t1And t 2 t_2t2, As long as t 1 [X] = t 2 [X] t_1[X]=t_2[X]t1[X]=t2[ X ], 就有t 1 [Y] = t 2 [Y] t_1 [Y] = t_2 [Y]t1[ And ]=t2[ And ]

Logical implications.

Assuming that the relational pattern R(X,Y,Z) is known, and there are functional dependencies X→Y, Y→Z, ask whether there is X→Z? Can the functional dependency XY→YZ be obtained from the known functional dependencies?
Similar to the above, judging whether some functional dependencies are established from a set of known functional dependencies or whether the latter functional dependencies can be deduced from the previously known functional dependencies is what the logic implies.
Insert picture description here
In short, if X→Y can be derived from F, it is said that F logic implies X→Y.

Inference rules for functional dependencies.

In the part of logical implication, we are aware of the necessity of some inference rules. From the known functional dependencies, we need to know which functional dependencies can be derived. The inference rules of functional dependencies first appeared in the 1974 WWArmstrong paper.
The symbols in the introduction of all the rules are explained as follows: there is a relational mode R(U), U is the attribute set of the relational mode R, and F is a functional dependency set established on R and only involves the attributes in U. X, Y, Z, and W are all subsets of U, and r is an instance of R.

Armstrong axiom.

[①Reflexivity]
Insert picture description here
Proof: Because Y is a subset of X, if two tuples in r have equal values ​​on X, then their values ​​on Y must also be equal.

[② Augmentation Law]
Insert picture description here
Prove: If the assumption is under the conditions, the conclusion does not hold, that is to say when t 1 [XZ] = t 2 [XZ] t_1[XZ]=t_2[XZ]t1[XZ]=t2[XZ]时,有 t 1 [ Y Z ] ≠ t 2 [ Y Z ] t_1[YZ]≠t_2[YZ] t1[YZ]=t2[ Y Z ] , that is,t 1 [Y] ≠ t 2 [Y] t_1[Y]≠t_2[Y]t1[ And ]=t2[Y] t 1 [ Z ] ≠ t 2 [ Z ] t_1[Z]≠t_2[Z] t1[ Z ]=t2[ Z ] . The former case is in contradiction with the law of reflexivity, the latter case is with the conditiont 1 [XZ] = t 2 [XZ] t_1[XZ]=t_2[XZ]t1[XZ]=t2[ X Z ] contradictory, so the hypothesis does not hold, that is, the augmenting law is correct.

[③Transitivity]
Insert picture description here
Prove: assuming this condition, the conclusion does not hold, that is, t 1 [X] = t 2 [X] t_1[X]=t_2[X]t1[X]=t2When [ X ] ,t 1 [Z] ≠ t 2 [Z] t_1[Z]≠t_2[Z]t1[ Z ]=t2[ Z ] . Under this assumption,t 1 t_1t1And t 2 t_2t2There are only two situations on attribute set Y: t 1 [Y] = / ≠ t 2 [Y] t_1[Y]=/≠t_2[Y]t1[ And ]=/=t2[ Y ] , if it is equal, it contradicts Y→Z; otherwise, it contradicts X→Y, so the hypothesis does not hold, so the transfer law is correct.

Armstrong Axiom Corollary.

[① Merger Law Union]
Insert picture description here
Prove: Given X→Y, add X on both sides of the augmenting law to get XX→XY, and similarly X→Z to get XY→YZ, and then according to the transfer law, get XX→YZ, that is X →YZ.

【②Pseudotransitivity】
Insert picture description here
Prove: Given X→Y, add W on both sides of the augmenting law to get XW→YW, and then according to the transmission law, get XW→Z.

[③Decomposition law Decomposition]
Insert picture description here
Prove: According to the reflexive law, Y→Z, and then according to the transfer law X→Z.
With the decomposition law and the merger law, we have the following theorem:
Insert picture description here
[④Composition]
Insert picture description here
Proof: According to The augmenting law and X→Y get XW→YW, and the same goes for YW→YZ, and then according to the transfer law, XW→YZ.

Guess you like

Origin blog.csdn.net/weixin_44246009/article/details/108080272