From 89bb38d0a206a24a0c6c945acb8f1c5c93816a34 Mon Sep 17 00:00:00 2001 From: Yifan Xu <30385241+xuyifangreeneyes@users.noreply.github.com> Date: Fri, 16 Jul 2021 15:01:33 +0800 Subject: [PATCH 1/2] planner: add some comment for checkOnlyFullGroupBy (#25769) --- planner/core/logical_plan_builder.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index c8a4a2e4e9a3c..bcda8eb5dcd37 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2745,6 +2745,28 @@ func checkColFuncDepend( Name: colInfo.Name, } pIdx, err := expression.FindFieldName(p.OutputNames(), pkName) + // It is possible that `pIdx < 0` and here is a case. + // ``` + // CREATE TABLE `BB` ( + // `pk` int(11) NOT NULL AUTO_INCREMENT, + // `col_int_not_null` int NOT NULL, + // PRIMARY KEY (`pk`) + // ); + // + // SELECT OUTR . col2 AS X + // FROM + // BB AS OUTR2 + // INNER JOIN + // (SELECT col_int_not_null AS col1, + // pk AS col2 + // FROM BB) AS OUTR ON OUTR2.col_int_not_null = OUTR.col1 + // GROUP BY OUTR2.col_int_not_null; + // ``` + // When we enter `checkColFuncDepend`, `pkName.Table` is `OUTR` which is an alias, while `pkName.Name` is `pk` + // which is a original name. Hence `expression.FindFieldName` will fail and `pIdx` will be less than 0. + // Currently, when we meet `pIdx < 0`, we directly regard `primaryFuncDepend` as false and jump out. This way is + // easy to implement but makes only-full-group-by checker not smart enough. Later we will refactor only-full-group-by + // checker and resolve the inconsistency between the alias table name and the original column name. if err != nil || pIdx < 0 { primaryFuncDepend = false break From 1f6c6698b3237162ba18b70a31d8b80c17fd3b44 Mon Sep 17 00:00:00 2001 From: wuliuqii <34090258+wuliuqii@users.noreply.github.com> Date: Fri, 16 Jul 2021 15:09:33 +0800 Subject: [PATCH 2/2] *: fix some errcheck (#25855) --- ddl/ddl_worker_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ddl/ddl_worker_test.go b/ddl/ddl_worker_test.go index 72fef7c96c19e..5085e4194f0d1 100644 --- a/ddl/ddl_worker_test.go +++ b/ddl/ddl_worker_test.go @@ -100,7 +100,10 @@ func (s *testDDLSuite) TestNotifyDDLJob(c *C) { WithStore(store), WithLease(testLease), ) - defer d.Stop() + defer func() { + err := d.Stop() + c.Assert(err, IsNil) + }() getFirstNotificationAfterStartDDL(d) // Ensure that the notification is not handled in workers `start` function. d.cancel() @@ -141,7 +144,10 @@ func (s *testDDLSuite) TestNotifyDDLJob(c *C) { WithStore(store), WithLease(testLease), ) - defer d1.Stop() + defer func() { + err := d1.Stop() + c.Assert(err, IsNil) + }() getFirstNotificationAfterStartDDL(d1) // Ensure that the notification is not handled by worker's "start". d1.cancel()