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

executor: refine the check of onlyFullGroupBy when groupByItem is parenthesesExpr or UnaryPlusExpr (#13655) #16145

Merged
merged 4 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
14 changes: 14 additions & 0 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,20 @@ func (s *testSuite) TestOnlyFullGroupBy(c *C) {
c.Assert(terror.ErrorEqual(err, plannercore.ErrAmbiguous), IsTrue, Commentf("err %v", err))
}

func (s *testSuite) TestIssue13652(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set sql_mode = 'ONLY_FULL_GROUP_BY'")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a real)")
tk.MustQuery("select a from t group by (a)")
tk.MustQuery("select a from t group by ((a))")
tk.MustQuery("select a from t group by +a")
tk.MustQuery("select a from t group by ((+a))")
_, err := tk.Exec("select a from t group by (-a)")
c.Assert(err.Error(), Equals, "[planner:1055]Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'a' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by")
}

func (s *testSuite) TestHaving(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)

Expand Down
5 changes: 3 additions & 2 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1538,14 +1538,15 @@ func (b *planBuilder) checkOnlyFullGroupByWithGroupClause(p LogicalPlan, sel *as
gbyExprs := make([]ast.ExprNode, 0, len(sel.Fields.Fields))
schema := p.Schema()
for _, byItem := range sel.GroupBy.Items {
if colExpr, ok := byItem.Expr.(*ast.ColumnNameExpr); ok {
expr := getInnerFromParenthesesAndUnaryPlus(byItem.Expr)
if colExpr, ok := expr.(*ast.ColumnNameExpr); ok {
col, err := schema.FindColumn(colExpr.Name)
if err != nil || col == nil {
continue
}
gbyCols[col] = struct{}{}
} else {
gbyExprs = append(gbyExprs, byItem.Expr)
gbyExprs = append(gbyExprs, expr)
}
}

Expand Down