Skip to content
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

Simplify update_skip_aggregation_probe method #12332

Merged
merged 3 commits into from
Sep 26, 2024

Conversation

lewiszlw
Copy link
Member

@lewiszlw lewiszlw commented Sep 5, 2024

Which issue does this PR close?

Closes #.

Rationale for this change

What changes are included in this PR?

Spilling only happens when mode is not AggregateMode::Partial,

&& !matches!(self.mode, AggregateMode::Partial)

but skipping agg probe only happens when mode is AggregateMode::Partial.
let skip_aggregation_probe = if agg.mode == AggregateMode::Partial

So there is no spilling when skip_aggregation_probe is Option::Some.

Are these changes tested?

Are there any user-facing changes?

@lewiszlw lewiszlw marked this pull request as draft September 5, 2024 06:34
@github-actions github-actions bot added the physical-expr Physical Expressions label Sep 5, 2024
@lewiszlw lewiszlw marked this pull request as ready for review September 5, 2024 06:56
@@ -1024,11 +1017,7 @@ impl GroupedHashAggregateStream {
/// Note: currently spilling is not supported for Partial aggregation
fn update_skip_aggregation_probe(&mut self, input_rows: usize) {
if let Some(probe) = self.skip_aggregation_probe.as_mut() {
if !self.spill_state.spills.is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now partial aggregation only do early emit indeed, but I guess this check is trying to be defensive, if someone decides to do spilling in the partial stage also, the early emit logic won't be break 🤔 Maybe we can leave an assertion here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #7400, the author tried spilling in partial stage, but he was asked to remove that. See #7400 (comment).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this check is trying to be defensive

Yes, that was the idea -- these features are mutually exclusive, with current implementation of spilling, but if they both are triggered (which never happens for now -- probably the note should be more informative) it shouldn't break query execution.

I think the change is reasonable since current code is redundant indeed, but not sure about assertion -- I suppose it's better to return not_implemented / internal error instead of panicking.

And it's probably worth to retain the note on why skip partial is incompatible with spilling.

Copy link
Contributor

@Rachelint Rachelint Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add another assert to ensure and emphasize that the update_state is only called in Partial mode?

IMO, when we are sure that some branches are actually unreacheable, assertion may be nice that it can let us easier to find the bug through tests?

...
assert!(self.spill_state.spills.is_empty() && self.mode == AggregateMode::Partial);
probe.update_state(input_rows, self.group_values.len());
...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree -- adding an assertion would be great. Can you perhaps make a PR to do so?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have submitted a pr about this #12640

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Let's get this merged 🚀

cc @Rachelint

@alamb
Copy link
Contributor

alamb commented Sep 25, 2024

I took the liberty of merging up from main to resolve a conflict

@alamb alamb merged commit 524e56d into apache:main Sep 26, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants