Documentation ¶
Index ¶
- Constants
- Variables
- func GetStatusVars() (map[string]*StatusVal, error)
- func RegisterStatistics(s Statistics)
- type GlobalVarAccessor
- type RetryInfo
- type ScopeFlag
- type SessionVars
- func (s *SessionVars) GetCharsetInfo() (charset, collation string)
- func (s *SessionVars) GetNextPreparedStmtID() uint32
- func (s *SessionVars) GetStatusFlag(flag uint16) bool
- func (s *SessionVars) GetTimeZone() *time.Location
- func (s *SessionVars) InTxn() bool
- func (s *SessionVars) IsAutocommit() bool
- func (s *SessionVars) SetLastInsertID(insertID uint64)
- func (s *SessionVars) SetStatusFlag(flag uint16, on bool)
- type StatementContext
- func (sc *StatementContext) AddAffectedRows(rows uint64)
- func (sc *StatementContext) AddFoundRows(rows uint64)
- func (sc *StatementContext) AffectedRows() uint64
- func (sc *StatementContext) AppendWarning(warn error)
- func (sc *StatementContext) FoundRows() uint64
- func (sc *StatementContext) GetWarnings() []error
- func (sc *StatementContext) HandleTruncate(err error) error
- func (sc *StatementContext) ResetForRetry()
- func (sc *StatementContext) SetWarnings(warns []error)
- func (sc *StatementContext) WarningCount() uint16
- type Statistics
- type StatusVal
- type SysVar
- type TableDelta
- type TransactionContext
Constants ¶
const ( SQLModeVar = "sql_mode" AutocommitVar = "autocommit" CharacterSetResults = "character_set_results" MaxAllowedPacket = "max_allowed_packet" TimeZone = "time_zone" )
special session variables.
const ( CodeUnknownStatusVar terror.ErrCode = 1 CodeUnknownSystemVar terror.ErrCode = 1193 CodeIncorrectScope terror.ErrCode = 1238 CodeUnknownTimeZone terror.ErrCode = 1298 )
Variable error codes.
const ( // 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" )
const ( // tidb_snapshot is used for reading history data, the default value is empty string. // When the value is set to a datetime string like '2017-11-11 20:20:20', the session reads history data of that time. TiDBSnapshot = "tidb_snapshot" // tidb_skip_constraint_check is used for loading data from a dump file, to speed up the loading process. // When the value is set to true, unique index constraint is not checked. TiDBSkipConstraintCheck = "tidb_skip_constraint_check" // tidb_opt_agg_push_down is used to endable/disable the optimizer rule of aggregation push down. TiDBOptAggPushDown = "tidb_opt_agg_push_down" // tidb_opt_insubquery_unfold is used to enable/disable the optimizer rule of in subquery unfold. TiDBOptInSubqUnFolding = "tidb_opt_insubquery_unfold" // 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_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_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_skip_ddl_wait skips the wait time of two lease after executing CREATE TABLE statement. // When we have multiple TiDB servers in a cluster, the newly created table may not be available on all TiDB server // until two lease time later, set this value to true will reduce the time to create a table, with the risk that // other TiDB servers may fail to use the newly created table in a small time window. TiDBSkipDDLWait = "tidb_skip_ddl_wait" // 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_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_max_row_count_for_inlj is used when do index nested loop join. // It controls the max row count of outer table when do index nested loop join without hint. // After the row count of the inner table is accurate, this variable will be removed. TiDBMaxRowCountForINLJ = "tidb_max_row_count_for_inlj" )
TiDB system variable names.
const ( DefIndexLookupConcurrency = 4 DefIndexSerialScanConcurrency = 1 DefIndexLookupSize = 20000 DefDistSQLScanConcurrency = 10 DefBuildStatsConcurrency = 4 DefMaxRowCountForINLJ = 128 DefSkipDDLWait = false DefSkipUTF8Check = false DefOptAggPushDown = true DefOptInSubqUnfolding = false DefBatchInsert = false )
Default TiDB system variable values.
Variables ¶
var ( UnknownStatusVar = terror.ClassVariable.New(CodeUnknownStatusVar, "unknown status variable") UnknownSystemVar = terror.ClassVariable.New(CodeUnknownSystemVar, "unknown system variable '%s'") ErrIncorrectScope = terror.ClassVariable.New(CodeIncorrectScope, "Incorrect variable scope") ErrUnknownTimeZone = terror.ClassVariable.New(CodeUnknownTimeZone, "unknown or incorrect time zone: %s") )
Variable errors
var DefaultScopeFlag = ScopeGlobal | ScopeSession
DefaultScopeFlag is the status default scope.
var (
ErrCantSetToNull = terror.ClassVariable.New(codeCantSetToNull, "cannot set variable to null")
)
Error instances.
var GoSQLDriverTest = false
GoSQLDriverTest is used for server testing. Because go-sql-driver regards the warnings as errors.
var SetNamesVariables = []string{
"character_set_client",
"character_set_connection",
"character_set_results",
}
SetNamesVariables is the system variable names related to set names statements.
var SysVars map[string]*SysVar
SysVars is global sys vars map.
Functions ¶
func GetStatusVars ¶
GetStatusVars gets registered statistics status variables.
func RegisterStatistics ¶
func RegisterStatistics(s Statistics)
RegisterStatistics registers statistics.
Types ¶
type GlobalVarAccessor ¶
type GlobalVarAccessor interface { // 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 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 { // Users are user defined variables. Users map[string]string // Systems are system variables. Systems map[string]string // PreparedStmts stores prepared statement. PreparedStmts map[uint32]interface{} PreparedStmtNameToID map[string]uint32 // retry information RetryInfo *RetryInfo // Should be reset on transaction finished. TxnCtx *TransactionContext 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. // ClientCapability is client's capability. ClientCapability uint32 // ConnectionID is the connection id of the current session. ConnectionID uint64 // User is the username with which the session login. User string // 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{} // 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 *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 interface{} // 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 // SkipConstraintCheck is true when importing data. SkipConstraintCheck bool // SkipUTF8Check check on input value. SkipUTF8Check bool // SkipDDLWait can be set to true to skip 2 lease wait after creating/dropping/truncating table, creating/dropping database. // Then if there are multiple TiDB servers, the new table may not be available for other TiDB servers. SkipDDLWait bool // BuildStatsConcurrencyVar is used to control statistics building concurrency. BuildStatsConcurrencyVar int // IndexLookupSize is the number of handles for an index lookup task in index double read executor. IndexLookupSize int // IndexLookupConcurrency is the number of concurrent index lookup worker. IndexLookupConcurrency int // DistSQLScanConcurrency is the number of concurrent dist SQL scan worker. DistSQLScanConcurrency int // IndexSerialScanConcurrency is the number of concurrent index serial scan worker. IndexSerialScanConcurrency int // BatchInsert indicates if we should split insert data into multiple batches. BatchInsert bool // MaxRowCountForINLJ defines max row count that the outer table of index nested loop join could be without force hint. MaxRowCountForINLJ int // 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) 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) GetTimeZone ¶
func (s *SessionVars) GetTimeZone() *time.Location
GetTimeZone returns the value of time_zone session variable.
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) 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.
type StatementContext ¶
type StatementContext struct { InUpdateOrDeleteStmt bool IgnoreTruncate bool TruncateAsWarning bool InShowWarning bool // contains filtered or unexported fields }
StatementContext contains variables for a statement. It should be reset before executing a statement.
func (*StatementContext) AddAffectedRows ¶
func (sc *StatementContext) AddAffectedRows(rows uint64)
AddAffectedRows adds affected rows.
func (*StatementContext) AddFoundRows ¶
func (sc *StatementContext) AddFoundRows(rows uint64)
AddFoundRows adds found rows.
func (*StatementContext) AffectedRows ¶
func (sc *StatementContext) AffectedRows() uint64
AffectedRows gets affected rows.
func (*StatementContext) AppendWarning ¶
func (sc *StatementContext) AppendWarning(warn error)
AppendWarning appends a warning.
func (*StatementContext) FoundRows ¶
func (sc *StatementContext) FoundRows() uint64
FoundRows gets found rows.
func (*StatementContext) GetWarnings ¶
func (sc *StatementContext) GetWarnings() []error
GetWarnings gets warnings.
func (*StatementContext) HandleTruncate ¶
func (sc *StatementContext) HandleTruncate(err error) error
HandleTruncate ignores or returns the error based on the StatementContext state.
func (*StatementContext) ResetForRetry ¶
func (sc *StatementContext) ResetForRetry()
ResetForRetry resets the changed states during execution.
func (*StatementContext) SetWarnings ¶
func (sc *StatementContext) SetWarnings(warns []error)
SetWarnings sets warnings.
func (*StatementContext) WarningCount ¶
func (sc *StatementContext) WarningCount() uint16
WarningCount gets warning count.
type Statistics ¶
type Statistics interface { // GetScope gets the status variables scope. GetScope(status string) ScopeFlag // Stats returns the statistics status variables. Stats() (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 ¶
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 TableDeltaMap map[int64]TableDelta }
TransactionContext is used to store variables that has transaction scope.
func (*TransactionContext) UpdateDeltaForTable ¶
func (tc *TransactionContext) UpdateDeltaForTable(tableID int64, delta int64, count int64)
UpdateDeltaForTable updates the delta info for some table.