Skip to content
About
Main content

What probabilistic structures forbid

Why store sketches rather than estimates?

The rule that is violated most often: store the sketch, not the estimate

A mergeable does not compound error. Merging 30 daily produces exactly the sketch you would have built from the full month, so the error of the monthly figure equals the error of one daily figure. But storing approx_count_distinct(day) as a number and summing across days is not approximately right. It is wrong, by the amount of cross-day overlap (a parcel scanned on Monday and Tuesday is counted twice), and the error grows with the number of days combined. The same applies to quantiles. A rollup table whose columns are sketches is a different kind of object from one whose columns are numbers, and the difference is that the first one composes.

This is also the answer to a question that is easy to miss: how does error behave when sketches feed sketches?

What this article forbids

  • Exact distinct counting in sublinear space.
  • Exact quantiles in bounded space.
  • Any estimator with error better than 1/√m from m observations (the ).
  • Cardinality estimation from a uniform sample.
  • Sub-quadratic exact all-pairs similarity.
  • In general: any question whose answer is not a function of the statistic the sketch kept. HLL cannot intersect, Count-Min cannot see the tail, a sample cannot count distinct values, a filter cannot list its contents.

There is one more, and it has operational teeth: you cannot recover the data from the sketch. Sketching is an early decision about the question. A rollup table of HLL sketches keyed by day and three dimensions has committed you to those dimensions. A fourth dimension means reprocessing the raw data, if you still have it. , and the bill arrives months later, when someone asks a reasonable question that the pipeline structurally cannot answer.

Escapes and their costs

EscapeCost
Keep the raw data next to the sketchthe space you were saving (usually still correct)
Choose a sketch with more algebraic closure (Theta instead of HLL)more space per unit of accuracy; buys intersections
Two tiers: exact structures for the head, sketches for the tail, or a sampled exact store next to a full sketchtwo systems to run
Restrict the question, not the answer (exact top-k by a , from Ordering structures)nothing; the best escape when it is available, because it costs no accuracy
Buy more memoryat the square-root exchange rate: 4 times the memory for half the error