Documentation ¶
Index ¶
- Constants
- Variables
- func DeepCopyNode(node sql.Node) (sql.Node, error)
- func DefaultRuleSelector(id RuleId) bool
- func FlagIsSet(flags *sql.QueryFlags, flag int) bool
- func Schemas(nodes []sql.Node) sql.Schema
- func SelectAllBatches(string) bool
- func SetPreparedStmts(v bool)
- func ValidateAddColumn(schema sql.Schema, ac *plan.AddColumn) (sql.Schema, error)
- type Analyzer
- func (a *Analyzer) Analyze(ctx *sql.Context, node sql.Node, scope *plan.Scope, qFlags *sql.QueryFlags) (sql.Node, error)
- func (a *Analyzer) Log(msg string, args ...interface{})
- func (a *Analyzer) LogDiff(prev, next sql.Node)
- func (a *Analyzer) LogFn() func(string, ...any)
- func (a *Analyzer) LogNode(n sql.Node)
- func (a *Analyzer) PopDebugContext()
- func (a *Analyzer) PushDebugContext(msg string)
- type Batch
- func (b *Batch) Eval(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, ...) (sql.Node, transform.TreeIdentity, error)
- func (b *Batch) EvalWithSelector(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, ...) (sql.Node, transform.TreeIdentity, error)
- type BatchSelector
- type Builder
- func (ab *Builder) AddPostAnalyzeRule(id RuleId, fn RuleFunc) *Builder
- func (ab *Builder) AddPostValidationRule(id RuleId, fn RuleFunc) *Builder
- func (ab *Builder) AddPreAnalyzeRule(id RuleId, fn RuleFunc) *Builder
- func (ab *Builder) AddPreValidationRule(id RuleId, fn RuleFunc) *Builder
- func (ab *Builder) Build() *Analyzer
- func (ab *Builder) RemoveAfterAllRule(id RuleId) *Builder
- func (ab *Builder) RemoveDefaultRule(id RuleId) *Builder
- func (ab *Builder) RemoveOnceAfterRule(id RuleId) *Builder
- func (ab *Builder) RemoveOnceBeforeRule(id RuleId) *Builder
- func (ab *Builder) RemoveValidationRule(id RuleId) *Builder
- func (ab *Builder) WithDebug() *Builder
- type Catalog
- func (c *Catalog) AllDatabases(ctx *sql.Context) []sql.Database
- func (c *Catalog) AuthorizationHandler() sql.AuthorizationHandler
- func (c *Catalog) CreateDatabase(ctx *sql.Context, dbName string, collation sql.CollationID) error
- func (c *Catalog) DataLength(ctx *sql.Context, db string, table sql.Table) (uint64, error)
- func (c *Catalog) Database(ctx *sql.Context, db string) (sql.Database, error)
- func (c *Catalog) DatabaseTable(ctx *sql.Context, db sql.Database, tableName string) (sql.Table, sql.Database, error)
- func (c *Catalog) DatabaseTableAsOf(ctx *sql.Context, db sql.Database, tableName string, asOf interface{}) (sql.Table, sql.Database, error)
- func (c *Catalog) DropDbStats(ctx *sql.Context, db string, flush bool) error
- func (c *Catalog) DropStats(ctx *sql.Context, qual sql.StatQualifier, cols []string) error
- func (c *Catalog) ExternalStoredProcedure(ctx *sql.Context, name string, numOfParams int) (*sql.ExternalStoredProcedureDetails, error)
- func (c *Catalog) ExternalStoredProcedures(ctx *sql.Context, name string) ([]sql.ExternalStoredProcedureDetails, error)
- func (c *Catalog) Function(ctx *sql.Context, name string) (sql.Function, bool)
- func (c *Catalog) GetBinlogPrimaryController() binlogreplication.BinlogPrimaryController
- func (c *Catalog) GetBinlogReplicaController() binlogreplication.BinlogReplicaController
- func (c *Catalog) GetStats(ctx *sql.Context, qual sql.StatQualifier, cols []string) (sql.Statistic, bool)
- func (c *Catalog) GetTableStats(ctx *sql.Context, db string, table sql.Table) ([]sql.Statistic, error)
- func (c *Catalog) HasBinlogPrimaryController() bool
- func (c *Catalog) HasBinlogReplicaController() bool
- func (c *Catalog) HasDatabase(ctx *sql.Context, db string) bool
- func (c *Catalog) LockTable(ctx *sql.Context, table string)
- func (c *Catalog) RefreshTableStats(ctx *sql.Context, table sql.Table, db string) error
- func (c *Catalog) RegisterFunction(ctx *sql.Context, fns ...sql.Function)
- func (c *Catalog) RemoveDatabase(ctx *sql.Context, dbName string) error
- func (c *Catalog) RowCount(ctx *sql.Context, db string, table sql.Table) (uint64, error)
- func (c *Catalog) SetStats(ctx *sql.Context, stats sql.Statistic) error
- func (c *Catalog) Table(ctx *sql.Context, dbName, tableName string) (sql.Table, sql.Database, error)
- func (c *Catalog) TableAsOf(ctx *sql.Context, dbName, tableName string, asOf interface{}) (sql.Table, sql.Database, error)
- func (c *Catalog) TableFunction(ctx *sql.Context, name string) (sql.TableFunction, bool)
- func (c *Catalog) TableSchema(ctx *sql.Context, dbName, schemaName, tableName string) (sql.Table, sql.Database, error)
- func (c *Catalog) UnlockTables(ctx *sql.Context, id uint32) error
- func (c *Catalog) WithTableFunctions(fns ...sql.TableFunction) (sql.TableFunctionProvider, error)
- type IndexScanOp
- type RoutineTable
- type Rule
- type RuleFunc
- type RuleId
- type RuleSelector
- type TableAliases
Constants ¶
const MaxBytePrefix = 3072
Variables ¶
var AlwaysBeforeDefault []Rule
AlwaysBeforeDefault contains the rules to be applied just once before the DefaultRules. These are an extension of the OnceBeforeDefault rules that will always apply to nodes, unlike the OnceBeforeDefault rules that may be excluded depending on the node. This is only used by integrators.
var DefaultRules = []Rule{
{validateStarExpressionsId, validateStarExpressions},
{pushdownSubqueryAliasFiltersId, pushdownSubqueryAliasFilters},
{pruneTablesId, pruneTables},
{validateCheckConstraintId, validateCheckConstraints},
{unnestInSubqueriesId, unnestInSubqueries},
{resolveSubqueriesId, resolveSubqueries},
{replaceCrossJoinsId, replaceCrossJoins},
}
DefaultRules to apply when analyzing nodes.
var DefaultValidationRules = []Rule{ {validateResolvedId, validateResolved}, {validateOrderById, validateOrderBy}, {validateGroupById, validateGroupBy}, {validateSchemaSourceId, validateSchemaSource}, {validateIndexCreationId, validateIndexCreation}, {ValidateOperandsId, validateOperands}, {validateIntervalUsageId, validateIntervalUsage}, {validateSubqueryColumnsId, validateSubqueryColumns}, {validateUnionSchemasMatchId, validateUnionSchemasMatch}, {validateAggregationsId, validateAggregations}, }
DefaultValidationRules to apply while analyzing nodes.
var ErrInAnalysis = errors.NewKind("error in analysis: %s")
ErrInAnalysis is thrown for generic analyzer errors
var ErrInvalidNodeType = errors.NewKind("%s: invalid node of type: %T")
ErrInvalidNodeType is thrown when the analyzer can't handle a particular kind of node type
var ErrMaxAnalysisIters = errors.NewKind("exceeded max analysis iterations (%d)")
ErrMaxAnalysisIters is thrown when the analysis iterations are exceeded
var ( // ErrOrderByColumnIndex is returned when in an order clause there is a // column that is unknown. ErrOrderByColumnIndex = errors.NewKind("unknown column %d in order by clause") )
var OnceAfterAll []Rule
var OnceAfterDefault = []Rule{
{unnestExistsSubqueriesId, unnestExistsSubqueries},
{moveJoinCondsToFilterId, moveJoinConditionsToFilter},
{finalizeUnionsId, finalizeUnions},
{loadTriggersId, loadTriggers},
{processTruncateId, processTruncate},
{stripTableNameInDefaultsId, stripTableNamesFromColumnDefaults},
{pushFiltersId, pushFilters},
{optimizeJoinsId, optimizeJoins},
{finalizeSubqueriesId, finalizeSubqueries},
{applyIndexesFromOuterScopeId, applyIndexesFromOuterScope},
{replaceAggId, replaceAgg},
{replaceIdxSortId, replaceIdxSort},
{eraseProjectionId, eraseProjection},
{flattenDistinctId, flattenDistinct},
{insertTopNId, insertTopNNodes},
{replaceIdxOrderByDistanceId, replaceIdxOrderByDistance},
{applyHashInId, applyHashIn},
{assignRoutinesId, assignRoutines},
{modifyUpdateExprsForJoinId, modifyUpdateExprsForJoin},
{applyForeignKeysId, applyForeignKeys},
}
var OnceBeforeDefault = []Rule{ {applyDefaultSelectLimitId, applyDefaultSelectLimit}, {replaceCountStarId, replaceCountStar}, {validateOffsetAndLimitId, validateOffsetAndLimit}, {validateCreateTableId, validateCreateTable}, {validateAlterTableId, validateAlterTable}, {validateExprSemId, validateExprSem}, {validateCreateProcedureId, validateCreateProcedure}, {resolveDropConstraintId, resolveDropConstraint}, {resolveAlterColumnId, resolveAlterColumn}, {validateDropTablesId, validateDropTables}, {resolveCreateSelectId, resolveCreateSelect}, {validateDropConstraintId, validateDropConstraint}, {resolveUnionsId, resolveUnions}, {validateCreateTriggerId, validateCreateTrigger}, {ValidateColumnDefaultsId, validateColumnDefaults}, {validateReadOnlyDatabaseId, validateReadOnlyDatabase}, {validateReadOnlyTransactionId, validateReadOnlyTransaction}, {validateDatabaseSetId, validateDatabaseSet}, {validateDeleteFromId, validateDeleteFrom}, {simplifyFiltersId, simplifyFilters}, {pushNotFiltersId, pushNotFilters}, {hoistOutOfScopeFiltersId, hoistOutOfScopeFilters}, }
OnceBeforeDefault contains the rules to be applied just once before the DefaultRules.
var PreparedStmtDisabled bool
Functions ¶
func DefaultRuleSelector ¶ added in v0.12.0
func FlagIsSet ¶ added in v0.19.0
func FlagIsSet(flags *sql.QueryFlags, flag int) bool
FlagIsSet returns whether a set of query flag has the |flag| bit marked, or a default value if |flags| is nil. Flags for rule selecting are enabled by default (true), flags for execution behavior are disabled by default (false).
func Schemas ¶ added in v0.18.0
Schemas returns the Schemas for the nodes given appended in to a single one
func SelectAllBatches ¶ added in v0.12.0
func SetPreparedStmts ¶ added in v0.12.0
func SetPreparedStmts(v bool)
func ValidateAddColumn ¶ added in v0.19.0
ValidateAddColumn validates that the column specified in |ac| can be added to the specified |schema|. A new Schema is returned, with the added column, if the column can be added. Otherwise, an error is returned if there are any validation errors.
Types ¶
type Analyzer ¶
type Analyzer struct { // Whether to log various debugging messages Debug bool // Whether to output the query plan at each step of the analyzer Verbose bool // Batches of Rules to apply. Batches []*Batch // Catalog of databases and registered functions. Catalog *Catalog // Coster estimates the incremental CPU+memory cost for execution operators. Coster memo.Coster // ExecBuilder converts a sql.Node tree into an executable iterator. ExecBuilder sql.NodeExecBuilder // contains filtered or unexported fields }
Analyzer analyzes nodes of the execution plan and applies rules and validations to them.
func NewDefault ¶
func NewDefault(provider sql.DatabaseProvider) *Analyzer
NewDefault creates a default Analyzer instance with all default Rules and configuration. To add custom rules, the easiest way is use the Builder.
func NewDefaultWithVersion ¶ added in v0.16.0
func NewDefaultWithVersion(provider sql.DatabaseProvider) *Analyzer
NewDefaultWithVersion creates a default Analyzer instance either experimental or
func (*Analyzer) Analyze ¶
func (a *Analyzer) Analyze(ctx *sql.Context, node sql.Node, scope *plan.Scope, qFlags *sql.QueryFlags) (sql.Node, error)
Analyze applies the transformation rules to the node given. In the case of an error, the last successfully transformed node is returned along with the error.
func (*Analyzer) Log ¶
Log prints an INFO message to stdout with the given message and args if the analyzer is in debug mode.
func (*Analyzer) LogDiff ¶
LogDiff logs the diff between the query plans after a transformation rules has been applied. Only can print a diff when the string representations of the nodes differ, which isn't always the case.
func (*Analyzer) PopDebugContext ¶
func (a *Analyzer) PopDebugContext()
PopDebugContext pops a context message off the context stack.
func (*Analyzer) PushDebugContext ¶
PushDebugContext pushes the given context string onto the context stack, to use when logging debug messages.
type Batch ¶
Batch executes a set of rules a specific number of times. When this number of times is reached, the actual node and ErrMaxAnalysisIters is returned.
func (*Batch) Eval ¶
func (b *Batch) Eval(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error)
Eval executes the rules of the batch. On any error, the partially transformed node is returned along with the error. If the batch's max number of iterations is reached without achieving stabilization (batch evaluation no longer changes the node), then this method returns ErrMaxAnalysisIters.
func (*Batch) EvalWithSelector ¶ added in v0.12.0
type BatchSelector ¶ added in v0.12.0
BatchSelector filters analysis batches by name
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder provides an easy way to generate Analyzer with custom rules and options.
func NewBuilder ¶
func NewBuilder(pro sql.DatabaseProvider) *Builder
NewBuilder creates a new Builder from a specific catalog. This builder allow us add custom Rules and modify some internal properties.
func (*Builder) AddPostAnalyzeRule ¶
AddPostAnalyzeRule adds a new rule to the analyzer after standard analyzer rules.
func (*Builder) AddPostValidationRule ¶
AddPostValidationRule adds a new rule to the analyzer after standard validation rules.
func (*Builder) AddPreAnalyzeRule ¶
AddPreAnalyzeRule adds a new rule to the analyze before the standard analyzer rules.
func (*Builder) AddPreValidationRule ¶
AddPreValidationRule adds a new rule to the analyzer before standard validation rules.
func (*Builder) RemoveAfterAllRule ¶
RemoveAfterAllRule removes a default rule from the analyzer which would occur after all other rules
func (*Builder) RemoveDefaultRule ¶
RemoveDefaultRule removes a default rule from the analyzer that is executed as part of the analysis
func (*Builder) RemoveOnceAfterRule ¶
RemoveOnceAfterRule removes a default rule from the analyzer which would occur just once after the default analysis
func (*Builder) RemoveOnceBeforeRule ¶
RemoveOnceBeforeRule removes a default rule from the analyzer which would occur before other rules
func (*Builder) RemoveValidationRule ¶
RemoveValidationRule removes a default rule from the analyzer which would occur as part of the validation rules
type Catalog ¶ added in v0.11.0
type Catalog struct { MySQLDb *mysql_db.MySQLDb InfoSchema sql.Database StatsProvider sql.StatsProvider DbProvider sql.DatabaseProvider AuthHandler sql.AuthorizationHandler // BinlogReplicaController holds an optional controller that receives forwarded binlog // replication messages (e.g. "start replica"). BinlogReplicaController binlogreplication.BinlogReplicaController // BinlogPrimaryController holds an optional controller that receives forwarded binlog // replication messages (e.g. "show replicas") and commands (e.g. COM_REGISTER_REPLICA). BinlogPrimaryController binlogreplication.BinlogPrimaryController // contains filtered or unexported fields }
func NewCatalog ¶ added in v0.11.0
func NewCatalog(provider sql.DatabaseProvider) *Catalog
NewCatalog returns a new empty Catalog with the given provider
func (*Catalog) AllDatabases ¶ added in v0.11.0
func (*Catalog) AuthorizationHandler ¶ added in v0.19.0
func (c *Catalog) AuthorizationHandler() sql.AuthorizationHandler
func (*Catalog) CreateDatabase ¶ added in v0.11.0
CreateDatabase creates a new Database and adds it to the catalog.
func (*Catalog) DataLength ¶ added in v0.18.0
func (*Catalog) DatabaseTable ¶ added in v0.16.0
func (*Catalog) DatabaseTableAsOf ¶ added in v0.16.0
func (*Catalog) DropDbStats ¶ added in v0.18.0
func (*Catalog) ExternalStoredProcedure ¶ added in v0.14.0
func (c *Catalog) ExternalStoredProcedure(ctx *sql.Context, name string, numOfParams int) (*sql.ExternalStoredProcedureDetails, error)
ExternalStoredProcedure implements sql.ExternalStoredProcedureProvider
func (*Catalog) ExternalStoredProcedures ¶ added in v0.14.0
func (c *Catalog) ExternalStoredProcedures(ctx *sql.Context, name string) ([]sql.ExternalStoredProcedureDetails, error)
ExternalStoredProcedures implements sql.ExternalStoredProcedureProvider
func (*Catalog) Function ¶ added in v0.11.0
Function returns the function with the name given, or false if it doesn't exist.
func (*Catalog) GetBinlogPrimaryController ¶ added in v0.18.1
func (c *Catalog) GetBinlogPrimaryController() binlogreplication.BinlogPrimaryController
func (*Catalog) GetBinlogReplicaController ¶ added in v0.18.0
func (c *Catalog) GetBinlogReplicaController() binlogreplication.BinlogReplicaController
func (*Catalog) GetTableStats ¶ added in v0.18.0
func (*Catalog) HasBinlogPrimaryController ¶ added in v0.18.1
func (*Catalog) HasBinlogReplicaController ¶ added in v0.18.1
func (*Catalog) HasDatabase ¶ added in v0.16.0
func (*Catalog) LockTable ¶ added in v0.11.0
LockTable adds a lock for the given table and session client. It is assumed the database is the current database in use.
func (*Catalog) RefreshTableStats ¶ added in v0.18.0
func (*Catalog) RegisterFunction ¶ added in v0.11.0
RegisterFunction registers the functions given, adding them to the built-in functions. Integrators with custom functions should typically use the FunctionProvider interface instead.
func (*Catalog) RemoveDatabase ¶ added in v0.11.0
RemoveDatabase removes a database from the catalog.
func (*Catalog) Table ¶ added in v0.11.0
func (c *Catalog) Table(ctx *sql.Context, dbName, tableName string) (sql.Table, sql.Database, error)
Table returns the table in the given database with the given name.
func (*Catalog) TableAsOf ¶ added in v0.11.0
func (c *Catalog) TableAsOf(ctx *sql.Context, dbName, tableName string, asOf interface{}) (sql.Table, sql.Database, error)
TableAsOf returns the table in the given database with the given name, as it existed at the time given. The database named must support timed queries.
func (*Catalog) TableFunction ¶ added in v0.12.0
TableFunction implements the TableFunctionProvider interface
func (*Catalog) TableSchema ¶ added in v0.19.0
func (c *Catalog) TableSchema(ctx *sql.Context, dbName, schemaName, tableName string) (sql.Table, sql.Database, error)
TableSchema returns the table in the given database with the given name, in the given schema name
func (*Catalog) UnlockTables ¶ added in v0.11.0
UnlockTables unlocks all tables for which the given session client has a lock.
func (*Catalog) WithTableFunctions ¶ added in v0.18.0
func (c *Catalog) WithTableFunctions(fns ...sql.TableFunction) (sql.TableFunctionProvider, error)
type IndexScanOp ¶ added in v0.19.0
type IndexScanOp uint8
const ( IndexScanOpEq IndexScanOp = iota // = IndexScanOpNullSafeEq // <=> IndexScanOpInSet // = IndexScanOpNotInSet // != IndexScanOpNotEq // != IndexScanOpGt // > IndexScanOpGte // >= IndexScanOpLt // < IndexScanOpLte // <= IndexScanOpAnd // && IndexScanOpOr // || IndexScanOpIsNull // IS NULL IndexScanOpIsNotNull // IS NOT NULL IndexScanOpSpatialEq // SpatialEq IndexScanOpFulltextEq // FulltextEq )
func IndexLeafChildren ¶ added in v0.19.0
func IndexLeafChildren(e sql.Expression) (IndexScanOp, sql.Expression, sql.Expression, bool)
IndexLeafChildren handles the struct types that may be found on a leaf node while creating indexes.
func (IndexScanOp) String ¶ added in v0.19.0
func (i IndexScanOp) String() string
func (IndexScanOp) Swap ¶ added in v0.19.0
func (o IndexScanOp) Swap() IndexScanOp
Swap returns the identity op for swapping a comparison's LHS and RHS
type RoutineTable ¶ added in v0.12.0
type RoutineTable interface { sql.Table // AssignProcedures assigns a map of db-procedures to the routines table. AssignProcedures(p map[string][]*plan.Procedure) sql.Table }
RoutineTable is a Table that depends on a procedures and functions.
type RuleFunc ¶
type RuleFunc func(*sql.Context, *Analyzer, sql.Node, *plan.Scope, RuleSelector, *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error)
RuleFunc is the function to be applied in a rule.
type RuleId ¶ added in v0.12.0
type RuleId int
const ( ValidateColumnDefaultsId RuleId // validateColumnDefaults ValidateOperandsId // validateOperands BacktickDefaulColumnValueNamesId // backtickDefaultColumnValueNames TrackProcessId // trackProcess )
type RuleSelector ¶ added in v0.12.0
RuleSelector filters analysis rules by id
func NewFinalizeSubquerySel ¶ added in v0.15.0
func NewFinalizeSubquerySel(sel RuleSelector) RuleSelector
func NewFinalizeUnionSel ¶ added in v0.15.0
func NewFinalizeUnionSel(sel RuleSelector) RuleSelector
func NewProcRuleSelector ¶ added in v0.15.0
func NewProcRuleSelector(sel RuleSelector) RuleSelector
func NewResolveSubqueryExprSelector ¶ added in v0.14.0
func NewResolveSubqueryExprSelector(sel RuleSelector) RuleSelector
type TableAliases ¶
type TableAliases struct {
// contains filtered or unexported fields
}
Source Files ¶
- aliases.go
- analyzer.go
- apply_foreign_keys.go
- apply_hash_in.go
- apply_indexes_from_outer_scope.go
- assign_routines.go
- assign_update_join.go
- batch.go
- catalog.go
- check_constraints.go
- constraints.go
- costed_index_scan.go
- filters.go
- fix_exec_indexes.go
- hoist_filters.go
- index_analyzer.go
- indexed_joins.go
- indexscanop_string.go
- inline_subquery_aliases.go
- inserts.go
- load_triggers.go
- node_batches.go
- optimization_rules.go
- process.go
- process_truncate.go
- pushdown.go
- replace_count_star.go
- replace_cross_joins.go
- replace_order_by_distance.go
- replace_sort.go
- resolve_column_defaults.go
- resolve_columns.go
- resolve_create_select.go
- resolve_ctes.go
- resolve_database.go
- resolve_external_stored_procedures.go
- resolve_orderby.go
- resolve_subqueries.go
- resolve_tables.go
- resolve_unions.go
- rule_ids.go
- ruleid_string.go
- rules.go
- select_limit.go
- stored_procedures.go
- symbol_resolution.go
- tables.go
- topn.go
- triggers.go
- unnest_exists_subqueries.go
- unnest_insubqueries.go
- validate_create_table.go
- validation_rules.go