From 9876de8961277e45fe432b56bd46ff24733af059 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] planner: disable SQL_CALC_FOUND_ROWS/LOCK IN SHARE MODE by default (#19506) --- expression/integration_test.go | 17 +++++++++++++++++ planner/core/logical_plan_builder.go | 11 +++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 3418588e44..d43190ed2e 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7226,6 +7226,23 @@ func (s *testIntegrationSerialSuite) TestIssue19116(c *C) { 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") +} + 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 3d67b1201b..685be8d4ef 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2604,8 +2604,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 }() @@ -2671,8 +2675,11 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L return nil, err } } - 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) } b.handleHelper.popMap()