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) AddAffectedRows(rows uint64)
- func (s *SessionVars) AddFoundRows(rows uint64)
- func (s *SessionVars) GetCharsetInfo() (charset, collation string)
- func (s *SessionVars) GetNextPreparedStmtID() uint32
- func (s *SessionVars) GetStatusFlag(flag uint16) bool
- func (s *SessionVars) GetSystemVar(key string) types.Datum
- func (s *SessionVars) GetTiDBSystemVar(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
- func (s *SessionVars) ShouldAutocommit() bool
- type Statistics
- type StatusVal
- type SysVar
Constants ¶
const ( SQLModeVar = "sql_mode" AutocommitVar = "autocommit" )
special session variables.
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" TiDBSkipConstraintCheck = "tidb_skip_constraint_check" )
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 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
// 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
// Current DB
CurrentDB string
// Strict SQL mode
StrictSQLMode bool
// CommonGlobalLoaded indicates if common global variable has been loaded for this session.
CommonGlobalLoaded 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{}
// SkipConstraintCheck is true when importing data.
SkipConstraintCheck bool
// GlobalAccessor is used to set and get global variables.
GlobalVarsAccessor GlobalVarAccessor
// contains filtered or unexported fields
}
SessionVars is to handle user-defined or global variables in current session.
func NewSessionVars ¶
func NewSessionVars() *SessionVars
NewSessionVars creates a session vars object.
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) 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(key string) types.Datum
GetSystemVar gets a system variable.
func (*SessionVars) GetTiDBSystemVar ¶
func (s *SessionVars) GetTiDBSystemVar(name string) (string, error)
GetTiDBSystemVar gets variable value for name. The variable should be a TiDB specific system variable (The vars in tidbSysVars map). We load the variable from session first, if not found, use local defined default variable.
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.
func (*SessionVars) ShouldAutocommit ¶
func (s *SessionVars) ShouldAutocommit() bool
ShouldAutocommit checks if current session should autocommit. With START TRANSACTION, autocommit remains disabled until you end the transaction with COMMIT or ROLLBACK.
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.