Theoremadvanced
Exponential propagation of estimation errors
Also called Ioannidis-Christodoulakis error propagation.
If each frequency that a join size estimate uses is off by at most a factor 1 + e, the estimate for a join of n relations is off by at most (1 + e)^n, and this bound is reached.
This theorem says that small errors in the statistics of single relations can become large errors in the estimated size of a join result, and that the growth is exponential in the number of relations in the worst case. Ioannidis and Christodoulakis proved results of this kind in 1991, in a model where each relation is described by the frequencies of its join attribute values. This page states and proves a clean form of the result in an explicit model, shows that the bound is reached, and separates it from the measurements of real systems. The estimation problem itself is on the cardinality estimation page.
Statement
Model. Let be a natural equality join of relations, with bag semantics. Call an attribute a join attribute if at least two of the relations have it, let be the join attributes of , and let be the set of all assignments of values to the join attributes. For an assignment to , let be the number of tuples of whose values on are . An estimator of the frequency kind has estimates of these frequencies and returns
where is the restriction of to . Histograms with a uniform frequency in each bucket, frequencies from a sample, and the classic formulas built on the number of distinct values all give estimators of this kind. The q-error of an estimate of is .
Theorem. Let and let .
- If every frequency estimate satisfies , then . So the q-error is at most , for a join of relations, that is joins.
- The bound is reached: for every instance with , the estimates satisfy the hypothesis of part 1 and give , and gives .
In plain words
To guess the size of a join, an optimizer multiplies guesses about each table. If each guess is a little too big, the product is too big by the small error times itself, once for each table. Ten tables that are each 10 percent too big give an answer that is about 2.6 times too big. Ten tables that are each twice too big give an answer that is a thousand times too big.
The theorem says that this is the worst that can happen when each table is off by a bounded factor, and that it really can happen. Real data adds a second problem: the guesses for different tables tend to be wrong in the same direction, so the errors do not cancel.
Proof
Lemma (the size of a join). .
Proof. A result tuple of is a choice of one tuple from each such that any two chosen tuples agree on the attributes they share. Only join attributes are shared, so the chosen tuples agree exactly when there is one assignment with for every , and this is unique, because every join attribute is in some . For a fixed , the tuples can be chosen independently among the tuples of with these values, which gives result tuples. Summing over counts each result tuple once.
Part 1. For each , every factor satisfies , and all the numbers are at least 0, so the products satisfy
Sum over and use the lemma: . When , this gives and .
Part 2. With , every product has the factor , so by the lemma, and the q-error is . The case is the same with .
Consequences
- Numbers. With and , the bound is . With it is about 57.7, and with it is . A plan whose intermediate result is a thousand times larger than estimated can be the wrong plan, for example a nested loop join where a hash join was needed.
- Errors in the same direction (a consequence of the proof). If each relation is off by a factor in the same direction for all its frequencies, for example because a sample of the table was scaled wrongly, then exactly. In logarithms, . If the are independent random variables with mean and variance , then has mean and variance . So a systematic bias makes the error grow exponentially in , and errors with no bias still give a typical q-error of about , which also grows without limit.
- Uniformity alone (an example in the model). Even exact table sizes and exact distinct counts give exponential errors when the data is skewed. Let each have 100 tuples on one join attribute , with value in 99 tuples and value in 1 tuple. Then . A uniform estimate uses for both values and gives . The ratio is about 1.96 for , 15.2 for and 463 for , close to .
- Measurements (not part of the theorem). Leis et al. (2015) measured the estimates of several systems on the Join Order Benchmark over the IMDB data. The estimates were mostly too small, and the errors grew quickly with the number of joins, which matches the second consequence with . Correlated columns, handled by the attribute value independence assumption, are a main reason for the common direction.
- What an optimizer can do. Keep the error of each estimate small where it matters, as histograms built for joins try to do; use bounds instead of estimates, as pessimistic cardinality estimation does; or check the sizes at run time and re-plan, as mid-query re-optimization does. Moerkotte, Neumann and Steidl (2009) define the q-error and bound the extra cost of the chosen plan in terms of the q-errors of its estimates.
Tightness
Part 2 of the theorem shows that the factor cannot be improved for any instance: the estimates that are off by exactly in the same direction for every frequency reach it. The exponent is the number of relations, so a chain of joins has exponent . If the errors of the relations have different directions, they can cancel, and the bound is then far from the truth; the theorem gives only the worst case. If the hypothesis is weakened to an error of a factor in the total size of each relation, with no control of single frequencies, the q-error is not bounded at all: two relations of tuples each join in 0 tuples if their join values are disjoint and in tuples if all tuples have the same join value, while the sizes are the same.
History
Ioannidis and Christodoulakis (1991) studied the size of the results of equality joins in a model that describes each relation by the frequency distribution of its join attribute values, and showed that the error of the estimate can grow exponentially with the number of joins. In 1993 they studied which histograms limit this worst-case growth. Moerkotte, Neumann and Steidl (2009) introduced the q-error as the measure of these errors that fits multiplication. Leis et al. (2015) built the Join Order Benchmark and measured the growth in real systems.
References
- On the propagation of errors in the size of join results, the result that, in their model of equality joins described by the frequencies of the join attribute values, the error of the estimated result size grows exponentially with the number of joins
- Yannis E. Ioannidis and Stavros Christodoulakis, Optimal histograms for limiting worst-case error propagation in the size of join results, ACM Transactions on Database Systems 18(4) (1993), 709 to 748, histograms chosen to limit the worst-case error that propagates through joins
- Preventing bad plans by bounding the impact of cardinality estimation errors, the q-error, the larger of estimate/truth and truth/estimate, and bounds on the cost of the chosen plan in terms of it
- Viktor Leis, Andrey Gubichev, Atanas Mirchev, Peter Boncz, Alfons Kemper and Thomas Neumann, How good are query optimizers, really?, Proceedings of the VLDB Endowment 9(3) (2015), 204 to 215, Section 3 (measured cardinality estimates of several systems on the Join Order Benchmark, by number of joins)
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 | W4 complete |
|
Tag ZDG38A Edit this page History Report an error Markdown