-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Changes from 11 commits
1ec1e66
546735e
457f508
c06138c
99d861c
cea0ed9
98814cb
0483828
c039b72
a4262bb
5d364a1
b26a884
c7c179f
335bc48
0537a98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
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 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new added |
||
{Scope: ScopeGlobal | ScopeSession, Name: TiDBRowFormatVersion, Value: strconv.Itoa(DefTiDBRowFormatV1), Type: TypeUnsigned, MinValue: 1, MaxValue: 2, SetGlobal: func(s *SessionVars, val string) error { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add your test into |
||
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") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This list keeps the |
||
) | ||
|
||
// TiDB intentional limits | ||
|
@@ -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 | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't put the |
||
) | ||
|
||
var ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
ScopeGlobal | ScopeSession
.