Skip to content

Commit 9876de8

Browse files
author
Null not nil
authored
planner: disable SQL_CALC_FOUND_ROWS/LOCK IN SHARE MODE by default (#19506)
1 parent 653dffe commit 9876de8

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

expression/integration_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7226,6 +7226,23 @@ func (s *testIntegrationSerialSuite) TestIssue19116(c *C) {
72267226
tk.MustQuery("select coercibility(1=1);").Check(testkit.Rows("5"))
72277227
}
72287228

7229+
func (s *testIntegrationSerialSuite) TestIssue14448and19383(c *C) {
7230+
tk := testkit.NewTestKit(c, s.store)
7231+
tk.MustExec("use test")
7232+
tk.MustExec("DROP TABLE IF EXISTS t1")
7233+
tk.MustExec("CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY)")
7234+
tk.MustExec("INSERT INTO t1 VALUES (1),(2),(3)")
7235+
_, err := tk.Exec("SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1")
7236+
message := `function SQL_CALC_FOUND_ROWS has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions`
7237+
c.Assert(strings.Contains(err.Error(), message), IsTrue)
7238+
_, err = tk.Exec("SELECT * FROM t1 LOCK IN SHARE MODE")
7239+
message = `function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions`
7240+
c.Assert(strings.Contains(err.Error(), message), IsTrue)
7241+
tk.MustExec("SET tidb_enable_noop_functions=1")
7242+
tk.MustExec("SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1")
7243+
tk.MustExec("SELECT * FROM t1 LOCK IN SHARE MODE")
7244+
}
7245+
72297246
func (s *testIntegrationSerialSuite) TestIssue19315(c *C) {
72307247
tk := testkit.NewTestKit(c, s.store)
72317248
tk.MustExec("use test")

planner/core/logical_plan_builder.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,8 +2604,12 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L
26042604
// table hints are only visible in the current SELECT statement.
26052605
b.popTableHints()
26062606
}()
2607-
2607+
enableNoopFuncs := b.ctx.GetSessionVars().EnableNoopFuncs
26082608
if sel.SelectStmtOpts != nil {
2609+
if sel.SelectStmtOpts.CalcFoundRows && !enableNoopFuncs {
2610+
err = expression.ErrFunctionsNoopImpl.GenWithStackByArgs("SQL_CALC_FOUND_ROWS")
2611+
return nil, err
2612+
}
26092613
origin := b.inStraightJoin
26102614
b.inStraightJoin = sel.SelectStmtOpts.StraightJoin
26112615
defer func() { b.inStraightJoin = origin }()
@@ -2671,8 +2675,11 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L
26712675
return nil, err
26722676
}
26732677
}
2674-
26752678
if sel.LockInfo != nil && sel.LockInfo.LockType != ast.SelectLockNone {
2679+
if sel.LockInfo.LockType == ast.SelectLockInShareMode && !enableNoopFuncs {
2680+
err = expression.ErrFunctionsNoopImpl.GenWithStackByArgs("LOCK IN SHARE MODE")
2681+
return nil, err
2682+
}
26762683
p = b.buildSelectLock(p, sel.LockInfo)
26772684
}
26782685
b.handleHelper.popMap()

0 commit comments

Comments
 (0)