Affects Version/s: 1.11.0
Fix Version/s: 1.12.0
Consider the log file attached to
DRILL-5513. The log shows an excessive number of buffer reallocations while assembling the merged output of the sort:
Hundreds of these lines appear. This means that the initial buffer allocation is too small.
Given that the merge phase knows the number of rows it will put into the batch, and has access to the "sizer" information to estimate Varchar widths, the merge phase should predict, and allocate, the required buffer sizes to avoid repeated reallocation. Each reallocation requires:
- Allocate new buffer (which puts memory pressure on the sort's memory)
- Copy data from old to new buffer
- Zero-fill the new half (zero-fill is not done on the first allocation, strangely.)
- Free the unneeded original buffer.
Since the sort is already slow, the above extra work just makes the problem worse.