banner



How To Find The Closure Of A Set

Do you know what a closure of a set of attributes is? Practise y'all know how to find it? This knowledge is essential for database normalization. In this commodity, learn what a closure of a set up of attributes is and how to detect it with real-world examples.

Finding the closure of a ready of attributes is an important topic for relational databases. The closure of a set of attributes is taught in every university database form. And a common exam problem is, "Find the closure of this set of attributes given this set of functional dependencies."

functional dependencies

Finding the closure of a set of attributes is needed for problems related to normalization. For case, you lot need to know how to compute the closure of a ready of attributes to bank check if a gear up of attributes is a candidate key or a superkey. Yous besides need this algorithm to decompose non-normal tables into normal forms.

Closure of a Set of Attributes

The closure of a set up of attributes X is the set of those attributes that can be functionally determined from X. The closure of Ten is denoted as X+ .

When given a closure problem, you'll have a set of functional dependencies over which to compute the closure and the set X for which to detect the closure. A functional dependency A1, A2, …, An -> B in a table holds if ii records that take the same value of attributes A1, A2, …, An also take the aforementioned value for attribute B.

The closure of X is the set of all attributes such that two records that have the same value of Ten also take the same value of 10+.

Real-Earth Examples

Database courses ordinarily teach closures using abstruse examples, and nosotros'll look at some abstract examples later. However, permit's first look at a existent-world example, which is easier to empathise.

Imagine we have a table Form Editions. The table contains data about editions of courses taught at a certain university.

Each year, each course can be taught by a different instructor. And each teacher has a date of nascence. With the year and the appointment of birth, y'all can make up one's mind the age of the instructor at the time the course was taught.

(Note: This database is poorly designed. Don't base your databases on this. Nosotros are only using this example to illustrate the concept of attribute closures.)

Class Editions

form twelvemonth instructor date_of_birth age
Databases 2019 Chris Cape 1974-x-12 45
Mathematics 2019 Daniel Parr 1985-05-17 34
Databases 2020 Jennifer Clock 1990-06-09 30

Here are the functional dependencies in this tabular array:

  • class, twelvemonth -> teacher
    • Given the course and year, you can determine the teacher who taught the grade that year.
  • teacher -> date_of_birth
    • Given a instructor, you tin make up one's mind the teacher's date of nascency.
  • year, date_of_birth -> age
    • Given the yr and date of nascency, y'all can determine the age of the teacher at the fourth dimension the course was taught.

At present, let's look at some of the attribute closures.

First, consider the closure of a set {year}, denoted {twelvemonth}+. If I am given the year, what columns tin can I determine? I can for certain decide the twelvemonth. So, the cavalcade twelvemonth is an element of {yr}+.

Are there any other columns that I can determine? The first functional dependency course, year -> teacher requires the course in addition to the twelvemonth, then it doesn't add anything to {year}+. The functional dependency twelvemonth, date_of_birth -> age requires the date of birth in addition to the year, so information technology doesn't add together anything to {year}+ either.

Then, {twelvemonth}+ contains but one column, year, that is {year}+ = {yr}.

Next, permit's expect at {year, teacher}+. Given the yr and teacher, what other columns can nosotros determine? Well, equally before, the year and teacher are given, and then they are in {year, teacher}+.

If I know the instructor, I likewise know the appointment of nascency because of the teacher -> date_of_birth functional dependency. And then, date_of_birth is besides in {year, teacher}+, and I know three columns: {yr, instructor, date_of_birth}.

If I know the year and appointment of birth, I can as well make up one's mind the historic period. Now, {yr, teacher}+ has four columns {year, teacher, date_of_birth, age}.

I have used ii of the 3 functional dependencies. I tin can't use the remaining dependency, course, year -> teacher because I don't know the course. Now that I have used all of the dependencies I can, {year, teacher}+ = {twelvemonth, teacher, date_of_birth, age}.

The Algorithm

The process shown in the previous example can be generalized to an algorithm. Assume we are given the prepare of functional dependencies FD and a set of attributes 10. The algorithm is every bit follows:

  1. Add the attributes contained in the aspect gear up X to the result fix X+.
  2. Add together the attributes to the event gear up X+ which tin exist functionally determined from the attributes already contained in the result set.
  3. Echo step two until no more than attributes tin can be added to the result gear up 10+.

Abstract Examples

Allow'due south accept a look at some abstract examples. This is how the closure of a set of attributes would be presented in a class.

Example 1

We are given the relation R(A, B, C, D, E). This means that the table R has five columns: A, B, C, D, and E. Nosotros are also given the set of functional dependencies: {A->B, B->C, C->D, D->E}.

What is {A}+?

  • Outset, we add together A to {A}+.
  • What columns tin be determined given A? We have A -> B, so nosotros can determine B. Therefore, {A}+ is at present {A, B}.
  • What columns can be determined given A and B? We take B -> C in the functional dependencies, then we tin can determine C. Therefore, {A}+ is now {A, B, C}.
  • Now, we have A, B, and C. What other columns can we determine? Well, we have C -> D, and then nosotros can add D to {A}+.
  • Now, we take A, B, C, and D. Tin can nosotros add anything else to it? Yes, since D -> Eastward, we can add together E to {A}+.
  • We accept used all of the columns in R and we have all used all functional dependencies. {A}+ = {A, B, C, D, E}.

Example 2

Let's expect at another case. Nosotros are given R(A, B, C, D, East, F). The functional dependencies are {AB->C, BC->Advertisement, D->Eastward, CF->B}. What is {A, B}+?

  • We start with {A, B}.
  • What columns can nosotros determine, given A and B? We have AB -> C, and so nosotros can add together C to {A, B}+.
  • Nosotros at present have A, B, and C. What other columns can we determine? We have BC -> Ad. We already accept A in {A, B}+, so we tin add D.
  • And then, we now have A, B, C, and D. What else can nosotros add? We have D -> E, and so we can add together Due east to {A, B}+.
  • At present {A, B}+ is {A, B, C, D, Due east}. Tin we add anything else? No. Nosotros have one more functional dependency in our set that we did not use: CF -> B. We tin't use this dependency because F is not in {A, B}+.
  • Thus, {A, B}+ is {A, B, C, D, E}.

Learn More

If yous liked this commodity, check out other normalization articles on our blog.

If you lot're a pupil taking database classes, make sure to create a free Bookish account in Vertabelo, our online ER diagram cartoon tool. It allows you to describe logical and physical ER diagrams directly in your browser.

Vertabelo supports PostgreSQL, SQL Server, Oracle, MySQL, Google BigQuery, Amazon Redshift, and other relational databases. Try it out and run across how easy it is to get started!

Source: https://vertabelo.com/blog/closure-of-a-set-of-attributes/

Posted by: ewingamill1957.blogspot.com

0 Response to "How To Find The Closure Of A Set"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel