Same top-K, three regimes
Same top-K, three regimes
pick by working set and exactness, never by habit or a universal threshold
regime
hash aggregation
external sort
sketch: approximate
working set fits
distinct keys in RAM
WINS: one pass
exact, fastest here
works
pays extra I/O
overkill
exactness is cheap here
working set exceeds
RAM: must spill
spills, or OOMs
death is not slowness
WINS: finishes
degrades with I/O
option
if error is allowed
top-100 approx
error budget given
sample first
then count exactly
possible
stop after top-K
WINS: tiny memory
bounded error only
teaching demo: 200k lines, 19,782 distinct, 10 spilled runs, identical top-5 on both paths
rule: measure your cap, your disk, your cardinality, then choose; no universal URL count exists
legend: green wins the row, pink fails or risks failing, white merely works