perf: Optimize array_has() for scalar needle#20374
Open
neilconway wants to merge 2 commits intoapache:mainfrom
Open
perf: Optimize array_has() for scalar needle#20374neilconway wants to merge 2 commits intoapache:mainfrom
neilconway wants to merge 2 commits intoapache:mainfrom
Conversation
The previous implementation tested the cost of building an array_has() `Expr` (!), not actually evaluating the array_has() operation itself. Refactor things along the way.
Contributor
Author
|
Benchmarks: |
getChan
approved these changes
Feb 16, 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?
array_has()for scalar needle #20377.Rationale for this change
compare_with_eq()checks for matching array elements via a single pass across the entire flat values buffer, which is reasonably fast. The previous implementation then determined per-row results by creating a BooleanArray slice for each row and callingtrue_count()to check for any matches. It turns out that that's quite a lot of per-row work.Instead, we use
BooleanBuffer::set_indices()to iterate over the set bits in the comparison result in a single forward pass. We walk this iterator in lockstep with the row offsets to determine whether each row contains a match, which does much less work per-row.This can be substantially faster, especially for short arrays. For example, for 10-element arrays of int64, it is 3-5x faster than the previous approach. 10-element string arrays are 1.6-4.8x faster. The improvement is smaller but non-zero for larger arrays (e.g., ~1.2x faster for 500 element arrays).
What changes are included in this PR?
In addition to the optimization, this commit adjusts the
array_hasbenchmark code to actually benchmarkarray_hasevaluation (!). The previous benchmark just constructed anExpr.Are these changes tested?
Yes. Passes existing tests. Performance validated via several benchmark runs.
Are there any user-facing changes?
No.