tidb: github.com/pingcap/tidb/bindinfo Index | Files

package bindinfo

import "github.com/pingcap/tidb/bindinfo"

Index

Package Files

cache.go handle.go session_handle.go

Constants

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"
)
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"
)
const SessionBindInfoKeyType sessionBindInfoKeyType = 0

SessionBindInfoKeyType is a variable key for store session bind info.

Variables

var Lease = 3 * time.Second

Lease influences the duration of loading bind info and handling invalid bind.

func GenerateBindSQL Uses

func GenerateBindSQL(ctx context.Context, stmtNode ast.StmtNode, planHint string) string

GenerateBindSQL generates binding sqls from stmt node and plan hints.

type BindHandle Uses

type BindHandle struct {
    // contains filtered or unexported fields
}

BindHandle is used to handle all global sql bind operations.

func NewBindHandle Uses

func NewBindHandle(ctx sessionctx.Context) *BindHandle

NewBindHandle creates a new BindHandle.

func (*BindHandle) AddBindRecord Uses

func (h *BindHandle) AddBindRecord(sctx sessionctx.Context, record *BindRecord) (err error)

AddBindRecord adds a BindRecord to the storage and BindRecord to the cache.

func (*BindHandle) AddDropInvalidBindTask Uses

func (h *BindHandle) AddDropInvalidBindTask(invalidBindRecord *BindRecord)

AddDropInvalidBindTask adds BindRecord which needs to be deleted into invalidBindRecordMap.

func (*BindHandle) AddEvolvePlanTask Uses

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 (*BindHandle) CaptureBaselines Uses

func (h *BindHandle) CaptureBaselines()

CaptureBaselines is used to automatically capture plan baselines.

func (*BindHandle) Clear Uses

func (h *BindHandle) Clear()

Clear resets the bind handle. It is only used for test.

func (*BindHandle) CreateBindRecord Uses

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 (*BindHandle) DropBindRecord Uses

func (h *BindHandle) DropBindRecord(originalSQL, db string, binding *Binding) (err error)

DropBindRecord drops a BindRecord to the storage and BindRecord int the cache.

func (*BindHandle) DropInvalidBindRecord Uses

func (h *BindHandle) DropInvalidBindRecord()

DropInvalidBindRecord executes the drop BindRecord tasks.

func (*BindHandle) FlushBindings Uses

func (h *BindHandle) FlushBindings() error

FlushBindings flushes the BindRecord in temp maps to storage and loads them into cache.

func (*BindHandle) GetAllBindRecord Uses

func (h *BindHandle) GetAllBindRecord() (bindRecords []*BindRecord)

GetAllBindRecord returns all bind records in cache.

func (*BindHandle) GetBindRecord Uses

func (h *BindHandle) GetBindRecord(hash, normdOrigSQL, db string) *BindRecord

GetBindRecord returns the BindRecord of the (normdOrigSQL,db) if BindRecord exist.

func (*BindHandle) HandleEvolvePlanTask Uses

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 (*BindHandle) ReloadBindings Uses

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 (*BindHandle) SaveEvolveTasksToStore Uses

func (h *BindHandle) SaveEvolveTasksToStore()

SaveEvolveTasksToStore saves the evolve task into store.

func (*BindHandle) Size Uses

func (h *BindHandle) Size() int

Size returns the size of bind info cache.

func (*BindHandle) Update Uses

func (h *BindHandle) Update(fullLoad bool) (err error)

Update updates the global sql bind cache.

type BindRecord Uses

type BindRecord struct {
    OriginalSQL string
    Db          string

    Bindings []Binding
}

BindRecord represents a sql bind record retrieved from the storage.

func (*BindRecord) FindBinding Uses

func (br *BindRecord) FindBinding(hint string) *Binding

FindBinding find bindings in BindRecord.

func (*BindRecord) HasUsingBinding Uses

func (br *BindRecord) HasUsingBinding() bool

HasUsingBinding checks if there are any using bindings in bind record.

type Binding Uses

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.

func (*Binding) SinceUpdateTime Uses

func (b *Binding) SinceUpdateTime() (time.Duration, error)

SinceUpdateTime returns the duration since last update time. Export for test.

type SessionHandle Uses

type SessionHandle struct {
    // contains filtered or unexported fields
}

SessionHandle is used to handle all session sql bind operations.

func NewSessionBindHandle Uses

func NewSessionBindHandle(parser *parser.Parser) *SessionHandle

NewSessionBindHandle creates a new SessionBindHandle.

func (*SessionHandle) Close Uses

func (h *SessionHandle) Close()

Close closes the session handle.

func (*SessionHandle) CreateBindRecord Uses

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 (*SessionHandle) DropBindRecord Uses

func (h *SessionHandle) DropBindRecord(originalSQL, db string, binding *Binding) error

DropBindRecord drops a BindRecord in the cache.

func (*SessionHandle) GetAllBindRecord Uses

func (h *SessionHandle) GetAllBindRecord() (bindRecords []*BindRecord)

GetAllBindRecord return all session bind info.

func (*SessionHandle) GetBindRecord Uses

func (h *SessionHandle) GetBindRecord(normdOrigSQL, db string) *BindRecord

GetBindRecord return the BindMeta of the (normdOrigSQL,db) if BindMeta exist.

Package bindinfo imports 30 packages (graph) and is imported by 27 packages. Updated 2020-05-31. Refresh now. Tools for package owners.