Always track the final size of the in-mem sorted arrays #3753
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #3747.
Rationale for this change
This code removes the assumption that the unsorted array's size and the sorted array's size is always the same or less (as discussed in #3747). Now we always do a final check on whether there is any size mismatch, and if we find one we record it so that the next iterations can decide whether to spill or not in a more reliable fashion.
What changes are included in this PR?
Fixes the broken check that assumes
size(sorted_arr) <= size(input_arr). We also now record the changes in size no matter whether there is a propagated limit or not, since thesizemight actually be different without any change in the underlying data.Are there any user-facing changes?
This is a fix/correction of two problems, the first one is the wrong check mentioned in #3747 and the second one is the wrong calculation of in-memory sorted arrays where the final result actually takes more space than we initially assumed it would.