diff --git a/src/query/sql/src/planner/binder/aggregate.rs b/src/query/sql/src/planner/binder/aggregate.rs index fe5a85696197..9433c6c4ee43 100644 --- a/src/query/sql/src/planner/binder/aggregate.rs +++ b/src/query/sql/src/planner/binder/aggregate.rs @@ -462,21 +462,9 @@ impl Binder { /// Generate GroupingSets from CUBE (expr1, expr2, ...) fn generate_cube_sets(exprs: Vec) -> Vec> { - let mut result = Vec::new(); - let n = exprs.len(); - - // Iterate through all possible subsets of the given expressions - for i in 0..(1 << n) { - let mut subset = Vec::new(); - for (j, expr) in exprs.iter().enumerate() { - if (i & (1 << j)) != 0 { - subset.push(expr.clone()); - } - } - result.push(subset); - } - - result + (0..=exprs.len()) + .flat_map(|count| exprs.clone().into_iter().combinations(count)) + .collect::>() } /// Generate GroupingSets from ROLLUP (expr1, expr2, ...)