-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Case evaluation improvements #17898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Case evaluation improvements #17898
Conversation
- Short circuit evaluation when selection vector is all false - Avoid filtering record batch when selection vector is all true
bb647a5
to
3b75814
Compare
@alamb could you trigger a benchmark run on this PR (once CI gives the green light)? |
🤖 |
🤖: Benchmark completed Details
|
Small improvement (which is what I had expected). WDYT, worth integrating? Edit: I had a closer look at the The example I'm looking at locally is a projection where a classification category is being associated with each row using a large case expression. Something like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it is worth pursing to me -- thanks @pepijnve
I wonder if we can factor out the pattern of "don't call evaluate_selection if the selection is still the entire remainder (mostly so we can document the behavior / make sure this it doesn't get lost in some future refactoring)
Maybe something we could wrap the count in some structure or a function
🤔
let mut remainder = Remainder::new(batch.num_rows());
remainder.update(&self.when_then_expr[i], &batch);
let mut current_value = new_null_array(&return_type, batch.num_rows()); | ||
// We only consider non-null values while comparing with whens | ||
let mut remainder = not(&base_nulls)?; | ||
let mut remainder_count = remainder.true_count(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have found in past evaluations, that the code generated for true_count
is astonishingly fast (it uses some special hardware instruction) so I am not surprised this works well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know that that’s fairly cheap.
What I’m experimenting with is retaining the filtered record batch from one loop iteration to the next so that the amount of data to be churned through each iteration shrinks.
🤖 |
🤖: Benchmark completed Details
|
Which issue does this PR close?
None yet
Rationale for this change
Speculative performance improvements for case evaluation
What changes are included in this PR?
Are these changes tested?
(Hopefully) covered by SQL logic tests
Are there any user-facing changes?
No