An ORDER BY query is chunked up and parallelized based on region boundaries
A split occurs after this, but before the results come back
The results we get back from a parallel scan will potentially no longer be ordered according to the ORDER BY, as if the scan was split up between different regions (unbeknownst to us), there'd be a point at which the order is wrong
We should write a unit test for this first, and then there are different ways of solving it:
While buffering the results, detect an out-of-order row and "insert" a new ResultIterator that will take part in the merge sort.
Perform the ORDER BY on the client side for each parallel scan results instead of on the server-side (this is the approach we've taken with GROUP BY).
There's an edge case for ORDER BY processing:
We should write a unit test for this first, and then there are different ways of solving it: