From 046fd4febce03b3652d7770200edddb8ae4ff2e0 Mon Sep 17 00:00:00 2001 From: Null not nil <67764674+nullnotnil@users.noreply.github.com> Date: Fri, 18 Sep 2020 05:18:37 -0600 Subject: [PATCH 1/2] cherry pick #19506 to release-4.0 Signed-off-by: ti-srebot --- expression/integration_test.go | 37 ++++++++++++++++++++++++++++ planner/core/logical_plan_builder.go | 15 ++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 86b92118dc8be..d96fcc59aa4f6 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6971,6 +6971,43 @@ func (s *testIntegrationSerialSuite) TestIssue19045(c *C) { tk.MustQuery(`select ( SELECT t1.a FROM t1, t2 WHERE t1.b = t2.a AND t2.b = '03' AND t1.c = a.a) invode from t a ;`).Check(testkit.Rows("a011", "a011")) } +<<<<<<< HEAD +======= +func (s *testIntegrationSerialSuite) TestIssue19116(c *C) { + collate.SetNewCollationEnabledForTest(true) + defer collate.SetNewCollationEnabledForTest(false) + + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("set names utf8mb4 collate utf8mb4_general_ci;") + tk.MustQuery("select collation(concat(1 collate `binary`));").Check(testkit.Rows("binary")) + tk.MustQuery("select coercibility(concat(1 collate `binary`));").Check(testkit.Rows("0")) + tk.MustQuery("select collation(concat(NULL,NULL));").Check(testkit.Rows("binary")) + tk.MustQuery("select coercibility(concat(NULL,NULL));").Check(testkit.Rows("6")) + tk.MustQuery("select collation(concat(1,1));").Check(testkit.Rows("utf8mb4_general_ci")) + tk.MustQuery("select coercibility(concat(1,1));").Check(testkit.Rows("4")) + tk.MustQuery("select collation(1);").Check(testkit.Rows("binary")) + tk.MustQuery("select coercibility(1);").Check(testkit.Rows("5")) + tk.MustQuery("select coercibility(1=1);").Check(testkit.Rows("5")) +} + +func (s *testIntegrationSerialSuite) TestIssue14448and19383(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("DROP TABLE IF EXISTS t1") + tk.MustExec("CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY)") + tk.MustExec("INSERT INTO t1 VALUES (1),(2),(3)") + _, err := tk.Exec("SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1") + message := `function SQL_CALC_FOUND_ROWS has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions` + c.Assert(strings.Contains(err.Error(), message), IsTrue) + _, err = tk.Exec("SELECT * FROM t1 LOCK IN SHARE MODE") + message = `function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions` + c.Assert(strings.Contains(err.Error(), message), IsTrue) + tk.MustExec("SET tidb_enable_noop_functions=1") + tk.MustExec("SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1") + tk.MustExec("SELECT * FROM t1 LOCK IN SHARE MODE") +} + +>>>>>>> 9876de896... planner: disable SQL_CALC_FOUND_ROWS/LOCK IN SHARE MODE by default (#19506) func (s *testIntegrationSerialSuite) TestIssue19315(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 0bef4438aedbe..0797f85ecb359 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2503,8 +2503,12 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L // table hints are only visible in the current SELECT statement. b.popTableHints() }() - + enableNoopFuncs := b.ctx.GetSessionVars().EnableNoopFuncs if sel.SelectStmtOpts != nil { + if sel.SelectStmtOpts.CalcFoundRows && !enableNoopFuncs { + err = expression.ErrFunctionsNoopImpl.GenWithStackByArgs("SQL_CALC_FOUND_ROWS") + return nil, err + } origin := b.inStraightJoin b.inStraightJoin = sel.SelectStmtOpts.StraightJoin defer func() { b.inStraightJoin = origin }() @@ -2570,9 +2574,18 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L return nil, err } } +<<<<<<< HEAD if sel.LockTp != ast.SelectLockNone { p = b.buildSelectLock(p, sel.LockTp) +======= + if sel.LockInfo != nil && sel.LockInfo.LockType != ast.SelectLockNone { + if sel.LockInfo.LockType == ast.SelectLockInShareMode && !enableNoopFuncs { + err = expression.ErrFunctionsNoopImpl.GenWithStackByArgs("LOCK IN SHARE MODE") + return nil, err + } + p = b.buildSelectLock(p, sel.LockInfo) +>>>>>>> 9876de896... planner: disable SQL_CALC_FOUND_ROWS/LOCK IN SHARE MODE by default (#19506) } b.handleHelper.popMap() b.handleHelper.pushMap(nil) From 8d7f6ff3ae8e9e544b4f25134a6452bad26cdd92 Mon Sep 17 00:00:00 2001 From: Null not nil Date: Sun, 15 Nov 2020 19:38:51 -0700 Subject: [PATCH 2/2] Fix conflicts. --- expression/integration_test.go | 30 +++------------------------- planner/core/logical_plan_builder.go | 13 ++---------- 2 files changed, 5 insertions(+), 38 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index d96fcc59aa4f6..f63afcc688f0a 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6971,43 +6971,19 @@ func (s *testIntegrationSerialSuite) TestIssue19045(c *C) { tk.MustQuery(`select ( SELECT t1.a FROM t1, t2 WHERE t1.b = t2.a AND t2.b = '03' AND t1.c = a.a) invode from t a ;`).Check(testkit.Rows("a011", "a011")) } -<<<<<<< HEAD -======= -func (s *testIntegrationSerialSuite) TestIssue19116(c *C) { - collate.SetNewCollationEnabledForTest(true) - defer collate.SetNewCollationEnabledForTest(false) - - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("set names utf8mb4 collate utf8mb4_general_ci;") - tk.MustQuery("select collation(concat(1 collate `binary`));").Check(testkit.Rows("binary")) - tk.MustQuery("select coercibility(concat(1 collate `binary`));").Check(testkit.Rows("0")) - tk.MustQuery("select collation(concat(NULL,NULL));").Check(testkit.Rows("binary")) - tk.MustQuery("select coercibility(concat(NULL,NULL));").Check(testkit.Rows("6")) - tk.MustQuery("select collation(concat(1,1));").Check(testkit.Rows("utf8mb4_general_ci")) - tk.MustQuery("select coercibility(concat(1,1));").Check(testkit.Rows("4")) - tk.MustQuery("select collation(1);").Check(testkit.Rows("binary")) - tk.MustQuery("select coercibility(1);").Check(testkit.Rows("5")) - tk.MustQuery("select coercibility(1=1);").Check(testkit.Rows("5")) -} - -func (s *testIntegrationSerialSuite) TestIssue14448and19383(c *C) { +func (s *testIntegrationSerialSuite) TestIssue19383(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("DROP TABLE IF EXISTS t1") tk.MustExec("CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY)") tk.MustExec("INSERT INTO t1 VALUES (1),(2),(3)") - _, err := tk.Exec("SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1") - message := `function SQL_CALC_FOUND_ROWS has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions` - c.Assert(strings.Contains(err.Error(), message), IsTrue) - _, err = tk.Exec("SELECT * FROM t1 LOCK IN SHARE MODE") - message = `function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions` + _, err := tk.Exec("SELECT * FROM t1 LOCK IN SHARE MODE") + message := `function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions` c.Assert(strings.Contains(err.Error(), message), IsTrue) tk.MustExec("SET tidb_enable_noop_functions=1") - tk.MustExec("SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1") tk.MustExec("SELECT * FROM t1 LOCK IN SHARE MODE") } ->>>>>>> 9876de896... planner: disable SQL_CALC_FOUND_ROWS/LOCK IN SHARE MODE by default (#19506) func (s *testIntegrationSerialSuite) TestIssue19315(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 0797f85ecb359..5c3a3bc7fbbeb 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2505,10 +2505,6 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L }() enableNoopFuncs := b.ctx.GetSessionVars().EnableNoopFuncs if sel.SelectStmtOpts != nil { - if sel.SelectStmtOpts.CalcFoundRows && !enableNoopFuncs { - err = expression.ErrFunctionsNoopImpl.GenWithStackByArgs("SQL_CALC_FOUND_ROWS") - return nil, err - } origin := b.inStraightJoin b.inStraightJoin = sel.SelectStmtOpts.StraightJoin defer func() { b.inStraightJoin = origin }() @@ -2574,18 +2570,13 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L return nil, err } } -<<<<<<< HEAD if sel.LockTp != ast.SelectLockNone { - p = b.buildSelectLock(p, sel.LockTp) -======= - if sel.LockInfo != nil && sel.LockInfo.LockType != ast.SelectLockNone { - if sel.LockInfo.LockType == ast.SelectLockInShareMode && !enableNoopFuncs { + if sel.LockTp == ast.SelectLockInShareMode && !enableNoopFuncs { err = expression.ErrFunctionsNoopImpl.GenWithStackByArgs("LOCK IN SHARE MODE") return nil, err } - p = b.buildSelectLock(p, sel.LockInfo) ->>>>>>> 9876de896... planner: disable SQL_CALC_FOUND_ROWS/LOCK IN SHARE MODE by default (#19506) + p = b.buildSelectLock(p, sel.LockTp) } b.handleHelper.popMap() b.handleHelper.pushMap(nil)