Canonical Cover

3.5


Whenever a user updates the database, the system must check whether any of the functional dependencies are getting violated in this process. If there is a violation of dependencies in the new database state, the system must roll back. Working with a huge set of functional dependencies can cause unnecessary added computational time. This is where the canonical cover comes into play.
A canonical cover of a set of functional dependencies F is a simplified set of functional dependencies that has the same closure as the original set F.

Important definitions:

Extraneous attributes: An attribute of a functional dependency is said to be extraneous if we can remove it without changing the closure of the set of functional dependencies.
Canonical cover: A canonical cover F_{c} of a set of functional dependencies F such that ALL the following properties are satisfied:

  • F logically implies all dependencies in F_{c}.
  • F_{c} logically implies all dependencies in F.
  • No functional dependency in F_{c} contains an extraneous attribute.
  • Each left side of a functional dependency in F_{c} is unique. That is, there are no two dependencies \alpha_{1} \rightarrow \beta_{1} and \alpha_{2} \rightarrow \beta_{2} in such that \alpha_{1} \rightarrow \alpha_{2}.

Finding Canonical Cover

Algorithm to compute canonical cover of set F:

repeat
    1. Use the union rule to replace any dependencies in 
       \alpha_{1} \rightarrow \beta_{1} and \alpha_{1} \rightarrow \beta_{2} with \alpha_{1} \rightarrow \beta_{1}\beta_{2}.
    2. Find a functional dependency \alpha \rightarrow \beta with an 
       extraneous attribute either in \alpha or in \beta.
    3. If an extraneous attribute is found, delete it from \alpha \rightarrow \beta.
       until F does not change

Example1:

Consider the following set F of functional dependencies:

F= {
A \rightarrow BC
B \rightarrow C
A \rightarrow B
AB \rightarrow C
}

Steps to find canonical cover:

  1. There are two functional dependencies with the same set of attributes on the left:
    A \rightarrow BC
    A \rightarrow B

    These two can be combined to get
    A \rightarrow BC.

    Now, the revised set F becomes:

    F= {
    A \rightarrow BC
    B \rightarrow C
    AB \rightarrow C
    }

  2. There is an extraneous attribute in AB \rightarrow C because even after removing AB \rightarrow C from the set F, we get the same closures. This is because B \rightarrow C is already a part of F.

    Now, the revised set F becomes:

    F= {
    A \rightarrow BC
    B \rightarrow C
    }

  3. C is an extraneous attribute in A \rightarrow BC, also A \rightarrow B is logically implied by A \rightarrow B and B \rightarrow C (by transitivity).

    F= {
    A \rightarrow B
    B \rightarrow C
    }

  4. After this step, F does not change anymore. So,
    Hence the required canonical cover is,
    F_{c}= {
    A \rightarrow B
    B \rightarrow C
    }

Example2:

Consider another set F of functional dependencies:

F={
A \rightarrow BC
CD \rightarrow E
B \rightarrow D
E \rightarrow A
}

  1. The left side of each functional dependency in F is unique.
  2. None of the attributes in the left or right side of any functional dependency is extraneous (Checked by applying definition of extraneous attributes on every functional dependency).
  3. Hence, the canonical cover F_{c} is equal to F.

Note: There can be more than one canonical cover F_{c} of a set F of functional dependencies.

How to check whether a set of f.d.’s F canonically cover another set of f.d.’s G?

Consider the following two sets of functional dependencies:

F = {
A \rightarrow B
AB \rightarrow C
D \rightarrow AC
D \rightarrow E
}

G = {
D \rightarrow BC
D \rightarrow AB
}

Now, we are required to find out whether one of these f.d.’s canonically covers the other set of f.d.’s. This means, we need to find out whether F canonically covers G, G canonically covers F, or none of the two canonically cover the other.

To find out, we follow the following steps:

  • Create a singleton right hand side. This means, the attributes to the right side of the f.d. arrow should all be singleton.
    The functional dependency D \rightarrow AC gets broken down into two functional dependencies, D \rightarrow A and D \rightarrow C.

    F = {
    A \rightarrow B
    AB \rightarrow C
    D \rightarrow A
    D \rightarrow C
    D \rightarrow E
    }

  • Remove all extraneous attributes.

    Consider any functional dependency XY \rightarrow Z. If X in itself can determine Z, then the attribute Y is extraneous and can be removed. As we can see, the occurrence of extraneous attributes is possible only in those functional dependencies where there are more than one attributes in the LHS.

    So, consider the functional dependency AB \rightarrow C.
    Now, we must find the closures of A and B to find whether any of these is extraneous.

    [A]^{+}=AB[/Tex]
    [B]^{+}=B[/Tex]

    As we can see, B can be determined from A. This means we can remove B from the functional dependency AB \rightarrow C.

    F = {
    A \rightarrow B
    A \rightarrow C
    D \rightarrow A
    D \rightarrow C
    D \rightarrow E
    }

  • Remove all redundant functional dependencies.

    Check all f.d.’s one by one, and see if by removing a f.d. X \rightarrow Y, we can still find out Y from X by some other f.d. A more formal way to state this is find [X]^{+} without making use of the f.d. we are testing and check whether Y is a part of the closure. If yes, then the f.d. is redundant.

    Here, when checking for the f.d. D \rightarrow C, we observe that even after hiding it, the closure of D contains C. This is because we can obtain C from D by the combination of two other f.d.’s D \rightarrow A and A \rightarrow C. So, \rightarrow C is redundant.

    F = {
    A \rightarrow B
    A \rightarrow C
    D \rightarrow A
    D \rightarrow E
    }

Now, do the same for G.

  • Create a singleton right hand side. This means, the attributes to the right side of the f.d. arrow should all be singleton.

    G = {
    A \rightarrow B
    A \rightarrow C
    D \rightarrow A
    D \rightarrow B
    }

  • Remove all extraneous attributes.
    Since the RHS of all f.d.’s contains only 1 attribute, there is no extraneous attribute possible.

  • Remove all redundant functional dependencies.

    By looping over all f.d.’s and checking the closure of the LHS in all cases, we observe that the f.d. D \rightarrow B is redundant as it can be obtained through a combination of 2 other f.d.’s, D \rightarrow A and A \rightarrow B.

    G = {
    A \rightarrow B
    A \rightarrow C
    D \rightarrow A
    }

Now, since all f.d.’s of G are already covered in F, we conclude that F covers G.

This article is contributed by Anannya Uberoi. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

GATE CS Corner    Company Wise Coding Practice

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

Recommended Posts:



3.5 Average Difficulty : 3.5/5.0
Based on 19 vote(s)










Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.