perf: Fix quadratic behavior of to_array_of_size#20459
Open
neilconway wants to merge 9 commits intoapache:mainfrom
Open
perf: Fix quadratic behavior of to_array_of_size#20459neilconway wants to merge 9 commits intoapache:mainfrom
to_array_of_size#20459neilconway wants to merge 9 commits intoapache:mainfrom
Conversation
Contributor
Author
|
Benchmarks: |
Contributor
Author
|
I see #18159 already exists for this issue; I'll be optimistic and claim this PR closes it... 😅 |
Contributor
Author
|
We could consider backing out the special-case logic in NLJ that was introduced in #18161, but that will require some consideration and benchmarking first. I tried a quick hack to remove the NLJ workaround but it hurt performance on a microbenchmark by ~15% |
Contributor
|
@Dandandan FYI |
comphead
approved these changes
Feb 22, 2026
Contributor
comphead
left a comment
There was a problem hiding this comment.
Thanks @neilconway the solution is elegant and makes a lot of sense
comphead
reviewed
Feb 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
ScalarValue::to_array_of_sizeis slow for StringViewArray with many buffers #20458.Utf8Viewarray buffers inScalarValue::to_array_of_size()#18159.Rationale for this change
When
array_to_size(n)was called on aList-like object containing aStringViewArraywithbdata buffers, the previous implementation returned a list containing aStringViewArraywithn*bbuffers, which results in catastrophically bad performance ifbgrows even somewhat large.This issue was previously noticed causing poor nested loop join performance. #18161 adjusted the NLJ code to avoid calling
to_array_of_sizefor this reason, but didn't attempt to fix the underlying issue into_array_of_size. This PR doesn't attempt to revert the change to the NLJ code: the special-case code added in #18161 is still slightly faster thanto_array_of_sizeafter this optimization. It might be possible to address that in a future PR.What changes are included in this PR?
repeat_n+concatto merge togetherncopies of theStringViewArray, we instead usetake, which preserves the same number of buffers as the inputStringViewArray.to_array_of_sizeAre these changes tested?
Yes and benchmarked.
Are there any user-facing changes?
No.
AI usage
Iterated on the problem with Claude Code; I understand the problem and the solution.