What ordering structures forbid
Which kinds of order can no structure give, and what does each escape cost?
What this article forbids
- You cannot output ordered results before you have read all input: sorting is blocking by construction. That makes it impossible on an unbounded stream and memory-hungry on a bounded one.
- You cannot establish a total order in parallel without first partitioning the domain, which means you cannot sort in parallel without an estimate of the distribution.
- You cannot maintain order incrementally without paying on every write.
- You cannot physically sort a dataset by more than one key.
The escapes and what each costs
| Escape | What it costs |
|---|---|
| Partial order (heap) | You can answer nothing except "what is next". It buys bounded memory with exactness when the question is top-k |
| Range partitioning | A sampling pass and exposure to skew: the sort's runtime is the maximum over tasks, so one bad boundary sets the stage duration |
| Bounded disorder (watermarks, LSM level structure, nearly sorted input) | An assumption you cannot verify, paid by whoever produced the record that violated it |
| Precomputed order (clustered, bucketed or sorted tables) | Write-time work, and lock-in to exactly one order; it pays off after a computable number of queries |
| Restricting the question, not the answer (top-k, monotonic windows) | The cheapest escape, because it costs no accuracy. Always check for it before reaching for approximation |
| Approximation | The last escape and the subject of Probabilistic structures |