-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Do not sort rows in FirstValueAccumulator
#14402
base: main
Are you sure you want to change the base?
Conversation
|
let indices = lexsort_to_indices(&sort_cols, None)?; | ||
take_arrays(&filtered_states, &indices, None)? | ||
}; | ||
let comparator = LexicographicalComparator::try_new(&sort_columns)?; |
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.
In lexsort_to_indices
there are some additional optimizations when there's just one column - so I also wrote a version which reuses lexsort_to_indices
- but the speed increase there is actually 20% smaller than here
@@ -3003,7 +3003,7 @@ SELECT FIRST_VALUE(amount ORDER BY ts ASC) AS fv1, | |||
LAST_VALUE(amount ORDER BY ts ASC) AS fv2 | |||
FROM sales_global | |||
---- | |||
30 100 | |||
30 80 |
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.
IMO, it actually makes more sense because that line has the same ORDER BY
value but appears last in the table.
fyi @jayzhan211 |
} | ||
let comparator = LexicographicalComparator::try_new(&sort_columns)?; | ||
let best = (0..value.len()) | ||
.filter(|&index| !(self.ignore_nulls && value.is_null(index))) |
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.
If we make 'ignore nulls' a constant generic, it might be faster than we can avoid filter logic for null if we don't ignore nulls
Which issue does this PR close?
Closes #14215
Rationale for this change
Right now, merging / updating batches in
first_value
/last_value
we sometimes sort input to find just one max / min row. In some cases, we request to sort only top-1 value but even that produces extra index buffers...What changes are included in this PR?
Instead of sorting arrays, just finding min / max directly.
Are these changes tested?
Yes, by
aggregate.slt
. Also added new benches to illustrate the speed improvementAre there any user-facing changes?
No