Functional dependencies and attribute closure

Trace a domain rule to its fixed-point closure, then tell a superkey from every inclusion-minimal candidate key. Dependencies and normal forms · Databases.

One room change forces you to edit yesterday's attendance rows. A new class cannot be recorded before its first student arrives. Remove the last attendance row and the class topic disappears too. The table is answering two different questions at once: what a class is, and who attended it. Let’s separate the rule from the sample and watch what follows.

A repeated fact needs a rule

Suppose class_attendance stores class_id, student_id, subject, room, and mark.

class_idstudent_idsubjectroommark
C17S4DBMSLab-2present
C17S9DBMSLab-2absent

The repeated subject and room are facts about class C17, copied once per student. That repetition creates the update, insert and delete symptoms from the hook. A separate class relation could own the class facts, while an attendance relation could own the student-specific mark.

For this lesson, we make two domain assumptions:

  • class_id -> subject, room: one class id names one subject and room in this timetable.
  • class_id, student_id -> mark: one student has one mark for one class.

A functional dependency (FD) has a determinant: the complete attribute set on the left of its arrow. In class_id, student_id -> mark, the determinant is class_id, student_id.

The arrows are semantic contracts. They do not mean that an id causes a room, and they are not inferred because two displayed rows happen to agree. A sample with the same class_id and two different rooms would refute the first assumption. A sample that agrees cannot prove it for every future legal row. The prerequisite lesson talked about declared keys and constraints; here we are reasoning from domain meaning.

Let the closure move

The first scene renames the same idea with compact symbols: A is class_id, B is student_id, C is subject, D is room, and E is mark. It also includes the timetable assumption C,D -> A: in this particular schedule, a subject-room pair identifies one class. That gives us a useful alternate candidate key to test, without asking the sample rows to establish the rule.

Start with {A, B}. Attribute closure starts with those attributes. Scan the displayed dependencies from top to bottom, and apply a dependency only when its full left side is already in the known set. Keep scanning until a complete pass adds nothing.

Closure: let the known set grow

Read the steps as text

  1. Start with seed A, B. Apply a dependency only when its left side is already known.
  2. A -> C,D adds C, D; the known set is now A, B, C, D.
  3. A,B -> E adds E; the known set is now A, B, C, D, E.
  4. No dependency adds another attribute. The fixed point is A, B, C, D, E.

At the fixed point, A,B,C,D,E is the full schema of A,B,C,D,E, and the candidate keys are A,B; B,C,D. Both keys are valid because each closes to the schema and neither has a removable attribute. A,B,D would still be a superkey, but it is not a candidate key: D adds no identifying power.

A different roster, the same question

Now use a fresh relation, desk_checkins. Let J be reservation_id, K be member_id, L be checkin_state, M be desk_zone, and N be day_code. Its declared assumptions are J -> M,N, J,K -> L, and M,N -> J.

The faded scene starts with {K, M, N}. Watch which complete determinant fires first. This relation has its own candidate-key list, while the removable check starts with {J} after dropping K from the proposed J,K key.

Faded roster: test another determinant

Read the steps as text

  1. Start with seed K, M, N. Apply a dependency only when its left side is already known.
  2. M,N -> J adds J; the known set is now J, K, M, N.
  3. J,K -> L adds L; the known set is now J, K, L, M, N.
  4. No dependency adds another attribute. The fixed point is J, K, L, M, N.

The faded closure reaches J,K,L,M,N, and its candidate keys are J,K; K,M,N. A candidate key can have three attributes here even though another candidate key has two. That is why “minimum number of columns” and “inclusion-minimal” answer different questions.

One-attribute removal check

Read the steps as text

  1. Start with seed J. Apply a dependency only when its left side is already known.
  2. J -> M,N adds M, N; the known set is now J, M, N.
  3. No dependency adds another attribute. The fixed point is J, M, N.

Dropping K from the proposed J,K key leaves J,M,N, which does not cover the J,K,L,M,N schema. The attribute is therefore not removable from J,K. This check is about a proper subset, not about whether a short sample row looks unique.

Recap

  • Repeated facts can cause update, insert and delete anomalies; an FD names the domain rule behind the repetition.
  • Closure is a fixed-point set calculation, and a complete left side must be known before its right side can enter.
  • Superkeys may contain extra attributes; candidate keys keep only inclusion-minimal superkeys, including all valid sizes.
Why the scan order is harmless

The order in which you scan the FDs can change the order in which additions appear. The final fixed point is unchanged because the set only grows, and you keep scanning until no rule adds anything.

The next lesson uses dependencies to classify normal forms and discuss their design tradeoffs. It will ask what a decomposition preserves, which is a separate question from computing one closure.

Next, follow the dependencies into normal forms. For a DSA connection, practise key-based lookup in Fundamentals: a map associates one key with a record, while a database schema must state which attributes determine which others.