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
- Model
- Word RAM
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 , 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 with tuples over a set of attributes, under set semantics and with no nulls.
Dependencies. , with and , holds in if any two tuples that agree on every attribute of also agree on . It is minimal if it holds and no with holds. The empty left side is allowed: holds when is constant in .
Output. The set of all minimal dependencies that hold in . Every dependency that holds in follows from this set by augmentation, so it is a cover of all of them.
Agree sets. For two tuples , the agree set is . Then holds if and only if for every pair with .
Variants
- Approximate dependencies. Allow a small error. The usual measure is : the least fraction of tuples that must be deleted for to hold. The task is to list the minimal with . These dependencies are not closed under Armstrong's axioms.
- Keys. A candidate key is a minimal set with for every . 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 only. This is the core step of most algorithms.
Examples
A small instance. Over take the tuples , , , and . The minimal dependencies are , , and . For the right side : the pairs of tuples that differ on are (1, 2), (1, 4), (2, 3), (2, 4), (2, 5), (3, 4) and (4, 5), with agree sets , , , , , and . A left side for must leave each of these agree sets, so it must contain (from the pairs that agree on ) and one of or (from the pair that agrees on ). The smallest such sets are and . The page TANE finds the same four dependencies on the same instance level by level.
An instance with many dependencies. Take attributes and , so , and tuples. Tuple 0 is all zeros with . Tuple , for , has , every other and equal to 0, and . For the minimal dependencies with the right side are , , and .
Known algorithms
- Brute force. For each and each , test by grouping the tuples on with a hash table, and keep the minimal ones. This takes 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 and exponential in .
- 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 and do better than lattice methods when is large and 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.
| Algorithm | Time | Space | Properties | Code |
|---|---|---|---|---|
| TANE | O((n + m^2.5) 2^m) worst | O((n + m) 2^m / sqrt(m)) extra | deterministicexactnot externalnot in placeofflineiterative | 1 language |
Bounds
The output can be exponential. In the second example, determines if and only if holds at least one attribute of each pair . Proof. All values of differ, so holds if and only if no two tuples agree on . Tuples 0 and agree exactly on the attributes outside , and tuples and agree on a subset of those. So two tuples agree on if and only if misses some pair. The minimal such pick one attribute from each pair, so there are minimal dependencies with tuples. Any algorithm must write them all, so the worst case time is even for . The source of Huhtala et al. for the same remark is Mannila and Räihä (1992).
The output is at most about . For a fixed , no minimal left side is a subset of another, so the left sides form an antichain of subsets of . By Sperner's theorem there are at most of them, and at most minimal dependencies in total.
Per test. One test of needs time to read the two columns, and partition methods reach for each lattice node.
Reductions
To minimal hitting sets. Fix . For each pair of tuples with , let the difference set be . By the agree set condition, holds if and only if meets every difference set. So the minimal left sides of 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 . This is the reduction that the agree set methods use.
Keys. is a superkey if and only if no two tuples agree on , that is, meets for every pair. The minimal keys are the minimal hitting sets of these complements; the second example is the case where they are the 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
- 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)
- 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
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 1TD1WN Edit this page History Report an error Markdown