From 24c9b99aa9f84c709c06625ff4ac645de4e2fe51 Mon Sep 17 00:00:00 2001 From: Kenan Yao Date: Mon, 4 Mar 2019 18:52:44 +0800 Subject: [PATCH] planner: fix false negative "full group by" check for agg in subquery (#9542) --- planner/core/expression_rewriter_test.go | 15 +++++++++++++++ planner/core/logical_plan_builder.go | 2 ++ 2 files changed, 17 insertions(+) diff --git a/planner/core/expression_rewriter_test.go b/planner/core/expression_rewriter_test.go index 61b2624c64e76..cff8f38ee1db0 100644 --- a/planner/core/expression_rewriter_test.go +++ b/planner/core/expression_rewriter_test.go @@ -152,3 +152,18 @@ 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()) +} diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 32cc9a60b9ffc..380feeeaac1a4 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -1495,6 +1495,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 }