bindinfo

package
v1.1.0-beta.0...-9815b45 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Enabled is the bind info's in enabled status.
	// It is the same as the previous 'Using' status.
	// Only use 'Enabled' status in the future, not the 'Using' status.
	// The 'Using' status is preserved for compatibility.
	Enabled = "enabled"
	// Disabled is the bind info's in disabled status.
	Disabled = "disabled"
	// Using is the bind info's in use status.
	// The 'Using' status is preserved for compatibility.
	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"
	// History indicate the binding is created from statement summary by plan digest
	History = "history"
)
View Source
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"
)
View Source
const SessionBindInfoKeyType sessionBindInfoKeyType = 0

SessionBindInfoKeyType is a variable key for store session bind info.

Variables

View Source
var Lease = 3 * time.Second

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

Functions

func GenerateBindSQL

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

GenerateBindSQL generates binding sqls from stmt node and plan hints.

func ParseCaptureTableFilter

func ParseCaptureTableFilter(tableFilter string) (f tablefilter.Filter, valid bool)

ParseCaptureTableFilter checks whether this filter is valid and parses it.

Types

type BindHandle

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

BindHandle is used to handle all global sql bind operations.

func NewBindHandle

func NewBindHandle(ctx sessionctx.Context) *BindHandle

NewBindHandle creates a new BindHandle.

func (*BindHandle) AddBindRecord

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

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

AddDropInvalidBindTask adds BindRecord which needs to be deleted into invalidBindRecordMap.

func (*BindHandle) AddEvolvePlanTask

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

func (h *BindHandle) CaptureBaselines()

CaptureBaselines is used to automatically capture plan baselines.

func (*BindHandle) Clear

func (h *BindHandle) Clear()

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

func (*BindHandle) CreateBindRecord

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

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

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

func (*BindHandle) DropBindRecordByDigest

func (h *BindHandle) DropBindRecordByDigest(sqlDigest string) (deletedRows uint64, err error)

DropBindRecordByDigest drop BindRecord to the storage and BindRecord int the cache.

func (*BindHandle) DropInvalidBindRecord

func (h *BindHandle) DropInvalidBindRecord()

DropInvalidBindRecord executes the drop BindRecord tasks.

func (*BindHandle) FlushBindings

func (h *BindHandle) FlushBindings() error

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

func (*BindHandle) GCBindRecord

func (h *BindHandle) GCBindRecord() (err error)

GCBindRecord physically removes the deleted bind records in mysql.bind_info.

func (*BindHandle) GetAllBindRecord

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

GetAllBindRecord returns all bind records in cache.

func (*BindHandle) GetBindRecord

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

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

func (*BindHandle) GetBindRecordBySQLDigest

func (h *BindHandle) GetBindRecordBySQLDigest(sqlDigest string) (*BindRecord, error)

GetBindRecordBySQLDigest returns the BindRecord of the sql digest.

func (*BindHandle) GetMemCapacity

func (h *BindHandle) GetMemCapacity() (memCapacity int64)

GetMemCapacity returns the memory capacity for the bind cache.

func (*BindHandle) GetMemUsage

func (h *BindHandle) GetMemUsage() (memUsage int64)

GetMemUsage returns the memory usage for the bind cache.

func (*BindHandle) GetScope

func (h *BindHandle) GetScope(status string) variable.ScopeFlag

GetScope gets the status variables scope.

func (*BindHandle) HandleEvolvePlanTask

func (h *BindHandle) HandleEvolvePlanTask(sctx sessionctx.Context, adminEvolve bool) error

HandleEvolvePlanTask tries to evolve one plan task. It only processes one task at a time because we want each task to use the latest parameters.

func (*BindHandle) LockBindInfoSQL

func (h *BindHandle) LockBindInfoSQL() string

LockBindInfoSQL simulates LOCK TABLE by updating a same row in each pessimistic transaction.

func (*BindHandle) ReloadBindings

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) Reset

func (h *BindHandle) Reset(ctx sessionctx.Context)

Reset is to reset the BindHandle and clean old info.

func (*BindHandle) SaveEvolveTasksToStore

func (h *BindHandle) SaveEvolveTasksToStore()

SaveEvolveTasksToStore saves the evolve task into store.

func (*BindHandle) SetBindCacheCapacity

func (h *BindHandle) SetBindCacheCapacity(capacity int64)

SetBindCacheCapacity reset the capacity for the bindCache. It will not affect already cached BindRecords.

func (*BindHandle) SetBindRecordStatus

func (h *BindHandle) SetBindRecordStatus(originalSQL string, binding *Binding, newStatus string) (ok bool, err error)

SetBindRecordStatus set a BindRecord's status to the storage and bind cache.

func (*BindHandle) Size

func (h *BindHandle) Size() int

Size returns the size of bind info cache.

func (*BindHandle) Stats

func (h *BindHandle) Stats(vars *variable.SessionVars) (map[string]interface{}, error)

Stats returns the server statistics.

func (*BindHandle) Update

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

Update updates the global sql bind cache.

type BindRecord

type BindRecord struct {
	OriginalSQL string
	Db          string

	Bindings []Binding
}

BindRecord represents a sql bind record retrieved from the storage.

func (*BindRecord) FindBinding

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

FindBinding find bindings in BindRecord.

func (*BindRecord) FindEnabledBinding

func (br *BindRecord) FindEnabledBinding() *Binding

FindEnabledBinding gets the enabled binding. There is at most one binding that can be used now.

func (*BindRecord) HasAvailableBinding

func (br *BindRecord) HasAvailableBinding() bool

HasAvailableBinding checks if there are any available bindings in bind record. The available means the binding can be used or can be converted into a usable status. It includes the 'Enabled', 'Using' and 'Disabled' status.

func (*BindRecord) HasEnabledBinding

func (br *BindRecord) HasEnabledBinding() bool

HasEnabledBinding checks if there are any enabled bindings in bind record.

type Binding

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. enabled, 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 `json:"-"`
	// ID is the string form of Hint. It would be non-empty only when the status is `Using` or `PendingVerify`.
	ID         string `json:"-"`
	SQLDigest  string
	PlanDigest string
}

Binding stores the basic bind hint info.

func (*Binding) IsBindingAvailable

func (b *Binding) IsBindingAvailable() bool

IsBindingAvailable returns whether the binding is available. The available means the binding can be used or can be converted into a usable status. It includes the 'Enabled', 'Using' and 'Disabled' status.

func (*Binding) IsBindingEnabled

func (b *Binding) IsBindingEnabled() bool

IsBindingEnabled returns whether the binding is enabled.

func (*Binding) SinceUpdateTime

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

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

type SessionHandle

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

SessionHandle is used to handle all session sql bind operations.

func NewSessionBindHandle

func NewSessionBindHandle() *SessionHandle

NewSessionBindHandle creates a new SessionBindHandle.

func (*SessionHandle) Close

func (h *SessionHandle) Close()

Close closes the session handle.

func (*SessionHandle) CreateBindRecord

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) DecodeSessionStates

func (h *SessionHandle) DecodeSessionStates(ctx context.Context, sctx sessionctx.Context, sessionStates *sessionstates.SessionStates) error

DecodeSessionStates implements SessionStatesHandler.DecodeSessionStates interface.

func (*SessionHandle) DropBindRecord

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

DropBindRecord drops a BindRecord in the cache.

func (*SessionHandle) DropBindRecordByDigest

func (h *SessionHandle) DropBindRecordByDigest(sqlDigest string) error

DropBindRecordByDigest drop BindRecord in the cache.

func (*SessionHandle) EncodeSessionStates

func (h *SessionHandle) EncodeSessionStates(ctx context.Context, sctx sessionctx.Context, sessionStates *sessionstates.SessionStates) error

EncodeSessionStates implements SessionStatesHandler.EncodeSessionStates interface.

func (*SessionHandle) GetAllBindRecord

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

GetAllBindRecord return all session bind info.

func (*SessionHandle) GetBindRecord

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

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

func (*SessionHandle) GetBindRecordBySQLDigest

func (h *SessionHandle) GetBindRecordBySQLDigest(sqlDigest string) (*BindRecord, error)

GetBindRecordBySQLDigest return all BindMeta corresponding to sqlDigest.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL