Skip to content

Commit fc9738b

Browse files
authored
planner: defer grouping function validation to expression rewriting logic (#45663)
close #45661
1 parent 1bf82bb commit fc9738b

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

planner/core/casetest/enforcempp/testdata/enforce_mpp_suite_in.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@
211211
"explain format = 'brief' select a+1, grouping(b) from t group by a+1, b with rollup; -- 7. resolve field list a+1 to grouping set column a+1",
212212
"explain format = 'brief' SELECT SUM(profit) AS profit FROM sales GROUP BY year+2, year+profit WITH ROLLUP order by year+2; -- 8. order by item year+2 resolve to gby grouping expression",
213213
"explain format = 'brief' SELECT year+2, SUM(profit) AS profit FROM sales GROUP BY year+2, year+profit WITH ROLLUP order by year+2; -- 9. order by item year+2 resolve to select field",
214-
"explain format = 'brief' SELECT year+2 as y, SUM(profit) as profit FROM sales GROUP BY year+2, year+profit WITH ROLLUP having y > 2002 order by year+2, profit; -- 10. having (year+2) shouldn't be pushed down"
214+
"explain format = 'brief' SELECT year+2 as y, SUM(profit) as profit FROM sales GROUP BY year+2, year+profit WITH ROLLUP having y > 2002 order by year+2, profit; -- 10. having (year+2) shouldn't be pushed down",
215+
"explain format = 'brief' SELECT year+2 as y, SUM(profit) AS profit, grouping(year+2) FROM sales GROUP BY year+2, year+profit WITH ROLLUP having y > 2002 order by year+2, profit; -- 11. grouping function validation"
215216
]
216217
}
217218
]

planner/core/casetest/enforcempp/testdata/enforce_mpp_suite_out.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,25 @@
21022102
" └─TableFullScan 10000.00 mpp[tiflash] table:sales keep order:false, stats:pseudo"
21032103
],
21042104
"Warn": null
2105+
},
2106+
{
2107+
"SQL": "explain format = 'brief' SELECT year+2 as y, SUM(profit) AS profit, grouping(year+2) FROM sales GROUP BY year+2, year+profit WITH ROLLUP having y > 2002 order by year+2, profit; -- 11. grouping function validation",
2108+
"Plan": [
2109+
"Sort 6400.00 root Column#6, Column#9",
2110+
"└─TableReader 6400.00 root MppVersion: 2, data:ExchangeSender",
2111+
" └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: PassThrough",
2112+
" └─Projection 6400.00 mpp[tiflash] Column#6, Column#9, grouping(gid)->Column#10",
2113+
" └─Projection 6400.00 mpp[tiflash] Column#9, Column#6, gid",
2114+
" └─HashAgg 6400.00 mpp[tiflash] group by:Column#29, Column#30, Column#31, funcs:sum(Column#26)->Column#9, funcs:firstrow(Column#27)->Column#6, funcs:firstrow(Column#28)->gid",
2115+
" └─Projection 8000.00 mpp[tiflash] cast(test.sales.profit, decimal(10,0) BINARY)->Column#26, Column#6->Column#27, gid->Column#28, Column#6->Column#29, Column#7->Column#30, gid->Column#31",
2116+
" └─ExchangeReceiver 8000.00 mpp[tiflash] ",
2117+
" └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#6, collate: binary], [name: Column#7, collate: binary], [name: gid, collate: binary]",
2118+
" └─Selection 8000.00 mpp[tiflash] gt(Column#6, 2002)",
2119+
" └─Expand 10000.00 mpp[tiflash] level-projection:[test.sales.profit, <nil>->Column#6, <nil>->Column#7, 0->gid],[test.sales.profit, Column#6, <nil>->Column#7, 1->gid],[test.sales.profit, Column#6, Column#7, 3->gid]; schema: [test.sales.profit,Column#6,Column#7,gid]",
2120+
" └─Projection 10000.00 mpp[tiflash] test.sales.profit, plus(test.sales.year, 2)->Column#6, plus(test.sales.year, test.sales.profit)->Column#7",
2121+
" └─TableFullScan 10000.00 mpp[tiflash] table:sales keep order:false, stats:pseudo"
2122+
],
2123+
"Warn": null
21052124
}
21062125
]
21072126
}

planner/core/logical_plan_builder.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,6 +3542,13 @@ func checkExprInGroupByOrIsSingleValue(
35423542
if _, ok := expr.(*ast.AggregateFuncExpr); ok {
35433543
return
35443544
}
3545+
if f, ok := expr.(*ast.FuncCallExpr); ok {
3546+
if f.FnName.L == ast.Grouping {
3547+
// just skip grouping function check here, because later in building plan phase, we
3548+
// will do the grouping function valid check.
3549+
return
3550+
}
3551+
}
35453552
if _, ok := expr.(*ast.ColumnNameExpr); !ok {
35463553
for _, gbyExpr := range gbyExprs {
35473554
if ast.ExpressionDeepEqual(gbyExpr, expr) {

0 commit comments

Comments
 (0)