Skip to content

Conversation

@xanderbailey
Copy link
Contributor

@xanderbailey xanderbailey commented Nov 14, 2025

Which issue does this PR close?

More detail is in the issue.

Rationale for this change

This is a pretty major correctness issue.

What changes are included in this PR?

Fixes issue and reorders skip aggregate and emit early within partial aggregate execution

Are these changes tested?

Yes, the unit test that's added here previously failed before this change.

Are there any user-facing changes?

@github-actions github-actions bot added the physical-plan Changes to the physical-plan crate label Nov 14, 2025
@xanderbailey xanderbailey changed the title Fix aggregate race Fix Partial AggregateExec correctness issue dropping rows Nov 14, 2025
// Check if we should switch to skip aggregation mode
// It's important that we do this before we early emit since we've
// already updated the probe.
if let Some(new_state) = self.switch_to_skip_aggregation()? {
Copy link
Contributor Author

@xanderbailey xanderbailey Nov 15, 2025

Choose a reason for hiding this comment

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

It's unclear to me why we set update_skip_aggregation_probe here https://github.com/apache/datafusion/pull/18712/files#diff-69c8ecaca5e2c7005f2ed1facaa41f80b45bfd006f2357e53ff3072f535c287dL687 and not next to switch_to_skip_aggregation. I can't fully give an explanation yet but allowing the probe to be updated and then allowing the look to break before we get here seems dangerous? It's important that we emit everything before we move to the SkipAggregation state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@korowa does that make sense to you?

@xanderbailey xanderbailey force-pushed the xb/fix_aggregate_race branch 2 times, most recently from b28fce0 to 353b11b Compare November 15, 2025 15:34

ExecutionState::Done => {
// Sanity check: all groups should have been emitted by now
if !self.group_values.is_empty() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding some protection here to try and avoid bugs like this happening in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather fail the query than return the wrong / incomplete results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Partial AggregateExec correctness issue dropping rows

1 participant