Documentation ¶
Index ¶
- Constants
- Variables
- func BootstrapSession(store kv.Storage) (*domain.Domain, error)
- func CreateSessionWithDomain(store kv.Storage, dom *domain.Domain) (*session, error)
- func DisableStats4Test()
- func ExecRestrictedStmt4Test(ctx context.Context, s Session, stmtNode ast.StmtNode, ...) ([]chunk.Row, []*ast.ResultField, error)
- func GetDomain(store kv.Storage) (*domain.Domain, error)
- func GetIndexUsageSyncLease() time.Duration
- func GetPlanReplayerGCLease() time.Duration
- func GetRows4Test(ctx context.Context, sctx sessionctx.Context, rs sqlexec.RecordSet) ([]chunk.Row, error)
- func GetStartTSFromSession(se interface{}) (uint64, uint64)
- func HandleNonTransactionalDML(ctx context.Context, stmt *ast.NonTransactionalDMLStmt, se Session) (sqlexec.RecordSet, error)
- func InitDDLJobTables(store kv.Storage) error
- func InitMDLTable(store kv.Storage) error
- func InitMDLVariable(store kv.Storage) error
- func InitMDLVariableForBootstrap(store kv.Storage) error
- func InitMDLVariableForUpgrade(store kv.Storage) (bool, error)
- func Parse(ctx sessionctx.Context, src string) ([]ast.StmtNode, error)
- func ParseWithParams4Test(ctx context.Context, s Session, sql string, args ...interface{}) (ast.StmtNode, error)
- func RemoveLockDDLJobs(s Session, job2ver map[int64]int64, job2ids map[int64]string, printLog bool)
- func ResetMockAutoRandIDRetryCount(failTimes int64)
- func ResetStoreForWithTiKVTest(store kv.Storage)
- func ResultSetToStringSlice(ctx context.Context, s Session, rs sqlexec.RecordSet) ([][]string, error)
- func SetIndexUsageSyncLease(lease time.Duration)
- func SetPlanReplayerGCLease(lease time.Duration)
- func SetSchemaLease(lease time.Duration)
- func SetStatsLease(lease time.Duration)
- type ExecStmtVarKeyType
- type LazyTxn
- func (txn *LazyTxn) CacheTableInfo(id int64, info *model.TableInfo)
- func (txn *LazyTxn) Commit(ctx context.Context) error
- func (txn *LazyTxn) GetOption(opt int) interface{}
- func (txn *LazyTxn) GetTableInfo(id int64) *model.TableInfo
- func (txn *LazyTxn) GoString() string
- func (txn *LazyTxn) KeysNeedToLock() ([]kv.Key, error)
- func (txn *LazyTxn) LockKeys(ctx context.Context, lockCtx *kv.LockCtx, keys ...kv.Key) error
- func (txn *LazyTxn) LockKeysFunc(ctx context.Context, lockCtx *kv.LockCtx, fn func(), keys ...kv.Key) error
- func (txn *LazyTxn) Mem() uint64
- func (txn *LazyTxn) Rollback() error
- func (txn *LazyTxn) RollbackMemDBToCheckpoint(savepoint *tikv.MemDBCheckpoint)
- func (txn *LazyTxn) SetMemoryFootprintChangeHook(hook func(uint64))
- func (txn *LazyTxn) Size() int
- func (txn *LazyTxn) String() string
- func (txn *LazyTxn) Valid() bool
- func (txn *LazyTxn) Wait(ctx context.Context, sctx sessionctx.Context) (kv.Transaction, error)
- type Opt
- type SchemaAmender
- type Session
- type StmtHistory
Constants ¶
const ( // CreateUserTable is the SQL statement creates User table in system db. // WARNING: There are some limitations on altering the schema of mysql.user table. // Adding columns that are nullable or have default values is permitted. // But operations like dropping or renaming columns may break the compatibility with BR. // REFERENCE ISSUE: https://github.com/wuhuizuo/tidb6/issues/38785 CreateUserTable = `` /* 2307-byte string literal not displayed */ // CreateGlobalPrivTable is the SQL statement creates Global scope privilege table in system db. CreateGlobalPrivTable = "CREATE TABLE IF NOT EXISTS mysql.global_priv (" + "Host CHAR(255) NOT NULL DEFAULT ''," + "User CHAR(80) NOT NULL DEFAULT ''," + "Priv LONGTEXT NOT NULL DEFAULT ''," + "PRIMARY KEY (Host, User)" + ")" // CreateDBPrivTable is the SQL statement creates DB scope privilege table in system db. CreateDBPrivTable = `` /* 1163-byte string literal not displayed */ // CreateTablePrivTable is the SQL statement creates table scope privilege table in system db. CreateTablePrivTable = `` /* 442-byte string literal not displayed */ // CreateColumnPrivTable is the SQL statement creates column scope privilege table in system db. CreateColumnPrivTable = `` /* 314-byte string literal not displayed */ // CreateGlobalVariablesTable is the SQL statement creates global variable table in system db. // TODO: MySQL puts GLOBAL_VARIABLES table in INFORMATION_SCHEMA db. // INFORMATION_SCHEMA is a virtual db in TiDB. So we put this table in system db. // Maybe we will put it back to INFORMATION_SCHEMA. CreateGlobalVariablesTable = `` /* 147-byte string literal not displayed */ // CreateTiDBTable is the SQL statement creates a table in system db. // This table is a key-value struct contains some information used by TiDB. // Currently we only put bootstrapped in it which indicates if the system is already bootstrapped. CreateTiDBTable = `` /* 164-byte string literal not displayed */ // CreateHelpTopic is the SQL statement creates help_topic table in system db. // See: https://dev.mysql.com/doc/refman/5.5/en/system-database.html#system-database-help-tables CreateHelpTopic = `` /* 418-byte string literal not displayed */ // CreateStatsMetaTable stores the meta of table statistics. CreateStatsMetaTable = `` /* 335-byte string literal not displayed */ // CreateStatsColsTable stores the statistics of table columns. CreateStatsColsTable = `` /* 647-byte string literal not displayed */ // CreateStatsBucketsTable stores the histogram info for every table columns. CreateStatsBucketsTable = `` /* 405-byte string literal not displayed */ // CreateGCDeleteRangeTable stores schemas which can be deleted by DeleteRange. CreateGCDeleteRangeTable = `` /* 398-byte string literal not displayed */ // CreateGCDeleteRangeDoneTable stores schemas which are already deleted by DeleteRange. CreateGCDeleteRangeDoneTable = `` /* 408-byte string literal not displayed */ // CreateStatsFeedbackTable stores the feedback info which is used to update stats. CreateStatsFeedbackTable = `` /* 220-byte string literal not displayed */ // CreateBindInfoTable stores the sql bind info which is used to update globalBindCache. CreateBindInfoTable = `` /* 655-byte string literal not displayed */ // CreateRoleEdgesTable stores the role and user relationship information. CreateRoleEdgesTable = `` /* 445-byte string literal not displayed */ // CreateDefaultRolesTable stores the active roles for a user. CreateDefaultRolesTable = `` /* 366-byte string literal not displayed */ // CreateStatsTopNTable stores topn data of a cmsketch with top n. CreateStatsTopNTable = `` /* 249-byte string literal not displayed */ // CreateStatsFMSketchTable stores FMSketch data of a column histogram. CreateStatsFMSketchTable = `` /* 213-byte string literal not displayed */ // CreateExprPushdownBlacklist stores the expressions which are not allowed to be pushed down. CreateExprPushdownBlacklist = `` /* 177-byte string literal not displayed */ // CreateOptRuleBlacklist stores the list of disabled optimizing operations. CreateOptRuleBlacklist = `CREATE TABLE IF NOT EXISTS mysql.opt_rule_blacklist ( name CHAR(100) NOT NULL );` // CreateStatsExtended stores the registered extended statistics. CreateStatsExtended = `` /* 376-byte string literal not displayed */ // CreateSchemaIndexUsageTable stores the index usage information. CreateSchemaIndexUsageTable = `` /* 217-byte string literal not displayed */ // CreateGlobalGrantsTable stores dynamic privs CreateGlobalGrantsTable = `` /* 251-byte string literal not displayed */ // CreateCapturePlanBaselinesBlacklist stores the baseline capture filter rules. CreateCapturePlanBaselinesBlacklist = `` /* 291-byte string literal not displayed */ // CreateColumnStatsUsageTable stores the column stats usage information. CreateColumnStatsUsageTable = `` /* 224-byte string literal not displayed */ // CreateTableCacheMetaTable stores the cached table meta lock information. CreateTableCacheMetaTable = `` /* 273-byte string literal not displayed */ // CreateAnalyzeOptionsTable stores the analyze options used by analyze and auto analyze. CreateAnalyzeOptionsTable = `` /* 398-byte string literal not displayed */ // CreateStatsHistory stores the historical stats. CreateStatsHistory = `` /* 453-byte string literal not displayed */ // CreateStatsMetaHistory stores the historical meta stats. CreateStatsMetaHistory = `` /* 389-byte string literal not displayed */ // CreateAnalyzeJobs stores the analyze jobs. CreateAnalyzeJobs = `` /* 767-byte string literal not displayed */ // CreateAdvisoryLocks stores the advisory locks (get_lock, release_lock). CreateAdvisoryLocks = `CREATE TABLE IF NOT EXISTS mysql.advisory_locks ( lock_name VARCHAR(64) NOT NULL PRIMARY KEY );` // CreateMDLView is a view about metadata locks. CreateMDLView = `` /* 448-byte string literal not displayed */ // CreatePlanReplayerStatusTable is a table about plan replayer status CreatePlanReplayerStatusTable = `` /* 365-byte string literal not displayed */ // CreatePlanReplayerTaskTable is a table about plan replayer capture task CreatePlanReplayerTaskTable = `` /* 255-byte string literal not displayed */ // CreateStatsTableLocked stores the locked tables CreateStatsTableLocked = `` /* 246-byte string literal not displayed */ // CreatePasswordHistory is a table save history passwd. CreatePasswordHistory = `` /* 356-byte string literal not displayed */ // CreateTTLTableStatus is a table about TTL task schedule CreateTTLTableStatus = `` /* 851-byte string literal not displayed */ )
const ( AmendNone int = iota // For add index. AmendNeedAddDelete AmendNeedAddDeleteAndInsert AmendNeedAddInsert )
Amend operation types.
Variables ¶
var ConstOpAddIndex = map[model.SchemaState]map[model.SchemaState]int{ model.StateNone: { model.StateDeleteOnly: AmendNeedAddDelete, model.StateWriteOnly: AmendNeedAddDeleteAndInsert, model.StateWriteReorganization: AmendNeedAddDeleteAndInsert, model.StatePublic: AmendNeedAddDeleteAndInsert, }, model.StateDeleteOnly: { model.StateWriteOnly: AmendNeedAddInsert, model.StateWriteReorganization: AmendNeedAddInsert, model.StatePublic: AmendNeedAddInsert, }, model.StateWriteOnly: { model.StateWriteReorganization: AmendNone, model.StatePublic: AmendNone, }, model.StateWriteReorganization: { model.StatePublic: AmendNone, }, }
ConstOpAddIndex is the possible ddl state changes, and related amend action types.
var ( // DDLJobTables is a list of tables definitions used in concurrent DDL. DDLJobTables = []struct { SQL string id int64 }{ {ddl.JobTableSQL, ddl.JobTableID}, {ddl.ReorgTableSQL, ddl.ReorgTableID}, {ddl.HistoryTableSQL, ddl.HistoryTableID}, } )
var (
ErrForUpdateCantRetry = dbterror.ClassSession.NewStd(errno.ErrForUpdateCantRetry)
)
Session errors.
var ErrNonTransactionalJobFailure = dbterror.ClassSession.NewStd(errno.ErrNonTransactionalJobFailure)
ErrNonTransactionalJobFailure is the error when a non-transactional job fails. The error is returned and following jobs are canceled.
var SchemaChangedWithoutRetry uint32
SchemaChangedWithoutRetry is used for testing.
Functions ¶
func BootstrapSession ¶
BootstrapSession runs the first time when the TiDB server start.
func CreateSessionWithDomain ¶
CreateSessionWithDomain creates a new Session and binds it with a Domain. We need this because when we start DDL in Domain, the DDL need a session to change some system tables. But at that time, we have been already in a lock context, which cause we can't call createSession directly.
func ExecRestrictedStmt4Test ¶
func ExecRestrictedStmt4Test(ctx context.Context, s Session, stmtNode ast.StmtNode, opts ...sqlexec.OptionFuncAlias) ( []chunk.Row, []*ast.ResultField, error)
ExecRestrictedStmt4Test wrapper `(s *session) ExecRestrictedStmt` for test.
func GetIndexUsageSyncLease ¶
GetIndexUsageSyncLease returns the index usage sync lease time.
func GetPlanReplayerGCLease ¶
GetPlanReplayerGCLease returns the plan replayer gc lease time.
func GetRows4Test ¶
func GetRows4Test(ctx context.Context, sctx sessionctx.Context, rs sqlexec.RecordSet) ([]chunk.Row, error)
GetRows4Test gets all the rows from a RecordSet, only used for test.
func GetStartTSFromSession ¶
GetStartTSFromSession returns the startTS in the session `se`
func HandleNonTransactionalDML ¶
func HandleNonTransactionalDML(ctx context.Context, stmt *ast.NonTransactionalDMLStmt, se Session) (sqlexec.RecordSet, error)
HandleNonTransactionalDML is the entry point for a non-transactional DML statement
func InitDDLJobTables ¶
InitDDLJobTables is to create tidb_ddl_job, tidb_ddl_reorg and tidb_ddl_history.
func InitMDLTable ¶
InitMDLTable is to create tidb_mdl_info, which is used for metadata lock.
func InitMDLVariable ¶
InitMDLVariable initializes the metadata lock variable.
func InitMDLVariableForBootstrap ¶
InitMDLVariableForBootstrap initializes the metadata lock variable.
func InitMDLVariableForUpgrade ¶
InitMDLVariableForUpgrade initializes the metadata lock variable.
func ParseWithParams4Test ¶
func ParseWithParams4Test(ctx context.Context, s Session, sql string, args ...interface{}) (ast.StmtNode, error)
ParseWithParams4Test wrapper (s *session) ParseWithParams for test
func RemoveLockDDLJobs ¶
RemoveLockDDLJobs removes the DDL jobs which doesn't get the metadata lock from job2ver.
func ResetMockAutoRandIDRetryCount ¶
func ResetMockAutoRandIDRetryCount(failTimes int64)
ResetMockAutoRandIDRetryCount set the number of occurrences of `kv.ErrTxnRetryable` when calling TxnState.Commit().
func ResetStoreForWithTiKVTest ¶
ResetStoreForWithTiKVTest is only used in the test code. TODO: Remove domap and storeBootstrapped. Use store.SetOption() to do it.
func ResultSetToStringSlice ¶
func ResultSetToStringSlice(ctx context.Context, s Session, rs sqlexec.RecordSet) ([][]string, error)
ResultSetToStringSlice changes the RecordSet to [][]string.
func SetIndexUsageSyncLease ¶
SetIndexUsageSyncLease changes the default index usage sync lease time for loading info.
func SetPlanReplayerGCLease ¶
SetPlanReplayerGCLease changes the default plan repalyer gc lease time.
func SetSchemaLease ¶
SetSchemaLease changes the default schema lease time for DDL. This function is very dangerous, don't use it if you really know what you do. SetSchemaLease only affects not local storage after bootstrapped.
func SetStatsLease ¶
SetStatsLease changes the default stats lease time for loading stats info.
Types ¶
type ExecStmtVarKeyType ¶
type ExecStmtVarKeyType int
ExecStmtVarKeyType is a dummy type to avoid naming collision in context.
const ExecStmtVarKey ExecStmtVarKeyType = 0
ExecStmtVarKey is a variable key for ExecStmt.
func (ExecStmtVarKeyType) String ¶
func (k ExecStmtVarKeyType) String() string
String defines a Stringer function for debugging and pretty printing.
type LazyTxn ¶
type LazyTxn struct { // States of a LazyTxn should be one of the followings: // Invalid: kv.Transaction == nil && txnFuture == nil // Pending: kv.Transaction == nil && txnFuture != nil // Valid: kv.Transaction != nil && txnFuture == nil kv.Transaction // contains filtered or unexported fields }
LazyTxn wraps kv.Transaction to provide a new kv.Transaction. 1. It holds all statement related modification in the buffer before flush to the txn, so if execute statement meets error, the txn won't be made dirty. 2. It's a lazy transaction, that means it's a txnFuture before StartTS() is really need.
func (*LazyTxn) CacheTableInfo ¶
CacheTableInfo caches the index name.
func (*LazyTxn) GetTableInfo ¶
GetTableInfo returns the cached index name.
func (*LazyTxn) KeysNeedToLock ¶
KeysNeedToLock returns the keys need to be locked.
func (*LazyTxn) LockKeysFunc ¶
func (txn *LazyTxn) LockKeysFunc(ctx context.Context, lockCtx *kv.LockCtx, fn func(), keys ...kv.Key) error
LockKeysFunc Wrap the inner transaction's `LockKeys` to record the status
func (*LazyTxn) RollbackMemDBToCheckpoint ¶
func (txn *LazyTxn) RollbackMemDBToCheckpoint(savepoint *tikv.MemDBCheckpoint)
RollbackMemDBToCheckpoint overrides the Transaction interface.
func (*LazyTxn) SetMemoryFootprintChangeHook ¶
SetMemoryFootprintChangeHook sets the hook to be called when the memory footprint of this transaction changes.
func (*LazyTxn) Wait ¶
func (txn *LazyTxn) Wait(ctx context.Context, sctx sessionctx.Context) (kv.Transaction, error)
Wait converts pending txn to valid
type Opt ¶
type Opt struct {
PreparedPlanCache sessionctx.PlanCache
}
Opt describes the option for creating session
type SchemaAmender ¶
type SchemaAmender struct {
// contains filtered or unexported fields
}
SchemaAmender is used to amend pessimistic transactions for schema change.
func NewSchemaAmenderForTikvTxn ¶
func NewSchemaAmenderForTikvTxn(sess *session) *SchemaAmender
NewSchemaAmenderForTikvTxn creates a schema amender for tikvTxn type.
func (*SchemaAmender) AmendTxn ¶
func (s *SchemaAmender) AmendTxn(ctx context.Context, startInfoSchema tikv.SchemaVer, change *transaction.RelatedSchemaChange, commitMutations transaction.CommitterMutations) (transaction.CommitterMutations, error)
AmendTxn does check and generate amend mutations based on input infoSchema and mutations, mutations need to prewrite are returned, the input commitMutations will not be changed.
type Session ¶
type Session interface { sessionctx.Context Status() uint16 // Flag of current status, such as autocommit. LastInsertID() uint64 // LastInsertID is the last inserted auto_increment ID. LastMessage() string // LastMessage is the info message that may be generated by last command AffectedRows() uint64 // Affected rows by latest executed stmt. // Execute is deprecated, and only used by plugins. Use ExecuteStmt() instead. Execute(context.Context, string) ([]sqlexec.RecordSet, error) // Execute a sql statement. // ExecuteStmt executes a parsed statement. ExecuteStmt(context.Context, ast.StmtNode) (sqlexec.RecordSet, error) // Parse is deprecated, use ParseWithParams() instead. Parse(ctx context.Context, sql string) ([]ast.StmtNode, error) // ExecuteInternal is a helper around ParseWithParams() and ExecuteStmt(). It is not allowed to execute multiple statements. ExecuteInternal(context.Context, string, ...interface{}) (sqlexec.RecordSet, error) String() string // String is used to debug. CommitTxn(context.Context) error RollbackTxn(context.Context) // PrepareStmt executes prepare statement in binary protocol. PrepareStmt(sql string) (stmtID uint32, paramCount int, fields []*ast.ResultField, err error) // CacheGeneralStmt parses the sql, generates the corresponding PlanCacheStmt and cache it. CacheGeneralStmt(sql string) (interface{}, error) // ExecutePreparedStmt executes a prepared statement. // Deprecated: please use ExecuteStmt, this function is left for testing only. // TODO: remove ExecutePreparedStmt. ExecutePreparedStmt(ctx context.Context, stmtID uint32, param []expression.Expression) (sqlexec.RecordSet, error) DropPreparedStmt(stmtID uint32) error // SetSessionStatesHandler sets SessionStatesHandler for type stateType. SetSessionStatesHandler(stateType sessionstates.SessionStateType, handler sessionctx.SessionStatesHandler) SetClientCapability(uint32) // Set client capability flags. SetConnectionID(uint64) SetCommandValue(byte) SetProcessInfo(string, time.Time, byte, uint64) SetTLSState(*tls.ConnectionState) SetCollation(coID int) error SetSessionManager(util.SessionManager) Close() Auth(user *auth.UserIdentity, auth, salt []byte) error AuthWithoutVerification(user *auth.UserIdentity) bool AuthPluginForUser(user *auth.UserIdentity) (string, error) MatchIdentity(username, remoteHost string) (*auth.UserIdentity, error) // Return the information of the txn current running TxnInfo() *txninfo.TxnInfo // PrepareTxnCtx is exported for test. PrepareTxnCtx(context.Context) error // FieldList returns fields list of a table. FieldList(tableName string) (fields []*ast.ResultField, err error) SetPort(port string) // set cur session operations allowed when tikv disk full happens. SetDiskFullOpt(level kvrpcpb.DiskFullOpt) GetDiskFullOpt() kvrpcpb.DiskFullOpt ClearDiskFullOpt() // SetExtensions sets the `*extension.SessionExtensions` object SetExtensions(extensions *extension.SessionExtensions) }
Session context, it is consistent with the lifecycle of a client connection.
func CreateSession ¶
CreateSession creates a new session environment.
func CreateSession4Test ¶
CreateSession4Test creates a new session environment for test.
func CreateSession4TestWithOpt ¶
CreateSession4TestWithOpt creates a new session environment for test.
type StmtHistory ¶
type StmtHistory struct {
// contains filtered or unexported fields
}
StmtHistory holds all histories of statements in a txn.
func GetHistory ¶
func GetHistory(ctx sessionctx.Context) *StmtHistory
GetHistory get all stmtHistory in current txn. Exported only for test.
func (*StmtHistory) Add ¶
func (h *StmtHistory) Add(st sqlexec.Statement, stmtCtx *stmtctx.StatementContext)
Add appends a stmt to history list.
func (*StmtHistory) Count ¶
func (h *StmtHistory) Count() int
Count returns the count of the history.