Skip to content

Commit 8d6161c

Browse files
authored
planner: disable LOCK IN SHARE MODE by default (#19506) (#21005)
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
1 parent c1a0077 commit 8d6161c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

expression/integration_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6980,6 +6980,19 @@ func (s *testIntegrationSerialSuite) TestIssue19045(c *C) {
69806980
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"))
69816981
}
69826982

6983+
func (s *testIntegrationSerialSuite) TestIssue19383(c *C) {
6984+
tk := testkit.NewTestKit(c, s.store)
6985+
tk.MustExec("use test")
6986+
tk.MustExec("DROP TABLE IF EXISTS t1")
6987+
tk.MustExec("CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY)")
6988+
tk.MustExec("INSERT INTO t1 VALUES (1),(2),(3)")
6989+
_, err := tk.Exec("SELECT * FROM t1 LOCK IN SHARE MODE")
6990+
message := `function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions`
6991+
c.Assert(strings.Contains(err.Error(), message), IsTrue)
6992+
tk.MustExec("SET tidb_enable_noop_functions=1")
6993+
tk.MustExec("SELECT * FROM t1 LOCK IN SHARE MODE")
6994+
}
6995+
69836996
func (s *testIntegrationSerialSuite) TestIssue19315(c *C) {
69846997
tk := testkit.NewTestKit(c, s.store)
69856998
tk.MustExec("use test")

planner/core/logical_plan_builder.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,7 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L
25032503
// table hints are only visible in the current SELECT statement.
25042504
b.popTableHints()
25052505
}()
2506-
2506+
enableNoopFuncs := b.ctx.GetSessionVars().EnableNoopFuncs
25072507
if sel.SelectStmtOpts != nil {
25082508
origin := b.inStraightJoin
25092509
b.inStraightJoin = sel.SelectStmtOpts.StraightJoin
@@ -2572,6 +2572,10 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L
25722572
}
25732573

25742574
if sel.LockTp != ast.SelectLockNone {
2575+
if sel.LockTp == ast.SelectLockInShareMode && !enableNoopFuncs {
2576+
err = expression.ErrFunctionsNoopImpl.GenWithStackByArgs("LOCK IN SHARE MODE")
2577+
return nil, err
2578+
}
25752579
p = b.buildSelectLock(p, sel.LockTp)
25762580
}
25772581
b.handleHelper.popMap()

0 commit comments

Comments
 (0)