diff --git a/planner/core/expression_rewriter_test.go b/planner/core/expression_rewriter_test.go index 805c81e7d3449..034634685e237 100644 --- a/planner/core/expression_rewriter_test.go +++ b/planner/core/expression_rewriter_test.go @@ -15,6 +15,8 @@ package core_test import ( . "github.com/pingcap/check" + "github.com/pingcap/parser/terror" + "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" "github.com/pingcap/tidb/util/testutil" @@ -223,3 +225,20 @@ func (s *testExpressionRewriterSuite) TestCompareSubquery(c *C) { )) tk.MustQuery("select * from t t1 where b = all (select a from t t2)").Check(testkit.Rows()) } + +func (s *testExpressionRewriterSuite) TestCheckFullGroupBy(c *C) { + defer testleak.AfterTest(c)() + store, dom, err := newStoreWithBootstrap() + c.Assert(err, IsNil) + tk := testkit.NewTestKit(c, store) + defer func() { + dom.Close() + store.Close() + }() + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int, b int)") + tk.MustQuery("select t1.a, (select max(t2.b) from t t2) from t t1").Check(testkit.Rows()) + err = tk.ExecToErr("select t1.a, (select t2.a, max(t2.b) from t t2) from t t1") + c.Assert(terror.ErrorEqual(err, core.ErrMixOfGroupFuncAndFields), IsTrue, Commentf("err %v", err)) +} diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 968fef7b23a3e..645ae6cb07278 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -1693,6 +1693,8 @@ func (c *colResolverForOnlyFullGroupBy) Enter(node ast.Node) (ast.Node, bool) { c.firstNonAggCol, c.firstNonAggColIdx = t.Name, c.exprIdx } return node, true + case *ast.SubqueryExpr: + return node, true } return node, false }