Closure concept
The following is a more scientific and standardized closure solution, where X and Y are subsets of the Property sets of relational R, and F is the function dependency set on R, for any property set B of R, once X → B, B must y, and for any property set Y1 that meets the preceding conditions of R, y must Y1, in this case, Y is the closure of attribute set X under function dependency set F and is recorded as X +.
The procedure for calculating the closure of property set X of relational R is as follows:
Step 1: set the final attribute set of the closure to Y and initialize y to X;
Step 2: Check that each function in F depends on A to B. If all the attributes in property set a are in Y, and some attributes in B are not in y, add it to y;
Step 3: Repeat Step 2 until no attribute can be added to property set Y. The final y is x +.
Example (1): the relational mode R (u, f) is set, where u = {A, B, C, D, E, I}, F = {A → D, AB → e, Bi → e, CD → I, e → C}, computing (AE) +
Solution: (1) make X = {AE}, x (0) = AE
(2) In F, find the function dependency of the subset of AE on the left that has not been used. The result is: A → D, E → C; so x (1) = x (0) DC = acde, obviously x (1) =x (0 ).
(3) In F, find the function dependency of the subset of acde on the left that has not been used. The result is: CD → I; So X (2) = x (1) I = acdei. Although X (2) =x (1), the left side of F that has not used function dependencies does not have a subset of X (2), so it does not need to be computed, that is, (AE) + = acdei.
To put it bluntly, a closure is a set of all attributes that are directly or indirectly derived from an attribute.
For example, F = {A-> B, B-> C, A-> D, E-> f}; A can directly obtain B and D, and indirectly obtain c, then the closure of a is {a, B, c, d}
Theory andAlgorithm
For the given relationship R (A1, A2 ,... An) and function dependency set F, which can be divided into four categories:
The class only appears in the attribute on the left of the function dependency.
The r class only appears in the right part of the function dependency.
Attributes of class n that do not appear on both sides of function dependency.
Attributes of the LR class on both sides of the function dependency.
Theorem: for a given relational model R and its function dependency set F,If X (xε R) is an L-class attribute, X must be a member of any candidate code of R.
Inference: for a given relational model R and its function dependency set F,If X (xε R) is an L-class attribute and x + contains all the attributes of R, X must be the unique candidate code of R.
Example (2): The relational mode R (A, B, C, D) is set, and its function dependency set f = {D → B, B → D, AD → B, AC → D}, calculate all candidate codes of R.
Solution: F found that the attributes A and C are class L, so AC must be a candidate code member of R, and because (AC) + = ABCD, therefore, AC is the only candidate code of R.
Theorem: for a given relational model R and its function dependency set F,If X (xε R) is an R class attribute, X is not in any candidate code.
Theorem: for a given relational model R and its function dependency set F,If X (xε R) is a class n attribute, X is included in any candidate code of R.
Inference: for a given relational model R and its function dependency set F,If X (xε R) is an attribute set composed of class L and Class N, and x + contains all attributes of R, X is the unique candidate code of R.