Skip to content
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

planner: do not eliminate group_concat in aggregate elimination #9967

Merged
merged 5 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ func (s *testSuite1) TestAggEliminator(c *C) {
tk.MustQuery("select min(b) from t").Check(testkit.Rows("-2"))
tk.MustQuery("select max(b*b) from t").Check(testkit.Rows("4"))
tk.MustQuery("select min(b*b) from t").Check(testkit.Rows("1"))
tk.MustQuery("select group_concat(b, b) from t group by a").Check(testkit.Rows("-1-1", "-2-2", "11", "<nil>"))
}

func (s *testSuite1) TestMaxMinFloatScalaFunc(c *C) {
Expand Down
13 changes: 13 additions & 0 deletions planner/core/rule_aggregation_elimination.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ type aggregationEliminateChecker struct {
// For count(expr), sum(expr), avg(expr), count(distinct expr, [expr...]) we may need to rewrite the expr. Details are shown below.
// If we can eliminate agg successful, we return a projection. Else we return a nil pointer.
func (a *aggregationEliminateChecker) tryToEliminateAggregation(agg *LogicalAggregation) *LogicalProjection {
for _, af := range agg.AggFuncs {
// TODO: Actually, we can rewrite GROUP_CONCAT.
// When it accepts only 1 argument, we can extract this argument into a
Copy link
Member

Choose a reason for hiding this comment

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

This case is easy to be added in this pr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noop, since group_concat_max_len is configurable.
We can not ensure whether the length of the final result exceeds max_len even if there is only 1 argument.

And, maybe it'll be easier to implement if we wrap the argument(s) into a concat_ws despite the count of the arguments.

// projection.
// When it accepts multiple arguments, we can wrap the arguments with a
// function CONCAT_WS and extract this function into a projection.
// BUT, GROUP_CONCAT should truncate the final result according to the
// system variable `group_concat_max_len`. To ensure the correctness of
// the result, we close the elimination of GROUP_CONCAT here.
XuHuaiyu marked this conversation as resolved.
Show resolved Hide resolved
if af.Name == ast.AggFuncGroupConcat {
return nil
XuHuaiyu marked this conversation as resolved.
Show resolved Hide resolved
}
}
schemaByGroupby := expression.NewSchema(agg.groupByCols...)
coveredByUniqueKey := false
for _, key := range agg.children[0].Schema().Keys {
Expand Down