Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor, session, sessionctx: make last_plan_from_cache and last_plan_from_binding read-only #21953

Merged
merged 9 commits into from
Dec 24, 2020
8 changes: 0 additions & 8 deletions executor/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,6 @@ func (e *SetExecutor) setSysVariable(name string, v *expression.VarAssignment) e
if name == variable.TxnIsolationOneShot && sessionVars.InTxn() {
return errors.Trace(ErrCantChangeTxCharacteristics)
}
if name == variable.TiDBFoundInPlanCache {
sessionVars.StmtCtx.AppendWarning(fmt.Errorf("Set operation for '%s' will not take effect", variable.TiDBFoundInPlanCache))
return nil
}
if name == variable.TiDBFoundInBinding {
sessionVars.StmtCtx.AppendWarning(fmt.Errorf("Set operation for '%s' will not take effect", variable.TiDBFoundInBinding))
return nil
}
err = variable.SetSessionSystemVar(sessionVars, name, value)
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3810,3 +3810,12 @@ func (s *testSessionSerialSuite) TestIssue21944(c *C) {
_, err := tk1.Exec("set @@tidb_current_ts=1;")
c.Assert(err.Error(), Equals, "[variable:1238]Variable 'tidb_current_ts' is a read only variable")
}

func (s *testSessionSerialSuite) TestIssue21943(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
_, err := tk.Exec("set @@last_plan_from_binding='123';")
c.Assert(err.Error(), Equals, "[variable:1238]Variable 'last_plan_from_binding' is a read only variable")

_, err = tk.Exec("set @@last_plan_from_cache='123';")
c.Assert(err.Error(), Equals, "[variable:1238]Variable 'last_plan_from_cache' is a read only variable")
}
4 changes: 2 additions & 2 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,8 +1131,8 @@ var defaultSysVars = []*SysVar{
{Scope: ScopeSession, Name: TiDBEnableSlowLog, Value: BoolToOnOff(logutil.DefaultTiDBEnableSlowLog), Type: TypeBool},
{Scope: ScopeSession, Name: TiDBQueryLogMaxLen, Value: strconv.Itoa(logutil.DefaultQueryLogMaxLen), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64},
{Scope: ScopeSession, Name: TiDBCheckMb4ValueInUTF8, Value: BoolToOnOff(config.GetGlobalConfig().CheckMb4ValueInUTF8), Type: TypeBool},
{Scope: ScopeSession, Name: TiDBFoundInPlanCache, Value: BoolToOnOff(DefTiDBFoundInPlanCache), Type: TypeBool},
{Scope: ScopeSession, Name: TiDBFoundInBinding, Value: BoolToOnOff(DefTiDBFoundInBinding), Type: TypeBool},
{Scope: ScopeSession, Name: TiDBFoundInPlanCache, Value: BoolToOnOff(DefTiDBFoundInPlanCache), Type: TypeBool, ReadOnly: true},
{Scope: ScopeSession, Name: TiDBFoundInBinding, Value: BoolToOnOff(DefTiDBFoundInBinding), Type: TypeBool, ReadOnly: true},
{Scope: ScopeSession, Name: TiDBEnableCollectExecutionInfo, Value: BoolToOnOff(DefTiDBEnableCollectExecutionInfo), Type: TypeBool},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBAllowAutoRandExplicitInsert, Value: BoolToOnOff(DefTiDBAllowAutoRandExplicitInsert), Type: TypeBool},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableClusteredIndex, Value: BoolToOnOff(DefTiDBEnableClusteredIndex), Type: TypeBool},
Expand Down
12 changes: 2 additions & 10 deletions sessionctx/variable/varsutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,18 +466,10 @@ func (s *testVarsutilSuite) TestVarsutil(c *C) {
c.Assert(err, ErrorMatches, ".*Incorrect argument type to variable 'tidb_stmt_summary_max_sql_length'")

err = SetSessionSystemVar(v, TiDBFoundInPlanCache, types.NewStringDatum("1"))
c.Assert(err, IsNil)
val, err = GetSessionSystemVar(v, TiDBFoundInPlanCache)
c.Assert(err, IsNil)
c.Assert(val, Equals, "OFF")
c.Assert(v.systems[TiDBFoundInPlanCache], Equals, "ON")
c.Assert(err, ErrorMatches, ".*]Variable 'last_plan_from_cache' is a read only variable")

err = SetSessionSystemVar(v, TiDBFoundInBinding, types.NewStringDatum("1"))
c.Assert(err, IsNil)
val, err = GetSessionSystemVar(v, TiDBFoundInBinding)
c.Assert(err, IsNil)
c.Assert(val, Equals, "OFF")
c.Assert(v.systems[TiDBFoundInBinding], Equals, "ON")
c.Assert(err, ErrorMatches, ".*]Variable 'last_plan_from_binding' is a read only variable")

err = SetSessionSystemVar(v, TiDBEnableChangeColumnType, types.NewStringDatum("ON"))
c.Assert(err, IsNil)
Expand Down