Documentation ¶
Index ¶
- Constants
- Variables
- func GetDDLReorgWorkerCounter() int32
- func GetGlobalSystemVar(s *SessionVars, key string) (string, error)
- func GetScopeNoneSystemVar(key string) (string, bool, error)
- func GetSessionOnlySysVars(s *SessionVars, key string) (string, bool, error)
- func GetSessionSystemVar(s *SessionVars, key string) (string, error)
- func GetStatusVars(vars *SessionVars) (map[string]*StatusVal, error)
- func GoTimeToTS(t time.Time) uint64
- func RegisterStatistics(s Statistics)
- func SetDDLReorgWorkerCounter(cnt int32)
- func SetSessionSystemVar(vars *SessionVars, name string, value types.Datum) error
- func TiDBOptOn(opt string) bool
- func ValidateGetSystemVar(name string, isGlobal bool) error
- func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, error)
- type BatchSize
- type Concurrency
- type GlobalVarAccessor
- type MemQuota
- type MockGlobalAccessor
- type RetryInfo
- type ScopeFlag
- type SessionVars
- func (s *SessionVars) AllocPlanColumnID() int64
- func (s *SessionVars) CleanBuffers()
- func (s *SessionVars) GetCharsetInfo() (charset, collation string)
- func (s *SessionVars) GetNextPreparedStmtID() uint32
- func (s *SessionVars) GetStatusFlag(flag uint16) bool
- func (s *SessionVars) GetSystemVar(name string) (string, bool)
- func (s *SessionVars) GetWriteStmtBufs() *WriteStmtBufs
- func (s *SessionVars) InTxn() bool
- func (s *SessionVars) IsAutocommit() bool
- func (s *SessionVars) Location() *time.Location
- func (s *SessionVars) ResetPrevAffectedRows()
- func (s *SessionVars) SetLastInsertID(insertID uint64)
- func (s *SessionVars) SetStatusFlag(flag uint16, on bool)
- func (s *SessionVars) SetSystemVar(name string, val string) error
- type Statistics
- type StatusVal
- type SysVar
- type TableDelta
- type TransactionContext
- type WriteStmtBufs
Constants ¶
const ( SQLModeVar = "sql_mode" AutocommitVar = "autocommit" CharacterSetResults = "character_set_results" MaxAllowedPacket = "max_allowed_packet" TimeZone = "time_zone" TxnIsolation = "tx_isolation" TxnIsolationOneShot = "tx_isolation_one_shot" )
special session variables.
const ( CodeUnknownStatusVar terror.ErrCode = 1 CodeUnknownSystemVar terror.ErrCode = mysql.ErrUnknownSystemVariable CodeIncorrectScope terror.ErrCode = mysql.ErrIncorrectGlobalLocalVar CodeUnknownTimeZone terror.ErrCode = mysql.ErrUnknownTimeZone CodeReadOnly terror.ErrCode = mysql.ErrVariableIsReadonly CodeWrongValueForVar terror.ErrCode = mysql.ErrWrongValueForVar CodeWrongTypeForVar terror.ErrCode = mysql.ErrWrongTypeForVar CodeTruncatedWrongValue terror.ErrCode = mysql.ErrTruncatedWrongValue )
Variable error codes.
const ( // CharacterSetConnection is the name for character_set_connection system variable. CharacterSetConnection = "character_set_connection" // CollationConnection is the name for collation_connection system variable. CollationConnection = "collation_connection" // CharsetDatabase is the name for character_set_database system variable. CharsetDatabase = "character_set_database" // CollationDatabase is the name for collation_database system variable. CollationDatabase = "collation_database" // GeneralLog is the name for 'general_log' system variable. GeneralLog = "general_log" // AvoidTemporalUpgrade is the name for 'avoid_temporal_upgrade' system variable. AvoidTemporalUpgrade = "avoid_temporal_upgrade" // BigTables is the name for 'big_tables' system variable. BigTables = "big_tables" // CheckProxyUsers is the name for 'check_proxy_users' system variable. CheckProxyUsers = "check_proxy_users" // CoreFile is the name for 'core_file' system variable. CoreFile = "core_file" // DefaultWeekFormat is the name for 'default_week_format' system variable. DefaultWeekFormat = "default_week_format" // GroupConcatMaxLen is the name for 'group_concat_max_len' system variable. GroupConcatMaxLen = "group_concat_max_len" // DelayKeyWrite is the name for 'delay_key_write' system variable. DelayKeyWrite = "delay_key_write" // EndMakersInJSON is the name for 'end_markers_in_json' system variable. EndMakersInJSON = "end_markers_in_json" // InnodbCommitConcurrency is the name for 'innodb_commit_concurrency' system variable. InnodbCommitConcurrency = "innodb_commit_concurrency" // InnodbFastShutdown is the name for 'innodb_fast_shutdown' system variable. InnodbFastShutdown = "innodb_fast_shutdown" // InnodbLockWaitTimeout is the name for 'innodb_lock_wait_timeout' system variable. InnodbLockWaitTimeout = "innodb_lock_wait_timeout" // SQLLogBin is the name for 'sql_log_bin' system variable. SQLLogBin = "sql_log_bin" // MaxSortLength is the name for 'max_sort_length' system variable. MaxSortLength = "max_sort_length" // MaxSpRecursionDepth is the name for 'max_sp_recursion_depth' system variable. MaxSpRecursionDepth = "max_sp_recursion_depth" // MaxUserConnections is the name for 'max_user_connections' system variable. MaxUserConnections = "max_user_connections" // OfflineMode is the name for 'offline_mode' system variable. OfflineMode = "offline_mode" // InteractiveTimeout is the name for 'interactive_timeout' system variable. InteractiveTimeout = "interactive_timeout" // FlushTime is the name for 'flush_time' system variable. FlushTime = "flush_time" // PseudoSlaveMode is the name for 'pseudo_slave_mode' system variable. PseudoSlaveMode = "pseudo_slave_mode" // LowPriorityUpdates is the name for 'low_priority_updates' system variable. LowPriorityUpdates = "low_priority_updates" // SessionTrackGtids is the name for 'session_track_gtids' system variable. SessionTrackGtids = "session_track_gtids" // OldPasswords is the name for 'old_passwords' system variable. OldPasswords = "old_passwords" // MaxConnections is the name for 'max_connections' system variable. MaxConnections = "max_connections" // SkipNameResolve is the name for 'skip_name_resolve' system variable. SkipNameResolve = "skip_name_resolve" // ForeignKeyChecks is the name for 'foreign_key_checks' system variable. ForeignKeyChecks = "foreign_key_checks" // SQLSafeUpdates is the name for 'sql_safe_updates' system variable. SQLSafeUpdates = "sql_safe_updates" // WarningCount is the name for 'warning_count' system variable. WarningCount = "warning_count" // ErrorCount is the name for 'error_count' system variable. ErrorCount = "error_count" // SQLSelectLimit is the name for 'sql_select_limit' system variable. SQLSelectLimit = "sql_select_limit" // MaxConnectErrors is the name for 'max_connect_errors' system variable. MaxConnectErrors = "max_connect_errors" // TableDefinitionCache is the name for 'table_definition_cache' system variable. TableDefinitionCache = "table_definition_cache" // TmpTableSize is the name for 'tmp_table_size' system variable. TmpTableSize = "tmp_table_size" // ConnectTimeout is the name for 'connect_timeout' system variable. ConnectTimeout = "connect_timeout" // SyncBinlog is the name for 'sync_binlog' system variable. SyncBinlog = "sync_binlog" // BlockEncryptionMode is the name for 'block_encryption_mode' system variable. BlockEncryptionMode = "block_encryption_mode" )
const ( // tidb_snapshot is used for reading history data, the default value is empty string. // The value can be a datetime string like '2017-11-11 20:20:20' or a tso string. When this variable is set, the session reads history data of that time. TiDBSnapshot = "tidb_snapshot" // tidb_opt_agg_push_down is used to enable/disable the optimizer rule of aggregation push down. TiDBOptAggPushDown = "tidb_opt_agg_push_down" // Auto analyze will run if (table modify count)/(table row count) is greater than this value. TiDBAutoAnalyzeRatio = "tidb_auto_analyze_ratio" // Auto analyze will run if current time is within start time and end time. TiDBAutoAnalyzeStartTime = "tidb_auto_analyze_start_time" TiDBAutoAnalyzeEndTime = "tidb_auto_analyze_end_time" // tidb_checksum_table_concurrency is used to speed up the ADMIN CHECKSUM TABLE // statement, when a table has multiple indices, those indices can be // scanned concurrently, with the cost of higher system performance impact. TiDBChecksumTableConcurrency = "tidb_checksum_table_concurrency" // TiDBCurrentTS is used to get the current transaction timestamp. // It is read-only. TiDBCurrentTS = "tidb_current_ts" // tidb_config is a read-only variable that shows the config of the current server. TiDBConfig = "tidb_config" // tidb_batch_insert is used to enable/disable auto-split insert data. If set this option on, insert executor will automatically // insert data into multiple batches and use a single txn for each batch. This will be helpful when inserting large data. TiDBBatchInsert = "tidb_batch_insert" // tidb_batch_delete is used to enable/disable auto-split delete data. If set this option on, delete executor will automatically // split data into multiple batches and use a single txn for each batch. This will be helpful when deleting large data. TiDBBatchDelete = "tidb_batch_delete" // tidb_dml_batch_size is used to split the insert/delete data into small batches. // It only takes effort when tidb_batch_insert/tidb_batch_delete is on. // Its default value is 20000. When the row size is large, 20k rows could be larger than 100MB. // User could change it to a smaller one to avoid breaking the transaction size limitation. TiDBDMLBatchSize = "tidb_dml_batch_size" // The following session variables controls the memory quota during query execution. // "tidb_mem_quota_query": control the memory quota of a query. // "tidb_mem_quota_hashjoin": control the memory quota of "HashJoinExec". // "tidb_mem_quota_mergejoin": control the memory quota of "MergeJoinExec". // "tidb_mem_quota_sort": control the memory quota of "SortExec". // "tidb_mem_quota_topn": control the memory quota of "TopNExec". // "tidb_mem_quota_indexlookupreader": control the memory quota of "IndexLookUpExecutor". // "tidb_mem_quota_indexlookupjoin": control the memory quota of "IndexLookUpJoin". // "tidb_mem_quota_nestedloopapply": control the memory quota of "NestedLoopApplyExec". TIDBMemQuotaQuery = "tidb_mem_quota_query" // Bytes. TIDBMemQuotaHashJoin = "tidb_mem_quota_hashjoin" // Bytes. TIDBMemQuotaMergeJoin = "tidb_mem_quota_mergejoin" // Bytes. TIDBMemQuotaSort = "tidb_mem_quota_sort" // Bytes. TIDBMemQuotaTopn = "tidb_mem_quota_topn" // Bytes. TIDBMemQuotaIndexLookupReader = "tidb_mem_quota_indexlookupreader" // Bytes. TIDBMemQuotaIndexLookupJoin = "tidb_mem_quota_indexlookupjoin" // Bytes. TIDBMemQuotaNestedLoopApply = "tidb_mem_quota_nestedloopapply" // Bytes. // tidb_general_log is used to log every query in the server in info level. TiDBGeneralLog = "tidb_general_log" // tidb_retry_limit is the maximun number of retries when committing a transaction. TiDBRetryLimit = "tidb_retry_limit" // tidb_disable_txn_auto_retry disables transaction auto retry. TiDBDisableTxnAutoRetry = "tidb_disable_txn_auto_retry" // tidb_enable_streaming enables TiDB to use streaming API for coprocessor requests. TiDBEnableStreaming = "tidb_enable_streaming" // tidb_optimizer_selectivity_level is used to control the selectivity estimation level. TiDBOptimizerSelectivityLevel = "tidb_optimizer_selectivity_level" // tidb_enable_table_partition is used to enable table partition feature. TiDBEnableTablePartition = "tidb_enable_table_partition" )
TiDB system variable names that only in session scope.
const ( // tidb_build_stats_concurrency is used to speed up the ANALYZE statement, when a table has multiple indices, // those indices can be scanned concurrently, with the cost of higher system performance impact. TiDBBuildStatsConcurrency = "tidb_build_stats_concurrency" // tidb_distsql_scan_concurrency is used to set the concurrency of a distsql scan task. // A distsql scan task can be a table scan or a index scan, which may be distributed to many TiKV nodes. // Higher concurrency may reduce latency, but with the cost of higher memory usage and system performance impact. // If the query has a LIMIT clause, high concurrency makes the system do much more work than needed. TiDBDistSQLScanConcurrency = "tidb_distsql_scan_concurrency" // tidb_opt_insubquery_unfold is used to enable/disable the optimizer rule of in subquery unfold. TiDBOptInSubqUnFolding = "tidb_opt_insubquery_unfold" // tidb_index_join_batch_size is used to set the batch size of a index lookup join. // The index lookup join fetches batches of data from outer executor and constructs ranges for inner executor. // This value controls how much of data in a batch to do the index join. // Large value may reduce the latency but consumes more system resource. TiDBIndexJoinBatchSize = "tidb_index_join_batch_size" // tidb_index_lookup_size is used for index lookup executor. // The index lookup executor first scan a batch of handles from a index, then use those handles to lookup the table // rows, this value controls how much of handles in a batch to do a lookup task. // Small value sends more RPCs to TiKV, consume more system resource. // Large value may do more work than needed if the query has a limit. TiDBIndexLookupSize = "tidb_index_lookup_size" // tidb_index_lookup_concurrency is used for index lookup executor. // A lookup task may have 'tidb_index_lookup_size' of handles at maximun, the handles may be distributed // in many TiKV nodes, we executes multiple concurrent index lookup tasks concurrently to reduce the time // waiting for a task to finish. // Set this value higher may reduce the latency but consumes more system resource. TiDBIndexLookupConcurrency = "tidb_index_lookup_concurrency" // tidb_index_lookup_join_concurrency is used for index lookup join executor. // IndexLookUpJoin starts "tidb_index_lookup_join_concurrency" inner workers // to fetch inner rows and join the matched (outer, inner) row pairs. TiDBIndexLookupJoinConcurrency = "tidb_index_lookup_join_concurrency" // tidb_index_serial_scan_concurrency is used for controlling the concurrency of index scan operation // when we need to keep the data output order the same as the order of index data. TiDBIndexSerialScanConcurrency = "tidb_index_serial_scan_concurrency" // tidb_max_chunk_capacity is used to control the max chunk size during query execution. TiDBMaxChunkSize = "tidb_max_chunk_size" // tidb_skip_utf8_check skips the UTF8 validate process, validate UTF8 has performance cost, if we can make sure // the input string values are valid, we can skip the check. TiDBSkipUTF8Check = "tidb_skip_utf8_check" // tidb_hash_join_concurrency is used for hash join executor. // The hash join outer executor starts multiple concurrent join workers to probe the hash table. TiDBHashJoinConcurrency = "tidb_hash_join_concurrency" // tidb_projection_concurrency is used for projection operator. // This variable controls the worker number of projection operator. TiDBProjectionConcurrency = "tidb_projection_concurrency" // tidb_hashagg_partial_concurrency is used for hash agg executor. // The hash agg executor starts multiple concurrent partial workers to do partial aggregate works. TiDBHashAggPartialConcurrency = "tidb_hashagg_partial_concurrency" // tidb_hashagg_final_concurrency is used for hash agg executor. // The hash agg executor starts multiple concurrent final workers to do final aggregate works. TiDBHashAggFinalConcurrency = "tidb_hashagg_final_concurrency" // tidb_backoff_lock_fast is used for tikv backoff base time in milliseconds. TiDBBackoffLockFast = "tidb_backoff_lock_fast" // tidb_ddl_reorg_worker_cnt defines the count of ddl reorg workers. TiDBDDLReorgWorkerCount = "tidb_ddl_reorg_worker_cnt" // tidb_ddl_reorg_priority defines the operations priority of adding indices. // It can be: PRIORITY_LOW, PRIORITY_NORMAL, PRIORITY_HIGH TiDBDDLReorgPriority = "tidb_ddl_reorg_priority" // tidb_force_priority defines the operations priority of all statements. // It can be "NO_PRIORITY", "LOW_PRIORITY", "HIGH_PRIORITY", "DELAYED" TiDBForcePriority = "tidb_force_priority" )
TiDB system variable names that both in session and global scope.
const ( DefIndexLookupConcurrency = 4 DefIndexLookupJoinConcurrency = 4 DefIndexSerialScanConcurrency = 1 DefIndexJoinBatchSize = 25000 DefIndexLookupSize = 20000 DefDistSQLScanConcurrency = 15 DefBuildStatsConcurrency = 4 DefAutoAnalyzeRatio = 0.5 DefAutoAnalyzeStartTime = "00:00 +0000" DefAutoAnalyzeEndTime = "23:59 +0000" DefChecksumTableConcurrency = 4 DefSkipUTF8Check = false DefOptAggPushDown = false DefOptInSubqUnfolding = false DefBatchInsert = false DefBatchDelete = false DefCurretTS = 0 DefMaxChunkSize = 32 DefDMLBatchSize = 20000 DefTiDBMemQuotaHashJoin = 32 << 30 // 32GB. DefTiDBMemQuotaMergeJoin = 32 << 30 // 32GB. DefTiDBMemQuotaSort = 32 << 30 // 32GB. DefTiDBMemQuotaTopn = 32 << 30 // 32GB. DefTiDBMemQuotaIndexLookupReader = 32 << 30 // 32GB. DefTiDBMemQuotaIndexLookupJoin = 32 << 30 // 32GB. DefTiDBMemQuotaNestedLoopApply = 32 << 30 // 32GB. DefTiDBGeneralLog = 0 DefTiDBRetryLimit = 10 DefTiDBDisableTxnAutoRetry = false DefTiDBHashJoinConcurrency = 5 DefTiDBProjectionConcurrency = 4 DefTiDBOptimizerSelectivityLevel = 0 DefTiDBDDLReorgWorkerCount = 16 DefTiDBHashAggPartialConcurrency = 4 DefTiDBHashAggFinalConcurrency = 4 DefTiDBForcePriority = mysql.NoPriority )
Default TiDB system variable values.
const (
// AnalyzeFullTimeFormat is the full format of analyze start time and end time.
AnalyzeFullTimeFormat = "15:04 -0700"
)
Variables ¶
var ( ErrCantSetToNull = terror.ClassVariable.New(codeCantSetToNull, "cannot set variable to null") ErrSnapshotTooOld = terror.ClassVariable.New(codeSnapshotTooOld, "snapshot is older than GC safe point %s") )
Error instances.
var ( UnknownStatusVar = terror.ClassVariable.New(CodeUnknownStatusVar, "unknown status variable") UnknownSystemVar = terror.ClassVariable.New(CodeUnknownSystemVar, mysql.MySQLErrName[mysql.ErrUnknownSystemVariable]) ErrIncorrectScope = terror.ClassVariable.New(CodeIncorrectScope, mysql.MySQLErrName[mysql.ErrIncorrectGlobalLocalVar]) ErrUnknownTimeZone = terror.ClassVariable.New(CodeUnknownTimeZone, mysql.MySQLErrName[mysql.ErrUnknownTimeZone]) ErrReadOnly = terror.ClassVariable.New(CodeReadOnly, "variable is read only") ErrWrongValueForVar = terror.ClassVariable.New(CodeWrongValueForVar, mysql.MySQLErrName[mysql.ErrWrongValueForVar]) ErrWrongTypeForVar = terror.ClassVariable.New(CodeWrongTypeForVar, mysql.MySQLErrName[mysql.ErrWrongTypeForVar]) ErrTruncatedWrongValue = terror.ClassVariable.New(CodeTruncatedWrongValue, mysql.MySQLErrName[mysql.ErrTruncatedWrongValue]) )
Variable errors
var ( ProcessGeneralLog uint32 DDLSlowOprThreshold uint32 = 300 // DDLSlowOprThreshold is the threshold for ddl slow operations, uint is millisecond. ForcePriority = int32(DefTiDBForcePriority) ServerHostname, _ = os.Hostname() )
Process global variables.
var DefaultStatusVarScopeFlag = ScopeGlobal | ScopeSession
DefaultStatusVarScopeFlag is the default scope of status variables.
var SetNamesVariables = []string{
"character_set_client",
"character_set_connection",
"character_set_results",
}
SetNamesVariables is the system variable names related to set names statements.
var SynonymsSysVariables = map[string][]string{}
SynonymsSysVariables is synonyms of system variables.
var SysVars map[string]*SysVar
SysVars is global sys vars map.
Functions ¶
func GetDDLReorgWorkerCounter ¶
func GetDDLReorgWorkerCounter() int32
GetDDLReorgWorkerCounter gets ddlReorgWorkerCounter.
func GetGlobalSystemVar ¶
func GetGlobalSystemVar(s *SessionVars, key string) (string, error)
GetGlobalSystemVar gets a global system variable.
func GetScopeNoneSystemVar ¶
GetScopeNoneSystemVar checks the validation of `key`, and return the default value if its scope is `ScopeNone`.
func GetSessionOnlySysVars ¶
func GetSessionOnlySysVars(s *SessionVars, key string) (string, bool, error)
GetSessionOnlySysVars get the default value defined in code for session only variable. The return bool value indicates whether it's a session only variable.
func GetSessionSystemVar ¶
func GetSessionSystemVar(s *SessionVars, key string) (string, error)
GetSessionSystemVar gets a system variable. If it is a session only variable, use the default value defined in code. Returns error if there is no such variable.
func GetStatusVars ¶
func GetStatusVars(vars *SessionVars) (map[string]*StatusVal, error)
GetStatusVars gets registered statistics status variables. TODO: Refactor this function to avoid repeated memory allocation / dealloc
func GoTimeToTS ¶
GoTimeToTS converts a Go time to uint64 timestamp.
func RegisterStatistics ¶
func RegisterStatistics(s Statistics)
RegisterStatistics registers statistics.
func SetDDLReorgWorkerCounter ¶
func SetDDLReorgWorkerCounter(cnt int32)
SetDDLReorgWorkerCounter sets ddlReorgWorkerCounter count. Max worker count is maxDDLReorgWorkerCount.
func SetSessionSystemVar ¶
func SetSessionSystemVar(vars *SessionVars, name string, value types.Datum) error
SetSessionSystemVar sets system variable and updates SessionVars states.
func TiDBOptOn ¶
TiDBOptOn could be used for all tidb session variable options, we use "ON"/1 to turn on those options.
func ValidateGetSystemVar ¶
ValidateGetSystemVar checks if system variable exists and validates its scope when get system variable.
func ValidateSetSystemVar ¶
func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, error)
ValidateSetSystemVar checks if system variable satisfies specific restriction.
Types ¶
type BatchSize ¶
type BatchSize struct { // DMLBatchSize indicates the size of batches for DML. // It will be used when BatchInsert or BatchDelete is on. DMLBatchSize int // IndexJoinBatchSize is the batch size of a index lookup join. IndexJoinBatchSize int // IndexLookupSize is the number of handles for an index lookup task in index double read executor. IndexLookupSize int // MaxChunkSize defines max row count of a Chunk during query execution. MaxChunkSize int }
BatchSize defines batch size values.
type Concurrency ¶
type Concurrency struct { // IndexLookupConcurrency is the number of concurrent index lookup worker. IndexLookupConcurrency int // IndexLookupJoinConcurrency is the number of concurrent index lookup join inner worker. IndexLookupJoinConcurrency int // DistSQLScanConcurrency is the number of concurrent dist SQL scan worker. DistSQLScanConcurrency int // HashJoinConcurrency is the number of concurrent hash join outer worker. HashJoinConcurrency int // ProjectionConcurrency is the number of concurrent projection worker. ProjectionConcurrency int64 // HashAggPartialConcurrency is the number of concurrent hash aggregation partial worker. HashAggPartialConcurrency int // HashAggPartialConcurrency is the number of concurrent hash aggregation final worker. HashAggFinalConcurrency int // IndexSerialScanConcurrency is the number of concurrent index serial scan worker. IndexSerialScanConcurrency int }
Concurrency defines concurrency values.
type GlobalVarAccessor ¶
type GlobalVarAccessor interface { // GetAllSysVars gets all the global system variable values. GetAllSysVars() (map[string]string, error) // GetGlobalSysVar gets the global system variable value for name. GetGlobalSysVar(name string) (string, error) // SetGlobalSysVar sets the global system variable name to value. SetGlobalSysVar(name string, value string) error }
GlobalVarAccessor is the interface for accessing global scope system and status variables.
type MemQuota ¶
type MemQuota struct { // MemQuotaQuery defines the memory quota for a query. MemQuotaQuery int64 // MemQuotaHashJoin defines the memory quota for a hash join executor. MemQuotaHashJoin int64 // MemQuotaMergeJoin defines the memory quota for a merge join executor. MemQuotaMergeJoin int64 // MemQuotaSort defines the memory quota for a sort executor. MemQuotaSort int64 // MemQuotaTopn defines the memory quota for a top n executor. MemQuotaTopn int64 // MemQuotaIndexLookupReader defines the memory quota for a index lookup reader executor. MemQuotaIndexLookupReader int64 // MemQuotaIndexLookupJoin defines the memory quota for a index lookup join executor. MemQuotaIndexLookupJoin int64 // MemQuotaNestedLoopApply defines the memory quota for a nested loop apply executor. MemQuotaNestedLoopApply int64 }
MemQuota defines memory quota values.
type MockGlobalAccessor ¶
type MockGlobalAccessor struct { }
MockGlobalAccessor implements GlobalVarAccessor interface. it's used in tests
func NewMockGlobalAccessor ¶
func NewMockGlobalAccessor() *MockGlobalAccessor
NewMockGlobalAccessor implements GlobalVarAccessor interface.
func (*MockGlobalAccessor) GetAllSysVars ¶
func (m *MockGlobalAccessor) GetAllSysVars() (map[string]string, error)
GetAllSysVars implements GlobalVarAccessor.GetAllSysVars interface.
func (*MockGlobalAccessor) GetGlobalSysVar ¶
func (m *MockGlobalAccessor) GetGlobalSysVar(name string) (string, error)
GetGlobalSysVar implements GlobalVarAccessor.GetGlobalSysVar interface.
func (*MockGlobalAccessor) SetGlobalSysVar ¶
func (m *MockGlobalAccessor) SetGlobalSysVar(name string, value string) error
SetGlobalSysVar implements GlobalVarAccessor.SetGlobalSysVar interface.
type RetryInfo ¶
type RetryInfo struct { Retrying bool DroppedPreparedStmtIDs []uint32 // contains filtered or unexported fields }
RetryInfo saves retry information.
func (*RetryInfo) AddAutoIncrementID ¶
AddAutoIncrementID adds id to AutoIncrementIDs.
func (*RetryInfo) GetCurrAutoIncrementID ¶
GetCurrAutoIncrementID gets current AutoIncrementID.
func (*RetryInfo) ResetOffset ¶
func (r *RetryInfo) ResetOffset()
ResetOffset resets the current retry offset.
type ScopeFlag ¶
type ScopeFlag uint8
ScopeFlag is for system variable whether can be changed in global/session dynamically or not.
const ( // ScopeNone means the system variable can not be changed dynamically. ScopeNone ScopeFlag = 0 // ScopeGlobal means the system variable can be changed globally. ScopeGlobal ScopeFlag = 1 << 0 // ScopeSession means the system variable can only be changed in current session. ScopeSession ScopeFlag = 1 << 1 )
type SessionVars ¶
type SessionVars struct { Concurrency MemQuota BatchSize RetryLimit int64 DisableTxnAutoRetry bool // UsersLock is a lock for user defined variables. UsersLock sync.RWMutex // Users are user defined variables. Users map[string]string // PreparedStmts stores prepared statement. PreparedStmts map[uint32]interface{} PreparedStmtNameToID map[string]uint32 // params for prepared statements PreparedParams []interface{} // retry information RetryInfo *RetryInfo // Should be reset on transaction finished. TxnCtx *TransactionContext // KVVars is the variables for KV storage. KVVars *kv.Variables // TxnIsolationLevelOneShot is used to implements "set transaction isolation level ..." TxnIsolationLevelOneShot struct { // state 0 means default // state 1 means it's set in current transaction. // state 2 means it should be used in current transaction. State int Value string } Status uint16 PrevLastInsertID uint64 // PrevLastInsertID is the last insert ID of previous statement. LastInsertID uint64 // LastInsertID is the auto-generated ID in the current statement. InsertID uint64 // InsertID is the given insert ID of an auto_increment column. // PrevAffectedRows is the affected-rows value(DDL is 0, DML is the number of affected rows). PrevAffectedRows int64 // ClientCapability is client's capability. ClientCapability uint32 // TLSConnectionState is the TLS connection state (nil if not using TLS). TLSConnectionState *tls.ConnectionState // ConnectionID is the connection id of the current session. ConnectionID uint64 // PlanID is the unique id of logical and physical plan. PlanID int // PlanColumnID is the unique id for column when building plan. PlanColumnID int64 // User is the user identity with which the session login. User *auth.UserIdentity // CurrentDB is the default database of this session. CurrentDB string // StrictSQLMode indicates if the session is in strict mode. StrictSQLMode bool // CommonGlobalLoaded indicates if common global variable has been loaded for this session. CommonGlobalLoaded bool // InRestrictedSQL indicates if the session is handling restricted SQL execution. InRestrictedSQL bool // SnapshotTS is used for reading history data. For simplicity, SnapshotTS only supports distsql request. SnapshotTS uint64 // SnapshotInfoschema is used with SnapshotTS, when the schema version at snapshotTS less than current schema // version, we load an old version schema for query. SnapshotInfoschema interface{} // BinlogClient is used to write binlog. BinlogClient interface{} // GlobalVarsAccessor is used to set and get global variables. GlobalVarsAccessor GlobalVarAccessor // LastFoundRows is the number of found rows of last query statement LastFoundRows uint64 // StmtCtx holds variables for current executing statement. StmtCtx *stmtctx.StatementContext // AllowAggPushDown can be set to false to forbid aggregation push down. AllowAggPushDown bool // AllowInSubqueryUnFolding can be set to true to fold in subquery AllowInSubqueryUnFolding bool // CurrInsertValues is used to record current ValuesExpr's values. // See http://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_values CurrInsertValues chunk.Row // Per-connection time zones. Each client that connects has its own time zone setting, given by the session time_zone variable. // See https://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html TimeZone *time.Location SQLMode mysql.SQLMode // LightningMode is true when the lightning use the kvencoder to transfer sql to raw kv. LightningMode bool // SkipUTF8Check check on input value. SkipUTF8Check bool // BatchInsert indicates if we should split insert data into multiple batches. BatchInsert bool // BatchDelete indicates if we should split delete data into multiple batches. BatchDelete bool // IDAllocator is provided by kvEncoder, if it is provided, we will use it to alloc auto id instead of using // Table.alloc. IDAllocator autoid.Allocator // OptimizerSelectivityLevel defines the level of the selectivity estimation in plan. OptimizerSelectivityLevel int // EnableTablePartition enables table partition feature. EnableTablePartition bool // DDLReorgPriority is the operation priority of adding indices. DDLReorgPriority int // EnableStreaming indicates whether the coprocessor request can use streaming API. // TODO: remove this after tidb-server configuration "enable-streaming' removed. EnableStreaming bool // contains filtered or unexported fields }
SessionVars is to handle user-defined or global variables in the current session.
func NewSessionVars ¶
func NewSessionVars() *SessionVars
NewSessionVars creates a session vars object.
func (*SessionVars) AllocPlanColumnID ¶
func (s *SessionVars) AllocPlanColumnID() int64
AllocPlanColumnID allocates column id for plan.
func (*SessionVars) CleanBuffers ¶
func (s *SessionVars) CleanBuffers()
CleanBuffers cleans the temporary bufs
func (*SessionVars) GetCharsetInfo ¶
func (s *SessionVars) GetCharsetInfo() (charset, collation string)
GetCharsetInfo gets charset and collation for current context. What character set should the server translate a statement to after receiving it? For this, the server uses the character_set_connection and collation_connection system variables. It converts statements sent by the client from character_set_client to character_set_connection (except for string literals that have an introducer such as _latin1 or _utf8). collation_connection is important for comparisons of literal strings. For comparisons of strings with column values, collation_connection does not matter because columns have their own collation, which has a higher collation precedence. See https://dev.mysql.com/doc/refman/5.7/en/charset-connection.html
func (*SessionVars) GetNextPreparedStmtID ¶
func (s *SessionVars) GetNextPreparedStmtID() uint32
GetNextPreparedStmtID generates and returns the next session scope prepared statement id.
func (*SessionVars) GetStatusFlag ¶
func (s *SessionVars) GetStatusFlag(flag uint16) bool
GetStatusFlag gets the session server status variable, returns true if it is on.
func (*SessionVars) GetSystemVar ¶
func (s *SessionVars) GetSystemVar(name string) (string, bool)
GetSystemVar gets the string value of a system variable.
func (*SessionVars) GetWriteStmtBufs ¶
func (s *SessionVars) GetWriteStmtBufs() *WriteStmtBufs
GetWriteStmtBufs get pointer of SessionVars.writeStmtBufs.
func (*SessionVars) InTxn ¶
func (s *SessionVars) InTxn() bool
InTxn returns if the session is in transaction.
func (*SessionVars) IsAutocommit ¶
func (s *SessionVars) IsAutocommit() bool
IsAutocommit returns if the session is set to autocommit.
func (*SessionVars) Location ¶
func (s *SessionVars) Location() *time.Location
Location returns the value of time_zone session variable. If it is nil, then return time.Local.
func (*SessionVars) ResetPrevAffectedRows ¶
func (s *SessionVars) ResetPrevAffectedRows()
ResetPrevAffectedRows reset the prev-affected-rows variable.
func (*SessionVars) SetLastInsertID ¶
func (s *SessionVars) SetLastInsertID(insertID uint64)
SetLastInsertID saves the last insert id to the session context. TODO: we may store the result for last_insert_id sys var later.
func (*SessionVars) SetStatusFlag ¶
func (s *SessionVars) SetStatusFlag(flag uint16, on bool)
SetStatusFlag sets the session server status variable. If on is ture sets the flag in session status, otherwise removes the flag.
func (*SessionVars) SetSystemVar ¶
func (s *SessionVars) SetSystemVar(name string, val string) error
SetSystemVar sets the value of a system variable.
type Statistics ¶
type Statistics interface { // GetScope gets the status variables scope. GetScope(status string) ScopeFlag // Stats returns the statistics status variables. Stats(*SessionVars) (map[string]interface{}, error) }
Statistics is the interface of statistics.
type StatusVal ¶
type StatusVal struct { Scope ScopeFlag Value interface{} }
StatusVal is the value of the corresponding status variable.
type SysVar ¶
type SysVar struct { // Scope is for whether can be changed or not Scope ScopeFlag // Name is the variable name. Name string // Value is the variable value. Value string }
SysVar is for system variable.
type TableDelta ¶
type TableDelta struct { Delta int64 Count int64 ColSize map[int64]int64 InitTime time.Time // InitTime is the time that this delta is generated. }
TableDelta stands for the changed count for one table.
type TransactionContext ¶
type TransactionContext struct { ForUpdate bool DirtyDB interface{} Binlog interface{} InfoSchema interface{} Histroy interface{} SchemaVersion int64 StartTS uint64 Shard *int64 TableDeltaMap map[int64]TableDelta // For metrics. CreateTime time.Time StatementCount int }
TransactionContext is used to store variables that has transaction scope.
func (*TransactionContext) ClearDelta ¶ added in v1.0.5
func (tc *TransactionContext) ClearDelta()
ClearDelta clears the delta map.
func (*TransactionContext) UpdateDeltaForTable ¶
func (tc *TransactionContext) UpdateDeltaForTable(tableID int64, delta int64, count int64, colSize map[int64]int64)
UpdateDeltaForTable updates the delta info for some table.
type WriteStmtBufs ¶
type WriteStmtBufs struct { // RowValBuf is used by tablecodec.EncodeRow, to reduce runtime.growslice. RowValBuf []byte // BufStore stores temp KVs for a row when executing insert statement. // We could reuse a BufStore for multiple rows of a session to reduce memory allocations. BufStore *kv.BufferStore // AddRowValues use to store temp insert rows value, to reduce memory allocations when importing data. AddRowValues []types.Datum // IndexValsBuf is used by index.FetchValues IndexValsBuf []types.Datum // IndexKeyBuf is used by index.GenIndexKey IndexKeyBuf []byte }
WriteStmtBufs can be used by insert/replace/delete/update statement. TODO: use a common memory pool to replace this.