import "github.com/pingcap/tidb/bindinfo"
cache.go handle.go session_handle.go
const ( // Using is the bind info's in use status. Using = "using" // Invalid is the bind info's invalid status. Invalid = "invalid" // PendingVerify means the bind info needs to be verified. PendingVerify = "pending verify" // Rejected means that the bind has been rejected after verify process. // We can retry it after certain time has passed. Rejected = "rejected" // Manual indicates the binding is created by SQL like "create binding for ...". Manual = "manual" // Capture indicates the binding is captured by TiDB automatically. Capture = "capture" // Evolve indicates the binding is evolved by TiDB from old bindings. Evolve = "evolve" // Builtin indicates the binding is a builtin record for internal locking purpose. It is also the status for the builtin binding. Builtin = "builtin" )
const ( // OwnerKey is the bindinfo owner path that is saved to etcd. OwnerKey = "/tidb/bindinfo/owner" // Prompt is the prompt for bindinfo owner manager. Prompt = "bindinfo" // BuiltinPseudoSQL4BindLock is used to simulate LOCK TABLE for mysql.bind_info. BuiltinPseudoSQL4BindLock = "builtin_pseudo_sql_for_bind_lock" )
const SessionBindInfoKeyType sessionBindInfoKeyType = 0
SessionBindInfoKeyType is a variable key for store session bind info.
Lease influences the duration of loading bind info and handling invalid bind.
func GenerateBindSQL(ctx context.Context, stmtNode ast.StmtNode, planHint string, captured bool, defaultDB string) string
GenerateBindSQL generates binding sqls from stmt node and plan hints.
type BindHandle struct {
// contains filtered or unexported fields
}
BindHandle is used to handle all global sql bind operations.
func NewBindHandle(ctx sessionctx.Context) *BindHandle
NewBindHandle creates a new BindHandle.
func (h *BindHandle) AddBindRecord(sctx sessionctx.Context, record *BindRecord) (err error)
AddBindRecord adds a BindRecord to the storage and BindRecord to the cache.
func (h *BindHandle) AddDropInvalidBindTask(invalidBindRecord *BindRecord)
AddDropInvalidBindTask adds BindRecord which needs to be deleted into invalidBindRecordMap.
func (h *BindHandle) AddEvolvePlanTask(originalSQL, DB string, binding Binding)
AddEvolvePlanTask adds the evolve plan task into memory cache. It would be flushed to store periodically.
func (h *BindHandle) CaptureBaselines()
CaptureBaselines is used to automatically capture plan baselines.
func (h *BindHandle) Clear()
Clear resets the bind handle. It is only used for test.
func (h *BindHandle) CreateBindRecord(sctx sessionctx.Context, record *BindRecord) (err error)
CreateBindRecord creates a BindRecord to the storage and the cache. It replaces all the exists bindings for the same normalized SQL.
func (h *BindHandle) DropBindRecord(originalSQL, db string, binding *Binding) (err error)
DropBindRecord drops a BindRecord to the storage and BindRecord int the cache.
func (h *BindHandle) DropInvalidBindRecord()
DropInvalidBindRecord executes the drop BindRecord tasks.
func (h *BindHandle) FlushBindings() error
FlushBindings flushes the BindRecord in temp maps to storage and loads them into cache.
func (h *BindHandle) GetAllBindRecord() (bindRecords []*BindRecord)
GetAllBindRecord returns all bind records in cache.
func (h *BindHandle) GetBindRecord(hash, normdOrigSQL, db string) *BindRecord
GetBindRecord returns the BindRecord of the (normdOrigSQL,db) if BindRecord exist.
func (h *BindHandle) HandleEvolvePlanTask(sctx sessionctx.Context, adminEvolve bool) error
HandleEvolvePlanTask tries to evolve one plan task. It only handle one tasks once because we want each task could use the latest parameters.
func (h *BindHandle) LockBindInfoSQL() string
LockBindInfoSQL simulates LOCK TABLE by updating a same row in each pessimistic transaction.
func (h *BindHandle) ReloadBindings() error
ReloadBindings clears existing binding cache and do a full load from mysql.bind_info. It is used to maintain consistency between cache and mysql.bind_info if the table is deleted or truncated.
func (h *BindHandle) SaveEvolveTasksToStore()
SaveEvolveTasksToStore saves the evolve task into store.
func (h *BindHandle) Size() int
Size returns the size of bind info cache.
func (h *BindHandle) Update(fullLoad bool) (err error)
Update updates the global sql bind cache.
BindRecord represents a sql bind record retrieved from the storage.
func (br *BindRecord) FindBinding(hint string) *Binding
FindBinding find bindings in BindRecord.
func (br *BindRecord) HasUsingBinding() bool
HasUsingBinding checks if there are any using bindings in bind record.
type Binding struct { BindSQL string // Status represents the status of the binding. It can only be one of the following values: // 1. deleted: BindRecord is deleted, can not be used anymore. // 2. using: Binding is in the normal active mode. Status string CreateTime types.Time UpdateTime types.Time Source string Charset string Collation string // Hint is the parsed hints, it is used to bind hints to stmt node. Hint *hint.HintsSet // ID is the string form of Hint. It would be non-empty only when the status is `Using` or `PendingVerify`. ID string }
Binding stores the basic bind hint info.
SinceUpdateTime returns the duration since last update time. Export for test.
type SessionHandle struct {
// contains filtered or unexported fields
}
SessionHandle is used to handle all session sql bind operations.
func NewSessionBindHandle(parser *parser.Parser) *SessionHandle
NewSessionBindHandle creates a new SessionBindHandle.
func (h *SessionHandle) Close()
Close closes the session handle.
func (h *SessionHandle) CreateBindRecord(sctx sessionctx.Context, record *BindRecord) (err error)
CreateBindRecord creates a BindRecord to the cache. It replaces all the exists bindings for the same normalized SQL.
func (h *SessionHandle) DropBindRecord(originalSQL, db string, binding *Binding) error
DropBindRecord drops a BindRecord in the cache.
func (h *SessionHandle) GetAllBindRecord() (bindRecords []*BindRecord)
GetAllBindRecord return all session bind info.
func (h *SessionHandle) GetBindRecord(normdOrigSQL, db string) *BindRecord
GetBindRecord return the BindMeta of the (normdOrigSQL,db) if BindMeta exist.
Package bindinfo imports 28 packages (graph) and is imported by 27 packages. Updated 2021-01-12. Refresh now. Tools for package owners.