Skip to content

Commit 65af315

Browse files
committed
Fix: grouping sets missing.
1 parent b407e6a commit 65af315

File tree

5 files changed

+36
-16
lines changed

5 files changed

+36
-16
lines changed

src/query/sql/src/planner/binder/aggregate.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,11 @@ impl Binder {
542542
);
543543
}
544544

545+
// If it's `GROUP BY GROUPING SETS`, ignore the optimization below.
546+
if collect_grouping_sets {
547+
return Ok(());
548+
}
549+
545550
// Remove dependent group items, group by a, f(a, b), f(a), b ---> group by a,b
546551
let mut results = vec![];
547552
for item in bind_context.aggregate_info.group_items.iter() {

tests/sqllogictests/suites/duckdb/sql/aggregate/group/group_by_grouping_sets.test

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ select (number % 2) as a from numbers(5) group by grouping sets (a) order by a;
44
0
55
1
66

7+
query TT
8+
select number % 2 as a, number % 3 as b from numbers(24) group by grouping sets ((a,b), (a), (b)) order by a,b;
9+
----
10+
0 0
11+
0 1
12+
0 2
13+
0 NULL
14+
1 0
15+
1 1
16+
1 2
17+
1 NULL
18+
NULL 0
19+
NULL 1
20+
NULL 2
21+
722

823
statement ok
924
drop table if exists t;
@@ -41,4 +56,4 @@ b NULL 11 1 0 1 2
4156
NULL NULL 18 1 1 3 3
4257

4358
statement ok
44-
drop table t all;
59+
drop table t all;

tests/sqllogictests/suites/mode/standalone/explain/limit.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Limit
8181
├── aggregate functions: []
8282
├── estimated rows: 0.33
8383
└── Filter
84-
├── filters: [is_true(CAST(t.number (#0) AS UInt64 NULL) = TRY_CAST(if(CAST(is_not_null(scalar_subquery_5 (#5)) AS Boolean NULL), CAST(CATCH(scalar_subquery_5 (#5)) AS Tuple(Int64 NULL, String NULL)), (0, NULL)) AS UInt64 NULL))]
84+
├── filters: [is_true(CAST(t.number (#0) AS UInt64 NULL) = TRY_CAST(if(CAST(is_not_null(scalar_subquery_5 (#5)) AS Boolean NULL), CAST(scalar_subquery_5 (#5) AS Int64 NULL), 0) AS UInt64 NULL))]
8585
├── estimated rows: 0.33
8686
└── HashJoin
8787
├── join type: SINGLE

tests/sqllogictests/suites/mode/standalone/explain/select.test

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ Filter
9999
├── estimated rows: 0.00
100100
└── TableScan
101101
├── table: default.system.numbers
102-
├── read rows: 1
103-
├── read bytes: 8
104-
├── partitions total: 1
105-
├── partitions scanned: 1
102+
├── read rows: 0
103+
├── read bytes: 0
104+
├── partitions total: 0
105+
├── partitions scanned: 0
106106
├── push downs: [filters: [false], limit: NONE]
107107
└── estimated rows: 1.00
108108

@@ -114,10 +114,10 @@ Filter
114114
├── estimated rows: 0.00
115115
└── TableScan
116116
├── table: default.system.numbers
117-
├── read rows: 1
118-
├── read bytes: 8
119-
├── partitions total: 1
120-
├── partitions scanned: 1
117+
├── read rows: 0
118+
├── read bytes: 0
119+
├── partitions total: 0
120+
├── partitions scanned: 0
121121
├── push downs: [filters: [false], limit: NONE]
122122
└── estimated rows: 1.00
123123

@@ -129,10 +129,10 @@ Filter
129129
├── estimated rows: 0.00
130130
└── TableScan
131131
├── table: default.system.numbers
132-
├── read rows: 1
133-
├── read bytes: 8
134-
├── partitions total: 1
135-
├── partitions scanned: 1
132+
├── read rows: 0
133+
├── read bytes: 0
134+
├── partitions total: 0
135+
├── partitions scanned: 0
136136
├── push downs: [filters: [false], limit: NONE]
137137
└── estimated rows: 1.00
138138

tests/sqllogictests/suites/mode/standalone/explain/subquery.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ query T
22
explain select t.number from numbers(1) as t, numbers(1) as t1 where t.number = (select count(*) from numbers(1) as t2, numbers(1) as t3 where t.number = t2.number)
33
----
44
Filter
5-
├── filters: [is_true(CAST(t.number (#0) AS UInt64 NULL) = TRY_CAST(if(CAST(is_not_null(scalar_subquery_5 (#5)) AS Boolean NULL), CAST(CATCH(scalar_subquery_5 (#5)) AS Tuple(Int64 NULL, String NULL)), (0, NULL)) AS UInt64 NULL))]
5+
├── filters: [is_true(CAST(t.number (#0) AS UInt64 NULL) = TRY_CAST(if(CAST(is_not_null(scalar_subquery_5 (#5)) AS Boolean NULL), CAST(scalar_subquery_5 (#5) AS Int64 NULL), 0) AS UInt64 NULL))]
66
├── estimated rows: 0.33
77
└── HashJoin
88
├── join type: SINGLE
@@ -337,7 +337,7 @@ query T
337337
explain select t.number from numbers(1) as t, numbers(1) as t1 where (select count(*) = 1 from numbers(1) where t.number = number) and t.number = t1.number
338338
----
339339
Filter
340-
├── filters: [is_true(try_to_boolean(TRY_CAST(if(CAST(is_not_null(scalar_subquery_4 (#4)) AS Boolean NULL), CAST(CATCH(TRY_CAST(scalar_subquery_4 (#4) AS UInt64 NULL)) AS Tuple(Int64 NULL, String NULL)), (0, NULL)) AS UInt64 NULL)))]
340+
├── filters: [is_true(try_to_boolean(TRY_CAST(if(CAST(is_not_null(scalar_subquery_4 (#4)) AS Boolean NULL), CAST(TRY_CAST(scalar_subquery_4 (#4) AS UInt64 NULL) AS Int64 NULL), 0) AS UInt64 NULL)))]
341341
├── estimated rows: 0.33
342342
└── HashJoin
343343
├── join type: SINGLE

0 commit comments

Comments
 (0)