Documentation ¶
Index ¶
- Constants
- Variables
- func BootstrapSession(store kv.Storage) (*domain.Domain, error)
- func Compile(ctx context.Context, sctx sessionctx.Context, stmtNode ast.StmtNode) (sqlexec.Statement, error)
- func CreateSessionWithDomain(store kv.Storage, dom *domain.Domain) (*session, error)
- func DisableStats4Test()
- func GetDomain(store kv.Storage) (*domain.Domain, error)
- func GetRows4Test(ctx context.Context, sctx sessionctx.Context, rs sqlexec.RecordSet) ([]chunk.Row, error)
- func Parse(ctx sessionctx.Context, src string) ([]ast.StmtNode, error)
- func ResetMockAutoRandIDRetryCount(failTimes int64)
- func ResetStoreForWithTiKVTest(store kv.Storage)
- func ResultSetToStringSlice(ctx context.Context, s Session, rs sqlexec.RecordSet) ([][]string, error)
- func SetSchemaLease(lease time.Duration)
- func SetStatsLease(lease time.Duration)
- type Opt
- type Session
- type StmtHistory
- type TxnState
- func (st *TxnState) BatchGet(ctx context.Context, keys []kv.Key) (map[string][]byte, error)
- func (st *TxnState) Commit(ctx context.Context) error
- func (st *TxnState) Delete(k kv.Key) error
- func (st *TxnState) Discard()
- func (st *TxnState) Flush() (int, error)
- func (st *TxnState) Get(ctx context.Context, k kv.Key) ([]byte, error)
- func (st *TxnState) GoString() string
- func (st *TxnState) Iter(k kv.Key, upperBound kv.Key) (kv.Iterator, error)
- func (st *TxnState) IterReverse(k kv.Key) (kv.Iterator, error)
- func (st *TxnState) KeysNeedToLock() ([]kv.Key, error)
- func (st *TxnState) NewStagingBuffer() kv.MemBuffer
- func (st *TxnState) Rollback() error
- func (st *TxnState) Set(k kv.Key, v []byte) error
- func (st *TxnState) Size() int
- func (st *TxnState) String() string
- func (st *TxnState) Valid() bool
Constants ¶
const ( // CreateUserTable is the SQL statement creates User table in system db. CreateUserTable = `` /* 1698-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(60) 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 = `` /* 1127-byte string literal not displayed */ // CreateTablePrivTable is the SQL statement creates table scope privilege table in system db. CreateTablePrivTable = `` /* 427-byte string literal not displayed */ // CreateColumnPrivTable is the SQL statement creates column scope privilege table in system db. CreateColumnPrivTable = `` /* 299-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 = `` /* 160-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 = `` /* 392-byte string literal not displayed */ // CreateStatsMetaTable stores the meta of table statistics. CreateStatsMetaTable = `` /* 270-byte string literal not displayed */ // CreateStatsColsTable stores the statistics of table columns. CreateStatsColsTable = `` /* 600-byte string literal not displayed */ // CreateStatsBucketsTable stores the histogram info for every table columns. CreateStatsBucketsTable = `` /* 349-byte string literal not displayed */ // CreateGCDeleteRangeTable stores schemas which can be deleted by DeleteRange. CreateGCDeleteRangeTable = `` /* 390-byte string literal not displayed */ // CreateGCDeleteRangeDoneTable stores schemas which are already deleted by DeleteRange. CreateGCDeleteRangeDoneTable = `` /* 400-byte string literal not displayed */ // CreateStatsFeedbackTable stores the feedback info which is used to update stats. CreateStatsFeedbackTable = `` /* 216-byte string literal not displayed */ // CreateBindInfoTable stores the sql bind info which is used to update globalBindCache. CreateBindInfoTable = `` /* 570-byte string literal not displayed */ // CreateRoleEdgesTable stores the role and user relationship information. CreateRoleEdgesTable = `` /* 432-byte string literal not displayed */ // CreateDefaultRolesTable stores the active roles for a user. CreateDefaultRolesTable = `` /* 356-byte string literal not displayed */ // CreateStatsTopNTable stores topn data of a cmsketch with top n. CreateStatsTopNTable = `` /* 242-byte string literal not displayed */ // CreateExprPushdownBlacklist stores the expressions which are not allowed to be pushed down. CreateExprPushdownBlacklist = `` /* 172-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 );` )
Variables ¶
var (
ErrForUpdateCantRetry = terror.ClassSession.New(errno.ErrForUpdateCantRetry, errno.MySQLErrName[errno.ErrForUpdateCantRetry])
)
Session errors.
var SchemaChangedWithoutRetry uint32
SchemaChangedWithoutRetry is used for testing.
Functions ¶
func BootstrapSession ¶
BootstrapSession runs the first time when the TiDB server start.
func Compile ¶
func Compile(ctx context.Context, sctx sessionctx.Context, stmtNode ast.StmtNode) (sqlexec.Statement, error)
Compile is safe for concurrent use by multiple goroutines.
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 createSesion directly.
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 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 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 Opt ¶
type Opt struct {
PreparedPlanCache *kvcache.SimpleLRUCache
}
Opt describes the option for creating session
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, use ExecuteStmt() instead. Execute(context.Context, string) ([]sqlexec.RecordSet, error) // Execute a sql statement. ExecuteInternal(context.Context, string) ([]sqlexec.RecordSet, error) // Execute a internal sql statement. ExecuteStmt(context.Context, ast.StmtNode) (sqlexec.RecordSet, error) Parse(ctx context.Context, sql string) ([]ast.StmtNode, 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) // ExecutePreparedStmt executes a prepared statement. ExecutePreparedStmt(ctx context.Context, stmtID uint32, param []types.Datum) (sqlexec.RecordSet, error) DropPreparedStmt(stmtID uint32) error 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 []byte, salt []byte) bool ShowProcess() *util.ProcessInfo // PrepareTxnCtx is exported for test. PrepareTxnCtx(context.Context) // FieldList returns fields list of a table. FieldList(tableName string) (fields []*ast.ResultField, err error) }
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.
type TxnState ¶
type TxnState struct { // States of a TxnState 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 }
TxnState 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 (*TxnState) IterReverse ¶
IterReverse overrides the Transaction interface.
func (*TxnState) KeysNeedToLock ¶
KeysNeedToLock returns the keys need to be locked.
func (*TxnState) NewStagingBuffer ¶
NewStagingBuffer returns a new child write buffer.