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

planner: introduce tidb_general_plan_cache_size for general plan cache #37087

Merged
merged 15 commits into from
Aug 16, 2022
9 changes: 9 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,15 @@ var defaultSysVars = []*SysVar{
}, GetGlobal: func(s *SessionVars) (string, error) {
return BoolToOnOff(EnableTmpStorageOnOOM.Load()), nil
}},
{Scope: ScopeGlobal, Name: TiDBGeneralPlanCacheSize, Value: strconv.FormatUint(uint64(DefTiDBGeneralPlanCacheSize), 10), Type: TypeUnsigned, MinValue: 0, MaxValue: 100000, SetGlobal: func(s *SessionVars, val string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ScopeGlobal | ScopeSession.

uVal, err := strconv.ParseUint(val, 10, 64)
if err == nil {
GeneralPlanCacheSize.Store(uVal)
}
return err
}, GetGlobal: func(s *SessionVars) (string, error) {
return strconv.FormatUint(GeneralPlanCacheSize.Load(), 10), nil
}},

/* The system variables below have GLOBAL and SESSION scope */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new added global && session variables should be added to this part.

{Scope: ScopeGlobal | ScopeSession, Name: TiDBRowFormatVersion, Value: strconv.Itoa(DefTiDBRowFormatV1), Type: TypeUnsigned, MinValue: 1, MaxValue: 2, SetGlobal: func(s *SessionVars, val string) error {
Expand Down
22 changes: 22 additions & 0 deletions sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,3 +1159,25 @@ func TestSetTIDBDiskQuota(t *testing.T) {
require.NoError(t, err)
require.Equal(t, strconv.FormatInt(pb, 10), val)
}

func TestGeneralPlanCache(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add your test into executor/set_test.go:TestSetVar.

vars := NewSessionVars()
mock := NewMockGlobalAccessor4Tests()
mock.SessionVars = vars
vars.GlobalVarsAccessor = mock
val, err := vars.GetGlobalSystemVar(TiDBGeneralPlanCacheSize)
require.NoError(t, err)
require.Equal(t, val, "100")
require.NoError(t, vars.GlobalVarsAccessor.SetGlobalSysVar(TiDBGeneralPlanCacheSize, "1000"))
val, err = vars.GetGlobalSystemVar(TiDBGeneralPlanCacheSize)
require.NoError(t, err)
require.Equal(t, val, "1000")
require.NoError(t, vars.GlobalVarsAccessor.SetGlobalSysVar(TiDBGeneralPlanCacheSize, "-1"))
val, err = vars.GetGlobalSystemVar(TiDBGeneralPlanCacheSize)
require.NoError(t, err)
require.Equal(t, val, "0")
require.NoError(t, vars.GlobalVarsAccessor.SetGlobalSysVar(TiDBGeneralPlanCacheSize, "1000000"))
val, err = vars.GetGlobalSystemVar(TiDBGeneralPlanCacheSize)
require.NoError(t, err)
require.Equal(t, val, "100000")
}
5 changes: 5 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,8 @@ const (
TiDBDDLEnableFastReorg = "tidb_ddl_fast_reorg"
// TiDBDDLDiskQuota used to set disk quota for lightning add index.
TiDBDDLDiskQuota = "tidb_ddl_disk_quota"
// TiDBGeneralPlanCacheSize controls the size of general plan cache. 0 indicate close.
TiDBGeneralPlanCacheSize = "tidb_general_plan_cache_size"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list keeps the global-only variables. See line 722.

)

// TiDB intentional limits
Expand Down Expand Up @@ -1007,6 +1009,7 @@ const (
DefTiDBEnableFastReorg = false
DefTiDBDDLDiskQuota = 100 * 1024 * 1024 * 1024 // 100GB
DefExecutorConcurrency = 5
DefTiDBGeneralPlanCacheSize = 100
// MaxDDLReorgBatchSize is exported for testing.
MaxDDLReorgBatchSize int32 = 10240
MinDDLReorgBatchSize int32 = 32
Expand Down Expand Up @@ -1058,6 +1061,8 @@ var (
EnableFastReorg = atomic.NewBool(DefTiDBEnableFastReorg)
// DDLDiskQuota is the temporary variable for set disk quota for lightning
DDLDiskQuota = atomic.NewInt64(DefTiDBDDLDiskQuota)
// GeneralPlanCacheSize is a variable for general plan cache
GeneralPlanCacheSize = atomic.NewUint64(DefTiDBGeneralPlanCacheSize)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't put the GeneralPlanCacheSize here. The list only contains the global-only variables. See line 1019

)

var (
Expand Down