Skip to content

fix: Streaming aggregation produces wrong result with grouping sets - #24422

Merged
2010YOUY01 merged 2 commits into
apache:mainfrom
2010YOUY01:fix-grouping-sets-ordering
Aug 19, 2026
Merged

fix: Streaming aggregation produces wrong result with grouping sets#24422
2010YOUY01 merged 2 commits into
apache:mainfrom
2010YOUY01:fix-grouping-sets-ordering

Conversation

@2010YOUY01

@2010YOUY01 2010YOUY01 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

The aggregation planning will enable ordering optimization when the grouping sets is available, however they're not compatible now.

I'm also not sure if we want to enable ordering optimization for grouping sets in the future, since this seems requires extra implementation complexity.

This PR disables ordering/streaming aggregation optimization when grouping set is present.

Reference for ordering optimization in aggregation:

What changes are included in this PR?

  • 80cb8ee: reproducer that fails without the fix
  • 5673f3e: fix. It disables ordering optimization when grouping set is present

Are these changes tested?

slt

Are there any user-facing changes?

no

@github-actions github-actions Bot added core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) physical-plan Changes to the physical-plan crate labels Aug 17, 2026
@codecov-commenter

codecov-commenter commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.23%. Comparing base (1f0615a) to head (5673f3e).
⚠️ Report is 33 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/physical-plan/src/aggregates/mod.rs 96.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24422      +/-   ##
==========================================
+ Coverage   81.17%   81.23%   +0.05%     
==========================================
  Files        1109     1112       +3     
  Lines      388117   390652    +2535     
  Branches   388117   390652    +2535     
==========================================
+ Hits       315071   317352    +2281     
- Misses      54504    54660     +156     
- Partials    18542    18640      +98     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

InputOrderMode::Linear
};

// Ordering optimization is not compatible with grouping sets

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to add some comments or todo for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks!

@2010YOUY01
2010YOUY01 force-pushed the fix-grouping-sets-ordering branch from 4ddfc45 to 5673f3e Compare August 17, 2026 08:39
@alamb

alamb commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

I'm also not sure if we want to enable ordering optimization for grouping sets in the future, since this seems requires extra implementation complexity.

I don't think so - as there is no one ordering I think that will satisfy all the groupings

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @2010YOUY01 and @zhuqi-lucas

Is this fixing a regression in df 55 (aka there are potentially wrong results in df 55 that were correct in df 54)? If so, I'll add it to the df 55.1 tracking ticket

@2010YOUY01

Copy link
Copy Markdown
Contributor Author

Thanks @2010YOUY01 and @zhuqi-lucas

Is this fixing a regression in df 55 (aka there are potentially wrong results in df 55 that were correct in df 54)? If so, I'll add it to the df 55.1 tracking ticket

@alamb No, I've checked this bug can also be reproduced in datafusion 54.0.0, and I believe this bug has always been there.


Thank you for the review @zhuqi-lucas and @alamb , let's merge it.

@2010YOUY01
2010YOUY01 added this pull request to the merge queue Aug 19, 2026
Merged via the queue into apache:main with commit 5c846af Aug 19, 2026
41 checks passed
@2010YOUY01
2010YOUY01 deleted the fix-grouping-sets-ordering branch August 19, 2026 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate physical-plan Changes to the physical-plan crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streaming aggregation produces wrong result with grouping sets

4 participants