When it does not fit

A summary's silence is a bound, not a count

When both sides of a join are skewed towards the same values the textbook estimate is 399 times too low and the order it picks costs 244 times the better one; two counters a side repair it. Skew them towards different values and the same estimate becomes 254 times too high — and the counters have nothing to say, because no value is in both summaries. Using their silence instead repairs the middle of the sweep and makes the far end six times worse.

The skew a few counters cannot repair measured a planner choosing the order of a three-way join from the textbook estimate, which assumes the join column is uniform. At a Zipf exponent of two the estimate is far too low, the order it picks costs 243.9 times the better one, and two heavy-hitter counters a side repair it completely. At an exponent of a half the estimate is out by less than a factor of two and no number of counters up to 256 changes the plan.

Every column on that page is skewed the same way on both sides: the popular values of the join column are popular in RR and in SS alike, which is what makes the sum of products large and the uniform estimate too low. Real joins are not always like that. The most-ordered products are not the most-reviewed ones, and a column can be skewed in both relations towards different values — and then the sum of products is small, the uniform estimate is too high, and the heavy values each summary reports are values the other summary does not hold.

This page rotates one side’s ranking away from the other’s and measures what happens to the estimate, to the plan, and to the repair.

One dial, both marginals fixed

The sweep changes which value sits at each rank of SS’s distribution and nothing else. At a rotation of zero, SS’s most popular value is RR’s most popular; at a rotation of five it is RR’s fifth; at 500 it is a value RR barely holds. Both columns keep the same shape — the same Zipf exponent, the same number of distinct values, the same row counts — so the uniform estimate, which reads only those, does not move at all.

As the two sides' heavy values separate, the uniform estimate goes from 399 times too low to 254 times too high — and the counters stop correcting it at 25The true join size divided by the estimate, against how far S's ranking of the join column is rotated from R's, on logarithmic axes, at a Zipf exponent of 2 over 1,000 distinct values. A rotation of zero means both sides are skewed towards the same values; a rotation of 500 means they are skewed towards unrelated ones. Rotated by 0: the join truly holds 63,871,022 rows; the uniform estimate is out by 399.194 and its order costs 243.87; 8 counters a side are out by 1.126 and cost 1.00; using the counters' silence as well is out by 1.125 and costs 1.00. Rotated by 1: the join truly holds 17,210,982 rows; the uniform estimate is out by 107.569 and its order costs 65.84; 8 counters a side are out by 1.354 and cost 1.00; using the counters' silence as well is out by 0.746 and costs 1.00. Rotated by 2: the join truly holds 7,737,274 rows; the uniform estimate is out by 48.358 and its order costs 29.69; 8 counters a side are out by 1.969 and cost 1.00; using the counters' silence as well is out by 0.467 and costs 1.00. Rotated by 5: the join truly holds 2,325,640 rows; the uniform estimate is out by 14.535 and its order costs 9.04; 8 counters a side are out by 20.414 and cost 9.04; using the counters' silence as well is out by 0.138 and costs 1.00. Rotated by 10: the join truly holds 793,786 rows; the uniform estimate is out by 4.961 and its order costs 3.19; 8 counters a side are out by 4.961 and cost 3.19; using the counters' silence as well is out by 0.029 and costs 1.00. Rotated by 25: the join truly holds 143,624 rows; the uniform estimate is out by 0.898 and its order costs 1.00; 8 counters a side are out by 0.898 and cost 1.00; using the counters' silence as well is out by 0.005 and costs 1.40. Rotated by 50: the join truly holds 8,636 rows; the uniform estimate is out by 0.054 and its order costs 1.00; 8 counters a side are out by 0.054 and cost 1.00; using the counters' silence as well is out by 0.000 and costs 5.07. Rotated by 100: the join truly holds 2,066 rows; the uniform estimate is out by 0.013 and its order costs 1.00; 8 counters a side are out by 0.013 and cost 1.00; using the counters' silence as well is out by 0.000 and costs 5.80. Rotated by 250: the join truly holds 242 rows; the uniform estimate is out by 0.002 and its order costs 1.00; 8 counters a side are out by 0.002 and cost 1.00; using the counters' silence as well is out by 0.000 and costs 6.05. Rotated by 500: the join truly holds 629 rows; the uniform estimate is out by 0.004 and its order costs 1.00; 8 counters a side are out by 0.004 and cost 1.00; using the counters' silence as well is out by 0.000 and costs 6.00.01251025501002505000.00010.0010.010.1110100how far S's ranking is rotated from R'strue size ÷ estimatethe uniform estimate8 counters a side8 counters, using their silenceexactZipf 2, 8 counters a sideabove the line: the estimate is too low
Fig. 1 The true join size divided by the estimate, against how far S’s ranking of the join column is rotated from R’s, on logarithmic axes, at a Zipf exponent of two over 1,000 distinct values. The uniform estimate runs from 399 times too low at a rotation of zero, through 14.5 at five and 4.96 at ten, to 254 times too high at 500. Eight counters a side track it down to a rotation of two and then stop correcting.

The first line spans five orders of magnitude and the estimate behind it never changes: 160,000 rows, at every rotation. The join truly holds 63,871,022 rows at a rotation of zero and 629 at 500.

So the estimator’s error swings by a factor of 100,000 across the sweep and the estimator cannot see any of it, because it has no term the sweep touches. That is worth separating from the usual complaint about uniformity assumptions. The textbook estimate is not merely approximate here; it is measuring a quantity — row counts over distinct values — that is invariant under the thing that decides the answer.

What the plan does about it

The order a uniform estimate chooses costs 244 times the better one when the heavy values coincide and nothing when they differ — and the correction that repairs the middle makes the far end 6.0 times worseThe regret of the order chosen, with the shared output removed, against how far S's ranking of the join column is rotated from R's, on logarithmic axes, at a Zipf exponent of 2 over 1,000 distinct values. A rotation of zero means both sides are skewed towards the same values; a rotation of 500 means they are skewed towards unrelated ones. Rotated by 0: the join truly holds 63,871,022 rows; the uniform estimate is out by 399.194 and its order costs 243.87; 8 counters a side are out by 1.126 and cost 1.00; using the counters' silence as well is out by 1.125 and costs 1.00. Rotated by 1: the join truly holds 17,210,982 rows; the uniform estimate is out by 107.569 and its order costs 65.84; 8 counters a side are out by 1.354 and cost 1.00; using the counters' silence as well is out by 0.746 and costs 1.00. Rotated by 2: the join truly holds 7,737,274 rows; the uniform estimate is out by 48.358 and its order costs 29.69; 8 counters a side are out by 1.969 and cost 1.00; using the counters' silence as well is out by 0.467 and costs 1.00. Rotated by 5: the join truly holds 2,325,640 rows; the uniform estimate is out by 14.535 and its order costs 9.04; 8 counters a side are out by 20.414 and cost 9.04; using the counters' silence as well is out by 0.138 and costs 1.00. Rotated by 10: the join truly holds 793,786 rows; the uniform estimate is out by 4.961 and its order costs 3.19; 8 counters a side are out by 4.961 and cost 3.19; using the counters' silence as well is out by 0.029 and costs 1.00. Rotated by 25: the join truly holds 143,624 rows; the uniform estimate is out by 0.898 and its order costs 1.00; 8 counters a side are out by 0.898 and cost 1.00; using the counters' silence as well is out by 0.005 and costs 1.40. Rotated by 50: the join truly holds 8,636 rows; the uniform estimate is out by 0.054 and its order costs 1.00; 8 counters a side are out by 0.054 and cost 1.00; using the counters' silence as well is out by 0.000 and costs 5.07. Rotated by 100: the join truly holds 2,066 rows; the uniform estimate is out by 0.013 and its order costs 1.00; 8 counters a side are out by 0.013 and cost 1.00; using the counters' silence as well is out by 0.000 and costs 5.80. Rotated by 250: the join truly holds 242 rows; the uniform estimate is out by 0.002 and its order costs 1.00; 8 counters a side are out by 0.002 and cost 1.00; using the counters' silence as well is out by 0.000 and costs 6.05. Rotated by 500: the join truly holds 629 rows; the uniform estimate is out by 0.004 and its order costs 1.00; 8 counters a side are out by 0.004 and cost 1.00; using the counters' silence as well is out by 0.000 and costs 6.00.0125102550100250500110100how far S's ranking is rotated from R'sregret of the order chosenthe uniform estimate8 counters a side8 counters, using their silencethe better orderZipf 2, 8 counters a sideone is the better order
Fig. 2 The regret of the order chosen, with the shared output removed from both orders, against the same rotation. The uniform estimate’s order costs 243.9 times the better one at a rotation of zero, 9.04 at five, 3.19 at ten and exactly one from twenty-five onwards. Eight counters a side bring the left of the sweep to one and leave the middle where it was; using the counters’ silence as well brings the middle to one and takes the far right to 6.0.

The planner’s decision is identical at every rotation — the same estimate produces the same comparison and the same order — so the regret line is entirely a statement about when that one fixed decision happens to be right.

It is wrong, expensively, on the left. It is right, for free, on the right: from a rotation of twenty-five onwards the order the uniform estimate picks is the better order, and the regret is one even though the estimate is between 1.1 and 254 times too high.

The join order is a guess is where that gap was first measured between an estimate’s error and a plan’s cost — an estimate out by seventy-two times producing a plan 1.49 times worse on the whole query and 43.9 times worse on the part the order actually decided. The same two numbers are reported here, and it is the second one the plates draw.

The overestimate costs nothing here and the underestimate costs 244×, and that asymmetry is not about estimation at all. An intermediate result that is truly enormous and is estimated as small makes the planner choose an order that materialises it; an intermediate result that is truly tiny and is estimated as large makes the planner avoid materialising something that would have been cheap. The first is a mistake that is paid in full; the second is a mistake that costs whatever the alternative order costs, which here is nothing. The estimate a plan rests on measured the same asymmetry for a single predicate and named its ceiling: guessing too few rows on a wide query costs at most a bounded factor, and guessing too many on a narrow one does not.

The order chosen on the uniform estimate costs 243.9× at skew 2; 4 counters 1.00×, 16 counters 1.00×, 64 counters 1.00×, 256 counters 1.00× — and at skew 0.5 every line is at 1.37×A three-way join of R (4,000 rows), S (40,000) and T (2,000), its order chosen on an estimate of the first join's size, swept over the skew of the join column. Each line is the regret of the part of the plan the order decides. uniform estimate: 1.00 at 0, 1.00 at 0.25, 1.37 at 0.5, 4.43 at 0.75, 17.73 at 1, 52.90 at 1.25, 110.97 at 1.5, 179.63 at 1.75, 243.87 at 2. 4 counters a side: 1.00 at 0, 1.00 at 0.25, 1.37 at 0.5, 4.43 at 0.75, 17.73 at 1, 1.00 at 1.25, 1.00 at 1.5, 1.00 at 1.75, 1.00 at 2. 16 counters a side: 1.00 at 0, 1.00 at 0.25, 1.37 at 0.5, 4.43 at 0.75, 1.00 at 1, 1.00 at 1.25, 1.00 at 1.5, 1.00 at 1.75, 1.00 at 2. 64 counters a side: 1.00 at 0, 1.00 at 0.25, 1.37 at 0.5, 1.00 at 0.75, 1.00 at 1, 1.00 at 1.25, 1.00 at 1.5, 1.00 at 1.75, 1.00 at 2. 256 counters a side: 1.00 at 0, 1.00 at 0.25, 1.37 at 0.5, 1.00 at 0.75, 1.00 at 1, 1.00 at 1.25, 1.00 at 1.5, 1.00 at 1.75, 1.00 at 2.10×20×50×100×200×00.250.50.7511.251.51.752skew of the join columnregret of the decided part, logarithmicuniform estimate4 counters a side16 counters a side64 counters a side256 counters a sideR 4,000, S 40,000, T 2,000 rows · 64-record blocks, 4,096 in memoryMisra–Gries on each side of the join column
Fig. 3 The earlier page’s sweep, for the parameter this page holds fixed: the regret of the order chosen, against the Zipf exponent, for the uniform estimate and for four counter counts, with both sides skewed towards the same values. The uniform estimate’s order costs 243.9 times the better one at an exponent of two and every counter count brings it to one; at an exponent of a half every line sits at 1.37.

That plate and the one above it are the same experiment at two different points of the same two-dimensional space, and it is worth naming the space because neither page draws it whole. A join’s estimate is decided by how skewed each side is and by how much the two skews agree. The earlier page swept the first with the second held at perfect agreement; this page sweeps the second with the first held at an exponent of two. The corner they share — exponent two, rotation zero — is the 243.9 that appears on both.

Why the counters stop

The repair that worked on the left is a Misra–Gries summary of each side. Values that both summaries report contribute the product of their reported counts exactly, and the rows left over are spread uniformly over the distinct values left over. At a rotation of zero both summaries hold the same eight values and the correction is nearly exact — 1.13 times the truth against the uniform estimate’s 399.

At a rotation of ten the two summaries hold eight values each and share none. The exact term is zero, every row is left over, and the corrected estimate is the uniform one to the last digit: 160,000, error 4.96, regret 3.19 — the same three numbers as with no summary at all.

That is the mechanism the earlier page’s question was about, and it is worth stating plainly. The summaries have not failed to find the heavy values; they have found them, and the estimator has no use for a heavy value the other side does not share. Eight counters a side on this data hold the eight values that matter on each side, and the estimator throws both sets away.

The counters a side each skew needs before the order is right: 512 at skew 0.5, 8 at skew 1, 2 at skew 1.5The regret of the decided part of a three-way join plan, its order chosen on an estimate built from Misra–Gries summaries of the join column, against the number of counters each summary keeps, on logarithmic axes. At skew 0.5 the uniform estimate's regret is 1.37; with 1 counters 1.37, 2 counters 1.37, 4 counters 1.37, 8 counters 1.37, 16 counters 1.37, 32 counters 1.37, 64 counters 1.37, 128 counters 1.37, 256 counters 1.37, 512 counters 1.00. At skew 1 the uniform estimate's regret is 17.73; with 1 counters 17.73, 2 counters 17.73, 4 counters 17.73, 8 counters 1.00, 16 counters 1.00, 32 counters 1.00, 64 counters 1.00, 128 counters 1.00, 256 counters 1.00, 512 counters 1.00. At skew 1.5 the uniform estimate's regret is 110.97; with 1 counters 110.97, 2 counters 1.00, 4 counters 1.00, 8 counters 1.00, 16 counters 1.00, 32 counters 1.00, 64 counters 1.00, 128 counters 1.00, 256 counters 1.00, 512 counters 1.00.1248163264128256512110100counters a sideregret, decided partskew 0.5skew 1skew 1.51 = the better orderR 4,000, S 40,000, T 2,000 rowsMisra–Gries on each side of the join column
Fig. 4 The earlier measurement, for context: the counters a side each skew needs before the order is right, with both sides skewed towards the same values. At a Zipf exponent of 1.5 a couple of counters are enough; at a half, 512 are not. Every point on this plate is at a rotation of zero, where the counters have shared values to work with.

The rotation of five is the interesting failure, because there the summaries share some values by accident and the correction is worse than none: it estimates 20.4 times too high where the uniform estimate was 14.5 times too low, and the order it picks is the same wrong one, so the regret stays at 9.04. A summary that shares two of its eight values takes those two products as exact and spreads the rest uniformly, which double-counts the mass those two values carry on both sides.

That failure is a shortage of counters and it does go away. Sixty-four counters a side hold enough of each ranking that the two overlap again at a rotation of ten, and the corrected estimate reads 1.05 times the truth with a regret of one; at 256 counters it is exact to two decimals from a rotation of zero to twenty-five. So the middle of the sweep is a case where more summary buys the answer, exactly as the earlier page’s skew sweep was.

The order a uniform estimate chooses costs 244 times the better one when the heavy values coincide and nothing when they differ — and the correction that repairs the middle makes the far end 6.0 times worseThe regret of the order chosen, with the shared output removed, against how far S's ranking of the join column is rotated from R's, on logarithmic axes, at a Zipf exponent of 2 over 1,000 distinct values. A rotation of zero means both sides are skewed towards the same values; a rotation of 500 means they are skewed towards unrelated ones. Rotated by 0: the join truly holds 63,871,022 rows; the uniform estimate is out by 399.194 and its order costs 243.87; 64 counters a side are out by 1.002 and cost 1.00; using the counters' silence as well is out by 1.002 and costs 1.00. Rotated by 1: the join truly holds 17,210,982 rows; the uniform estimate is out by 107.569 and its order costs 65.84; 64 counters a side are out by 1.004 and cost 1.00; using the counters' silence as well is out by 0.922 and costs 1.00. Rotated by 2: the join truly holds 7,737,274 rows; the uniform estimate is out by 48.358 and its order costs 29.69; 64 counters a side are out by 1.007 and cost 1.00; using the counters' silence as well is out by 0.808 and costs 1.00. Rotated by 5: the join truly holds 2,325,640 rows; the uniform estimate is out by 14.535 and its order costs 9.04; 64 counters a side are out by 1.018 and cost 1.00; using the counters' silence as well is out by 0.519 and costs 1.00. Rotated by 10: the join truly holds 793,786 rows; the uniform estimate is out by 4.961 and its order costs 3.19; 64 counters a side are out by 1.048 and cost 1.00; using the counters' silence as well is out by 0.257 and costs 1.00. Rotated by 25: the join truly holds 143,624 rows; the uniform estimate is out by 0.898 and its order costs 1.00; 64 counters a side are out by 0.987 and cost 1.00; using the counters' silence as well is out by 0.047 and costs 1.40. Rotated by 50: the join truly holds 8,636 rows; the uniform estimate is out by 0.054 and its order costs 1.00; 64 counters a side are out by 0.054 and cost 1.00; using the counters' silence as well is out by 0.002 and costs 5.07. Rotated by 100: the join truly holds 2,066 rows; the uniform estimate is out by 0.013 and its order costs 1.00; 64 counters a side are out by 0.013 and cost 1.00; using the counters' silence as well is out by 0.000 and costs 5.80. Rotated by 250: the join truly holds 242 rows; the uniform estimate is out by 0.002 and its order costs 1.00; 64 counters a side are out by 0.002 and cost 1.00; using the counters' silence as well is out by 0.000 and costs 6.05. Rotated by 500: the join truly holds 629 rows; the uniform estimate is out by 0.004 and its order costs 1.00; 64 counters a side are out by 0.004 and cost 1.00; using the counters' silence as well is out by 0.000 and costs 6.00.0125102550100250500110100how far S's ranking is rotated from R'sregret of the order chosenthe uniform estimate64 counters a side64 counters, using their silencethe better orderZipf 2, 64 counters a sideone is the better order
Fig. 5 The same regret sweep with sixty-four counters a side rather than eight. The plain correction now reaches one across the whole left half — a rotation of five and of ten are both repaired — and the far right is unchanged: the uniform estimate is right by accident there and the corrections are not needed.

The far right is a different thing entirely, and it is worth taking apart because the number is surprising.

Where the overestimate actually lives

At a rotation of 100 the join truly holds 2,066 rows and the uniform estimate says 160,000. With 256 counters a side, the corrected estimate reads 155,201, and it decomposes:

  • the shared heavy values contribute 2,050, against a true total of 2,066;
  • the rows left over contribute 153,151.

The summary has the answer. Eleven values are in both summaries, their products sum to within one per cent of the whole join, and the estimator then adds seventy-four times that much for the rows neither summary holds.

So the overestimate is not a failure of the heavy-value correction; it is the uniform assumption applied to the tail. The two rankings are unrelated, so a value that is moderately common in RR is, on average, unremarkable in SS — but the products of the two tails are far below the product of their averages, because the averages are pulled up by mass that sits at different values on the two sides. The uniform term is computing (Rtail)(Stail)/d\left(\sum_R \text{tail}\right)\left(\sum_S \text{tail}\right) / d, which is an average of products replaced by a product of averages, and the two differ by exactly the correlation the sweep is about.

A summary of heavy values cannot repair that, at any size, because the mass causing it is by construction not heavy. That is the honest reading of the far right, and it is a different failure from the one at a rotation of five.

Using what a summary does not say

A Misra–Gries summary of kk counters holds every value occurring more than n/(k+1)n/(k+1) times. So a value one summary reports and the other does not is not merely uncovered: the second summary’s silence is an upper bound on how often that value occurs there.

Using the bound gives a third estimator. A value held by one side and not the other contributes its reported count times n/(k+1)n/(k+1) rather than its reported count times the average, and the remainder is spread as before.

It works where the plain counters failed. At a rotation of five it takes the error from 20.4 times too high to 7 times too high and the regret from 9.04 to 1.00; at ten, from 4.96 times too low to 1.00 regret. Across rotations from zero to ten it produces the right order every time.

And it breaks the far end. At a rotation of 100 it estimates about a hundred times too high and its order costs 5.8 times the better one; at 500, 6.0. The uniform estimate, which knows nothing, costs 1.00 at both.

The reason is in the word “bound”. n/(k+1)n/(k+1) is 4,444 rows when the summary holds eight counters over 40,000 rows, and the true frequency of a value the summary does not hold is anything from 4,444 down to zero. On the left of the sweep, where the heavy values nearly coincide, the values the summaries miss really do occur thousands of times and the bound is close. On the right, where the rankings are unrelated, a value heavy in RR occurs in SS a handful of times, and the bound overstates it by three orders of magnitude.

So the answer to whether a summary can correct an overestimate as well as it corrects an underestimate is no — and the reason is not the one the question implied. A summary’s positive statements are counts and its negative ones are bounds. Counts can be multiplied together to correct in either direction, which is why more counters repair the middle of this sweep; a bound multiplied by a count gives a bound, and a bound used where an estimate is wanted errs in one direction only, which is exactly the direction that was already wrong on the right.

And underneath both is the decomposition above: the overestimate on the right is in the uniform tail, which is the one part of the estimate that no summary of heavy values addresses, by definition.

What a planner should take from this

Ask which direction the error runs before choosing a repair. The two halves of this sweep need different things: the left needs the shared heavy values, which counters supply once there are enough of them; the right needs the tail’s correlation, which no summary of the heaviest few values holds. A planner that applies the heavy-value correction everywhere is right on the left, harmless on the right, and wrong in a narrow band in between if its summaries are too small.

And count the counters against the ranking, not against the skew. Eight counters a side repair a rotation of zero and fail at five; sixty-four repair both. The number needed is set by how far the two rankings have to overlap before a shared value appears, which is a property of the pair of columns and not of either one. A planner sizing its summaries from a single column’s skew — which is what a histogram on one table gives it — is sizing them for the wrong quantity.

And a correction that helps in the middle is not therefore safe. The silence-using estimator is the best of the three over rotations from zero to ten and the worst of the three from twenty-five on. Measuring it only where the problem was first noticed would have shipped it.

That is the same shape the skew a few counters cannot repair found in the other parameter: the easy case was the extreme one, and the moderate case was hard for a reason with a name. Here the extreme cases are easy in both directions — a rotation of zero is repaired by counters and a rotation of 500 needs no repair at all — and the middle is where every estimator on the page is at its worst.

As the two sides' heavy values separate, the uniform estimate goes from 29 times too low to 2 times too high — and the counters stop correcting it at 250The true join size divided by the estimate, against how far S's ranking of the join column is rotated from R's, on logarithmic axes, at a Zipf exponent of 1 over 1,000 distinct values. A rotation of zero means both sides are skewed towards the same values; a rotation of 500 means they are skewed towards unrelated ones. Rotated by 0: the join truly holds 4,604,560 rows; the uniform estimate is out by 28.779 and its order costs 17.73; 8 counters a side are out by 18.035 and cost 1.00; using the counters' silence as well is out by 17.144 and costs 1.00. Rotated by 1: the join truly holds 2,700,906 rows; the uniform estimate is out by 16.881 and its order costs 10.47; 8 counters a side are out by 16.881 and cost 10.47; using the counters' silence as well is out by 2.517 and costs 1.00. Rotated by 2: the join truly holds 2,192,205 rows; the uniform estimate is out by 13.701 and its order costs 8.53; 8 counters a side are out by 13.701 and cost 8.53; using the counters' silence as well is out by 2.043 and costs 1.00. Rotated by 5: the join truly holds 1,308,466 rows; the uniform estimate is out by 8.178 and its order costs 5.16; 8 counters a side are out by 8.178 and cost 5.16; using the counters' silence as well is out by 1.219 and costs 1.00. Rotated by 10: the join truly holds 954,389 rows; the uniform estimate is out by 5.965 and its order costs 3.81; 8 counters a side are out by 5.965 and cost 3.81; using the counters' silence as well is out by 0.889 and costs 1.00. Rotated by 25: the join truly holds 445,605 rows; the uniform estimate is out by 2.785 and its order costs 1.86; 8 counters a side are out by 2.785 and cost 1.86; using the counters' silence as well is out by 0.415 and costs 1.00. Rotated by 50: the join truly holds 271,496 rows; the uniform estimate is out by 1.697 and its order costs 1.20; 8 counters a side are out by 1.697 and cost 1.20; using the counters' silence as well is out by 0.253 and costs 1.00. Rotated by 100: the join truly holds 172,314 rows; the uniform estimate is out by 1.077 and its order costs 1.00; 8 counters a side are out by 1.077 and cost 1.00; using the counters' silence as well is out by 0.161 and costs 1.22. Rotated by 250: the join truly holds 97,129 rows; the uniform estimate is out by 0.607 and its order costs 1.00; 8 counters a side are out by 0.607 and cost 1.00; using the counters' silence as well is out by 0.091 and costs 1.87. Rotated by 500: the join truly holds 75,538 rows; the uniform estimate is out by 0.472 and its order costs 1.00; 8 counters a side are out by 0.472 and cost 1.00; using the counters' silence as well is out by 0.070 and costs 2.21.01251025501002505000.1110how far S's ranking is rotated from R'strue size ÷ estimatethe uniform estimate8 counters a side8 counters, using their silenceexactZipf 1, 8 counters a sideabove the line: the estimate is too low
Fig. 6 The same sweep at a Zipf exponent of one rather than two. The uniform estimate runs from 29 times too low at a rotation of zero to twice too high at 500 — a span of sixty rather than 100,000 — and eight counters a side track it much further along, stopping only at a rotation of 250. A flatter distribution puts more of its mass outside any small summary, and also makes the rankings’ correlation matter less.

The exponent decides how much is at stake and the rotation decides who can see it, and the two are not interchangeable. At an exponent of one the whole sweep spans a factor of sixty and the worst order costs 17.7; at two it spans 100,000 and the worst order costs 244. A planner that has measured its column’s skew knows the first number and knows nothing about the second.

What is not measured here

Rotation, not a correlation coefficient. The sweep rotates one side’s ranking, which takes the two heavy sets from identical to disjoint through a sequence in which they partially overlap. It is one path through the space of rankings; a random permutation of SS’s ranking would be a different one and would have no monotone parameter.

One distribution shape on both sides. Both columns are Zipf with the same exponent. A join between a heavily skewed column and a nearly uniform one is a different case and is not swept.

One summary, not a histogram. A Misra–Gries summary is the structure the items that survive k counters measured, and it is built to find heavy hitters rather than to describe a distribution. A histogram over equal-width buckets describes the tail, which is where the far right’s error lives — and the histogram that cannot see the order is the standing warning about what a histogram loses instead.

The bound is the textbook one. A Misra–Gries summary’s guarantee is that it holds every value above n/(k+1)n/(k+1); a real implementation also knows each counter’s residual error and could bound an absent value more tightly. That would move the silence-using estimator’s break-even and would not change its direction.

The rows a join produces, not the rows it reads. The estimate under test is of the intermediate result’s size, which the occurrences a join invents is about in a different setting: a join over skewed values produces far more rows than either side holds, and an estimate that cannot see the skew cannot see that either.

Three relations, one shape. The join is RSTR \bowtie S \bowtie T with SS in the middle, and only the RRSS column is skewed. A plan over six relations has more orders and more estimates, and the regret compounds across them rather than resting on one.

Transfers, not time, as throughout these join measurements, and the regret reported is the decided part — the whole plan’s cost with the final result’s own write removed from both orders, since both orders pay it and it swamps the part the estimate actually decided.

Still open: a summary that measures rather than bounds

Everything that went wrong on the right of this sweep went wrong because a summary answers “how often does this value occur” with either a count or a bound, and the bound is loose when the answer is small. A structure that answers with an estimate in both cases exists and has been measured here: a Count-Min sketch returns a count for every value, never below the truth and wrong by an amount proportional to the whole stream rather than to the value.

A count that is never under is the structure to reach for, and its one-sided error is the thing to watch when two of its answers are multiplied together: two estimates that are each never below the truth give a product that is never below the truth either, and the errors compound rather than cancel.

The measurement that follows replaces the two Misra–Gries summaries with two Count-Min sketches of the same total width, estimates the join size as the sum over the heavy values of each side of the product of the two sketches’ answers, and asks three things: whether the right of the sweep is repaired, what the sketches’ one-sided error does to the estimate when both factors are overestimates, and how the accuracy at a fixed number of bits compares with the counters’ — since a sketch spends its space on every value and a summary spends it on the few that matter, and the sweep on this page is precisely about whether the few that matter on one side matter on the other.

Named alongside this one

Essays reaching for the same objects. Nobody chose these; they are what the concept index makes visible.

What links here

Every essay whose body links to this one.

The objects this essay names

Each one links to every other essay that touches it.

Cardinality estimationCorrelationHeavy hitterJoin orderMisra–GriesQuery plannerRegretSkewSummaryUpper boundZipf