Documentation ¶
Index ¶
- Constants
- Variables
- func BindGlobalVarAccessor(ctx context.Context, accessor GlobalVarAccessor)
- func BindSessionVars(ctx context.Context)
- func GetCharsetInfo(ctx context.Context) (charset, collation string)
- func GetSnapshotTS(ctx context.Context) uint64
- func GetStatusVars() (map[string]*StatusVal, error)
- func RegisterStatistics(s Statistics)
- type GlobalVarAccessor
- type RetryInfo
- type ScopeFlag
- type SessionVars
- func (s *SessionVars) AddAffectedRows(rows uint64)
- func (s *SessionVars) AddFoundRows(rows uint64)
- func (s *SessionVars) GetNextPreparedStmtID() uint32
- func (s *SessionVars) GetSystemVar(key string) types.Datum
- func (s *SessionVars) GetTiDBSystemVar(ctx context.Context, name string) (string, error)
- func (s *SessionVars) SetAffectedRows(affectedRows uint64)
- func (s *SessionVars) SetCurrentUser(user string)
- func (s *SessionVars) SetLastInsertID(insertID uint64)
- func (s *SessionVars) SetStatusFlag(flag uint16, on bool)
- func (s *SessionVars) SetSystemVar(key string, value types.Datum) error
- type Statistics
- type StatusVal
- type SysVar
Constants ¶
const ( CodeUnknownStatusVar terror.ErrCode = 1 CodeUnknownSystemVar terror.ErrCode = 1193 )
Variable error codes.
const ( TiDBSnapshot = "tidb_snapshot" DistSQLScanConcurrencyVar = "tidb_distsql_scan_concurrency" DistSQLJoinConcurrencyVar = "tidb_distsql_join_concurrency" )
TiDB system variables
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" )
Variables ¶
var ( UnknownStatusVar = terror.ClassVariable.New(CodeUnknownStatusVar, "unknown status variable") UnknownSystemVar = terror.ClassVariable.New(CodeUnknownSystemVar, "unknown system variable") )
Variable errors
var DefaultScopeFlag = ScopeGlobal | ScopeSession
DefaultScopeFlag is the status default scope.
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 BindGlobalVarAccessor ¶
func BindGlobalVarAccessor(ctx context.Context, accessor GlobalVarAccessor)
BindGlobalVarAccessor binds global var accessor to context.
func BindSessionVars ¶
BindSessionVars creates a session vars object and binds it to context.
func GetCharsetInfo ¶
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 GetSnapshotTS ¶
GetSnapshotTS gets snapshot timestamp that has been set by set variable statement.
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(ctx context.Context, name string) (string, error) // SetGlobalSysVar sets the global system variable name to value. SetGlobalSysVar(ctx context.Context, name string, value string) error }
GlobalVarAccessor is the interface for accessing global scope system and status variables.
func GetGlobalVarAccessor ¶
func GetGlobalVarAccessor(ctx context.Context) GlobalVarAccessor
GetGlobalVarAccessor gets accessor from ctx.
type RetryInfo ¶
type RetryInfo struct { Retrying bool // Attempts is the current number of retry attempts. Attempts int // 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 { // user-defined variables Users map[string]string // prepared statement PreparedStmts map[uint32]interface{} PreparedStmtNameToID map[string]uint32 // retry information RetryInfo *RetryInfo // following variables are special for current session Status uint16 LastInsertID uint64 AffectedRows uint64 // Client capability ClientCapability uint32 // Connection ID ConnectionID uint64 // Found rows FoundRows uint64 // Current user User string // Strict SQL mode StrictSQLMode bool // InUpdateStmt indicates if the session is handling update stmt. InUpdateStmt 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{} // contains filtered or unexported fields }
SessionVars is to handle user-defined or global variables in current session.
func GetSessionVars ¶
func GetSessionVars(ctx context.Context) *SessionVars
GetSessionVars gets the session vars from context.
func (*SessionVars) AddAffectedRows ¶
func (s *SessionVars) AddAffectedRows(rows uint64)
AddAffectedRows adds affected rows with the argument rows.
func (*SessionVars) AddFoundRows ¶
func (s *SessionVars) AddFoundRows(rows uint64)
AddFoundRows adds found rows with the argument rows.
func (*SessionVars) GetNextPreparedStmtID ¶
func (s *SessionVars) GetNextPreparedStmtID() uint32
GetNextPreparedStmtID generates and returns the next session scope prepared statement id.
func (*SessionVars) GetSystemVar ¶
func (s *SessionVars) GetSystemVar(key string) types.Datum
GetSystemVar gets a system variable.
func (*SessionVars) GetTiDBSystemVar ¶
GetTiDBSystemVar get variable value for name. The variable should be a TiDB specific system variable (The vars in tidbSysVars map). If the session scope variable is not set, it will get global scope value and fill session scope value.
func (*SessionVars) SetAffectedRows ¶
func (s *SessionVars) SetAffectedRows(affectedRows uint64)
SetAffectedRows saves the affected rows to the session context.
func (*SessionVars) SetCurrentUser ¶
func (s *SessionVars) SetCurrentUser(user string)
SetCurrentUser saves the current user to the session context.
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(key string, value types.Datum) error
SetSystemVar sets 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() (map[string]interface{}, error) }
Statistics is the interface of statistics.