Algorithm Search⌘K

Problemadvanced

Functional dependency discovery

Also called FD discovery, dependency mining.

Given one relation instance, list every minimal functional dependency X -> A that holds in it. The output can be exponential in the number of attributes.

Time
O(m n 2^m) worst
Where
m = the number of attributes; n = the number of tuples

Functional dependency discovery asks for all functional dependencies that hold in a given relation instance, not the ones that a designer declares for a schema. The answer is the set of minimal dependencies X→AX \to A, from which Armstrong's axioms give all the others. This page states the problem, its size bounds and its reduction to hitting sets. The page TANE gives one algorithm for it in full: the levelwise lattice search with partitions. The other main family works from the pairs of rows that agree on some attributes and disagree on others.

In plain words

You get a table and nobody tells you its rules. You want to find every rule of the form "if two rows have the same values in these columns, they also have the same value in that column". You want only the shortest such rules, because a longer rule follows from a shorter one. The rules describe this one table: a new row can break any of them. The hard part is that a table with a few dozen columns can have a huge number of short rules, so any method must sometimes do a huge amount of work just to write the answer down. Methods differ in what they count: groups of columns, or pairs of rows.

Definition

Input. A relation instance rr with nn tuples over a set RR of mm attributes, under set semantics and with no nulls.

Dependencies. X→AX \to A, with X⊆RX \subseteq R and A∈R∖XA \in R \setminus X, holds in rr if any two tuples that agree on every attribute of XX also agree on AA. It is minimal if it holds and no Y→AY \to A with Y⊊XY \subsetneq X holds. The empty left side is allowed: ∅→A\emptyset \to A holds when AA is constant in rr.

Output. The set of all minimal dependencies that hold in rr. Every dependency that holds in rr follows from this set by augmentation, so it is a cover of all of them.

Agree sets. For two tuples t≠ut \ne u, the agree set is ag(t,u)={B∈R:t[B]=u[B]}\mathrm{ag}(t, u) = \{ B \in R : t[B] = u[B] \}. Then X→AX \to A holds if and only if X⊈ag(t,u)X \not\subseteq \mathrm{ag}(t, u) for every pair with t[A]≠u[A]t[A] \ne u[A].

Variants

  • Approximate dependencies. Allow a small error. The usual measure is g3g_3: the least fraction of tuples that must be deleted for X→AX \to A to hold. The task is to list the minimal X→AX \to A with g3≤εg_3 \le \varepsilon. These dependencies are not closed under Armstrong's axioms.
  • Keys. A candidate key is a minimal set XX with X→AX \to A for every AA. Finding all minimal keys of an instance is the special case of unique column combinations.
  • Conditional dependencies. A conditional functional dependency holds only on the tuples that match a pattern. Denial constraints generalize both and are mined by similar methods.
  • Fixed right side. List the minimal left sides of one attribute AA only. This is the core step of most algorithms.

Examples

A small instance. Over A,B,C,DA, B, C, D take the tuples (1,a,x,1)(1, a, x, 1), (1,a,y,2)(1, a, y, 2), (2,b,x,1)(2, b, x, 1), (2,b,y,3)(2, b, y, 3) and (3,b,x,1)(3, b, x, 1). The minimal dependencies are A→BA \to B, D→CD \to C, AC→DAC \to D and BC→DBC \to D. For the right side DD: the pairs of tuples that differ on DD are (1, 2), (1, 4), (2, 3), (2, 4), (2, 5), (3, 4) and (4, 5), with agree sets ABAB, ∅\emptyset, ∅\emptyset, CC, ∅\emptyset, ABAB and BB. A left side for DD must leave each of these agree sets, so it must contain CC (from the pairs that agree on ABAB) and one of AA or BB (from the pair that agrees on CC). The smallest such sets are ACAC and BCBC. The page TANE finds the same four dependencies on the same instance level by level.

An instance with many dependencies. Take attributes A1,B1,…,Ak,BkA_1, B_1, \ldots, A_k, B_k and CC, so m=2k+1m = 2k + 1, and k+1k + 1 tuples. Tuple 0 is all zeros with C=0C = 0. Tuple ii, for i=1,…,ki = 1, \ldots, k, has Ai=Bi=1A_i = B_i = 1, every other AjA_j and BjB_j equal to 0, and C=iC = i. For k=2k = 2 the minimal dependencies with the right side CC are A1A2→CA_1 A_2 \to C, A1B2→CA_1 B_2 \to C, B1A2→CB_1 A_2 \to C and B1B2→CB_1 B_2 \to C.

Known algorithms

  • Brute force. For each AA and each X⊆R∖{A}X \subseteq R \setminus \{A\}, test X→AX \to A by grouping the tuples on XX with a hash table, and keep the minimal ones. This takes O(mn2m)O(m n 2^m) expected time.
  • Lattice traversal. TANE visits the attribute sets level by level and tests each candidate with stripped partitions. FUN and FD_Mine also go level by level with other pruning rules, and DFD goes depth first. These methods are linear in nn and exponential in mm.
  • Difference and agree sets. Dep-Miner and FastFDs compute the agree sets of all pairs of tuples, then find the minimal left sides as minimal hitting sets (see Reductions). They are quadratic in nn and do better than lattice methods when mm is large and nn is small.
  • Dependency induction. FDEP starts from the most general dependencies and specializes them with each pair of tuples that violates one.

Papenbrock et al. (2015) implemented all seven of these algorithms in one framework and measured them on the same data sets. Their results are measurements on those data sets, not bounds.

AlgorithmTimeSpacePropertiesCode
TANEO((n + m^2.5) 2^m) worstO((n + m) 2^m / sqrt(m)) extradeterministicexactnot externalnot in placeofflineiterative1 language

Bounds

The output can be exponential. In the second example, X⊆R∖{C}X \subseteq R \setminus \{C\} determines CC if and only if XX holds at least one attribute of each pair {Ai,Bi}\{A_i, B_i\}. Proof. All values of CC differ, so X→CX \to C holds if and only if no two tuples agree on XX. Tuples 0 and ii agree exactly on the attributes outside {Ai,Bi}\{A_i, B_i\}, and tuples ii and jj agree on a subset of those. So two tuples agree on XX if and only if XX misses some pair. The minimal such XX pick one attribute from each pair, so there are 2k=2(m−1)/22^k = 2^{(m-1)/2} minimal dependencies with k+1k + 1 tuples. Any algorithm must write them all, so the worst case time is Ω(2(m−1)/2)\Omega(2^{(m-1)/2}) even for n=O(m)n = O(m). The source of Huhtala et al. for the same remark is Mannila and Räihä (1992).

The output is at most about 2m2^m. For a fixed AA, no minimal left side is a subset of another, so the left sides form an antichain of subsets of R∖{A}R \setminus \{A\}. By Sperner's theorem there are at most (m−1⌊(m−1)/2⌋)\binom{m-1}{\lfloor (m-1)/2 \rfloor} of them, and at most m(m−1⌊(m−1)/2⌋)=O(2mm)m \binom{m-1}{\lfloor (m-1)/2 \rfloor} = O(2^m \sqrt{m}) minimal dependencies in total.

Per test. One test of X→AX \to A needs Θ(n)\Theta(n) time to read the two columns, and partition methods reach O(n)O(n) for each lattice node.

Reductions

To minimal hitting sets. Fix AA. For each pair of tuples with t[A]≠u[A]t[A] \ne u[A], let the difference set be R∖ag(t,u)∖{A}R \setminus \mathrm{ag}(t, u) \setminus \{A\}. By the agree set condition, X→AX \to A holds if and only if XX meets every difference set. So the minimal left sides of AA are exactly the minimal hitting sets (minimal transversals) of the family of difference sets, and only the minimal difference sets matter. The first example shows this for A=DA = D. This is the reduction that the agree set methods use.

Keys. XX is a superkey if and only if no two tuples agree on XX, that is, XX meets R∖ag(t,u)R \setminus \mathrm{ag}(t, u) for every pair. The minimal keys are the minimal hitting sets of these complements; the second example is the case where they are the 2k2^k choices of one attribute per pair.

From the output to closures. Once the minimal dependencies are known, the attribute closure algorithm decides any implied dependency without the data.

Applications

  • Data profiling. Find keys and dependencies of a table that has no declared schema, such as an exported file or a data lake table.
  • Schema design. The dependencies suggest a decomposition in normalization, after a person confirms which ones are real rules and which hold only by chance.
  • Data cleaning. Approximate dependencies point at the few tuples that break a rule, and the rules become input to repair systems such as HoloClean.
  • Query optimization. Known dependencies let an optimizer drop redundant grouping columns and estimate the sizes of joins and groups better.

References

  1. Yka Huhtala, Juha Kärkkäinen, Pasi Porkka and Hannu Toivonen, TANE: an efficient algorithm for discovering functional and approximate dependencies, The Computer Journal 42(2), 1999, pages 100 to 111, Section 1 (the problem, minimal dependencies, the g3 error of approximate dependencies, and the remark that the number of minimal dependencies can be exponential in the number of attributes), Section 2 (partitions)
  2. Heikki Mannila and Kari-Jouko Räihä, On the complexity of inferring functional dependencies, Discrete Applied Mathematics 40, 1992, pages 237 to 243, the paper that Huhtala et al. (1999, Section 1) cite for the exponential number of minimal dependencies
  3. Thorsten Papenbrock, Jens Ehrlich, Jannik Marten, Tommy Neubert, Jan-Peer Rudolph, Martin Schönberg, Jakob Zwiener and Felix Naumann, Functional dependency discovery: an experimental evaluation of seven algorithms, PVLDB 8(10), 2015, pages 1082 to 1093, the classification of the algorithms into lattice traversal, difference and agree set, and dependency induction methods, and the measured run times and memory use of TANE, FUN, FD_Mine, DFD, Dep-Miner, FastFDs and FDEP

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a contract.yaml