Skip to content

Commit

Permalink
executor, session, sessionctx: make last_plan_from_cache and last_pla…
Browse files Browse the repository at this point in the history
…n_from_binding read-only (pingcap#21953)
  • Loading branch information
TszKitLo40 authored and Jianke Tang committed Dec 25, 2020
1 parent bfc06d4 commit 787b255
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
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

0 comments on commit 787b255

Please sign in to comment.