diff --git a/executor/aggregate_test.go b/executor/aggregate_test.go index 5bd7fe00ae207..d2a64108354fb 100644 --- a/executor/aggregate_test.go +++ b/executor/aggregate_test.go @@ -580,6 +580,16 @@ func (s *testSuite1) TestIssue13652(c *C) { c.Assert(err.Error(), Equals, "[planner:1055]Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t.a' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by") } +func (s *testSuite1) TestIssue14947(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 int)") + tk.MustQuery("select ((+a+1)) as tmp from t group by tmp") + tk.MustQuery("select count(*), (case when a=1 then 0 else 2 end) as xx from t group by xx;") +} + func (s *testSuite1) TestHaving(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index cab17c946c623..83cfdb8070325 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -1754,7 +1754,7 @@ func (b *PlanBuilder) checkOnlyFullGroupByWithGroupClause(p LogicalPlan, sel *as if field.Auxiliary { continue } - checkExprInGroupBy(p, field.Expr, offset, ErrExprInSelect, gbyCols, gbyExprs, notInGbyCols) + checkExprInGroupBy(p, getInnerFromParenthesesAndUnaryPlus(field.Expr), offset, ErrExprInSelect, gbyCols, gbyExprs, notInGbyCols) } if sel.OrderBy != nil {