Skip to content

feat(query): add rule_grouping_sets_to_union #18413

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

Merged
merged 92 commits into from
Jul 28, 2025

Conversation

sundy-li
Copy link
Member

@sundy-li sundy-li commented Jul 24, 2025

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

feat(query): add rule_grouping_sets_to_union

add a new setting grouping_sets_to_union which apply this rule (default disabled)

Split Grouping Sets into Union All of Group by
Eg:

select number % 10 AS a, number % 3 AS b, number % 4 AS c
from numbers(100000000)
group by grouping sets((a,b),(a,c));

INTO:

select number % 10 AS a, number % 3 AS b, number % 4 AS c
from numbers(100000000)
group by a,b
union all
select number % 10 AS a, number % 3 AS b, number % 4 AS c
from numbers(100000000)
group by a,c

And with CTE integration after pr #18226

with _t as (select * from numbers(100000000))
select number % 10 AS a, number % 3 AS b, null AS c
from _t
group by a,b
union all
select number % 10 AS a, null AS b, number % 4 AS c
from _t
group by a,c

performance 2X:

explain analyze select  number % 10 a, number % 3 b, number % 4 c, number % 5 d, number % 6 e, number % 7 f from numbers(100000000) group by cube(a, b, c, d, e, f);

--main: Res 3.7GB, 14s
--pr : Res 2.1GB, 6.8s

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@sundy-li sundy-li marked this pull request as ready for review July 27, 2025 11:58
@sundy-li sundy-li marked this pull request as draft July 27, 2025 15:17
@sundy-li sundy-li marked this pull request as ready for review July 27, 2025 15:24
@sundy-li sundy-li requested review from zhang2014 and SkyFan2002 July 28, 2025 06:26
@RinChanNOWWW
Copy link
Contributor

Is function grouping still supported when enable grouping_sets_to_union?

@sundy-li sundy-li merged commit 91e76f1 into databendlabs:main Jul 28, 2025
89 checks passed
@sundy-li sundy-li deleted the rule_grouping_sets_to_union branch July 28, 2025 09:26
@sundy-li sundy-li added the ci-cloud Build docker image for cloud test label Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-cloud Build docker image for cloud test pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants