Documentation
¶
Index ¶
- type AccessObject
- type BuildPBContext
- type DataAccesser
- type GroupExpression
- type JoinType
- type LogicalOptRule
- type LogicalPlan
- type MPPSink
- type MemTablePredicateExtractor
- type PartitionAccesser
- type PartitionTable
- type PhysicalJoin
- type PhysicalPlan
- type Plan
- type PlanContext
- type ShowPredicateExtractor
- type Task
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessObject ¶
type AccessObject interface {
String() string
NormalizedString() string
// SetIntoPB transform itself into a protobuf message and set into the binary plan.
SetIntoPB(*tipb.ExplainOperator)
}
AccessObject represents what is accessed by an operator. It corresponds to the "access object" column in an EXPLAIN statement result.
type BuildPBContext ¶
type BuildPBContext = planctx.BuildPBContext
BuildPBContext is the context for building `*tipb.Executor`.
type DataAccesser ¶
type DataAccesser interface {
// AccessObject return plan's `table`, `partition` and `index`.
AccessObject() AccessObject
// OperatorInfo return other operator information to be explained.
OperatorInfo(normalized bool) string
}
DataAccesser is a plan that means it can access underlying data. Include `PhysicalTableScan`, `PhysicalIndexScan`, `PointGetPlan`, `BatchPointScan` and `PhysicalMemTable`. ExplainInfo = AccessObject + OperatorInfo
type GroupExpression ¶
type GroupExpression interface {
LogicalPlan
// IsExplored return whether this gE has explored rule i.
IsExplored(i uint) bool
// InputsLen returns the length of inputs.
InputsLen() int
// GetInputSchema returns the input logical's schema by index.
GetInputSchema(idx int) *expression.Schema
}
GroupExpression is the interface for group expression.
func GetGEAndLogicalOp ¶
func GetGEAndLogicalOp[T LogicalPlan](super LogicalPlan) (ge GroupExpression, logicalOp T)
GetGEAndLogicalOp is get the possible group expression and logical operator from common super pointer.
type JoinType ¶
type JoinType int
JoinType contains CrossJoin, InnerJoin, LeftOuterJoin, RightOuterJoin, SemiJoin, AntiJoin.
const ( // InnerJoin means inner join. InnerJoin JoinType = iota // LeftOuterJoin means left join. LeftOuterJoin // RightOuterJoin means right join. RightOuterJoin // SemiJoin means if row a in table A matches some rows in B, just output a. SemiJoin // AntiSemiJoin means if row a in table A does not match any row in B, then output a. AntiSemiJoin // LeftOuterSemiJoin means if row a in table A matches some rows in B, output (a, true), otherwise, output (a, false). LeftOuterSemiJoin // AntiLeftOuterSemiJoin means if row a in table A matches some rows in B, output (a, false), otherwise, output (a, true). AntiLeftOuterSemiJoin )
func (JoinType) IsInnerJoin ¶
IsInnerJoin returns if this joiner is a inner joiner
func (JoinType) IsOuterJoin ¶
IsOuterJoin returns if this joiner is an outer joiner
func (JoinType) IsSemiJoin ¶
IsSemiJoin returns if this joiner is a semi/anti-semi joiner
type LogicalOptRule ¶
type LogicalOptRule interface {
// Optimize return parameters:
// 1. base.LogicalPlan: The optimized base.LogicalPlan after rule is applied
// 2. bool: Used to judge whether the plan is changed or not by logical rule.
// If the plan is changed, it will return true.
// The default value is false. It means that no interaction rule will be triggered.
// 3. error: If there is error during the rule optimizer, it will be thrown
Optimize(context.Context, LogicalPlan) (LogicalPlan, bool, error)
Name() string
}
LogicalOptRule means a logical optimizing rule, which contains de-correlate, ppd, column pruning, etc.
type LogicalPlan ¶
type LogicalPlan interface {
Plan
base.HashEquals
// HashCode encodes a LogicalPlan to fast compare whether a LogicalPlan equals to another.
// We use a strict encode method here which ensures there is no conflict.
HashCode() []byte
// PredicatePushDown pushes down the predicates in the where/on/having clauses as deeply as possible.
// It will accept a predicate that is an expression slice, and return the expressions that can't be pushed.
// Because it might change the root if the having clause exists, we need to return a plan that represents a new root.
PredicatePushDown([]expression.Expression) ([]expression.Expression, LogicalPlan, error)
// PruneColumns prunes the unused columns, and return the new logical plan if changed, otherwise it's same.
PruneColumns([]*expression.Column) (LogicalPlan, error)
// BuildKeyInfo will collect the information of unique keys into schema.
// Because this method is also used in cascades planner, we cannot use
// things like `p.schema` or `p.children` inside it. We should use the `selfSchema`
// and `childSchema` instead.
BuildKeyInfo(selfSchema *expression.Schema, childSchema []*expression.Schema)
// PushDownTopN will push down the topN or limit operator during logical optimization.
// interface definition should depend on concrete implementation type.
PushDownTopN(topN LogicalPlan) LogicalPlan
// DeriveTopN derives an implicit TopN from a filter on row_number window function...
DeriveTopN() LogicalPlan
// PredicateSimplification consolidates different predcicates on a column and its equivalence classes.
PredicateSimplification() LogicalPlan
// ConstantPropagation generate new constant predicate according to column equivalence relation
ConstantPropagation(parentPlan LogicalPlan, currentChildIdx int) (newRoot LogicalPlan)
// PullUpConstantPredicates recursive find constant predicate, used for the constant propagation rule
PullUpConstantPredicates() []expression.Expression
// RecursiveDeriveStats derives statistic info between plans.
RecursiveDeriveStats(colGroups [][]*expression.Column) (*property.StatsInfo, bool, error)
// DeriveStats derives statistic info for current plan node given child stats.
// We need selfSchema, childSchema here because it makes this method can be used in
// cascades planner, where LogicalPlan might not record its children or schema.
DeriveStats(childStats []*property.StatsInfo, selfSchema *expression.Schema, childSchema []*expression.Schema, reloads []bool) (*property.StatsInfo, bool, error)
// ExtractColGroups extracts column groups from child operator whose DNVs are required by the current operator.
// For example, if current operator is LogicalAggregation of `Group By a, b`, we indicate the child operators to maintain
// and propagate the NDV info of column group (a, b), to improve the row count estimation of current LogicalAggregation.
// The parameter colGroups are column groups required by upper operators, besides from the column groups derived from
// current operator, we should pass down parent colGroups to child operator as many as possible.
ExtractColGroups(colGroups [][]*expression.Column) [][]*expression.Column
// PreparePossibleProperties is only used for join and aggregation. Like group by a,b,c, all permutation of (a,b,c) is
// valid, but the ordered indices in leaf plan is limited. So we can get all possible order properties by a pre-walking.
PreparePossibleProperties(schema *expression.Schema, childrenProperties ...[][]*expression.Column) [][]*expression.Column
ExtractCorrelatedCols() []*expression.CorrelatedColumn
// MaxOneRow means whether this operator only returns max one row.
MaxOneRow() bool
// Children Get all the children.
Children() []LogicalPlan
// SetChildren sets the children for the plan.
SetChildren(...LogicalPlan)
// SetChild sets the ith child for the plan.
SetChild(i int, child LogicalPlan)
// RollBackTaskMap roll back all taskMap's logs after TimeStamp TS.
RollBackTaskMap(TS uint64)
// CanPushToCop check if we might push this plan to a specific store.
// Deprecated: don't depend subtree based push check, see CanSelfBeingPushedToCopImpl based op-self push check.
CanPushToCop(store kv.StoreType) bool
// ExtractFD derive the FDSet from the tree bottom up.
ExtractFD() *fd.FDSet
// GetBaseLogicalPlan return the baseLogicalPlan inside each logical plan.
GetBaseLogicalPlan() LogicalPlan
// ConvertOuterToInnerJoin converts outer joins if the matching rows are filtered.
ConvertOuterToInnerJoin(predicates []expression.Expression) LogicalPlan
// SetPlanIDsHash set sub operator tree's ids hash64
SetPlanIDsHash(uint64)
// GetPlanIDsHash set sub operator tree's ids hash64
GetPlanIDsHash() uint64
// GetWrappedLogicalPlan return the wrapped logical plan inside a group expression.
// For logicalPlan implementation, it just returns itself as well.
GetWrappedLogicalPlan() LogicalPlan
// GetChildStatsAndSchema gets the stats and schema of the first child.
GetChildStatsAndSchema() (*property.StatsInfo, *expression.Schema)
// GetJoinChildStatsAndSchema gets the stats and schema of both children.
GetJoinChildStatsAndSchema() (stats0, stats1 *property.StatsInfo, schema0, schema1 *expression.Schema)
}
LogicalPlan is a tree of logical operators. We can do a lot of logical optimizations to it, like predicate push-down and column pruning.
type MPPSink ¶
type MPPSink interface {
PhysicalPlan
GetCompressionMode() vardef.ExchangeCompressionMode
GetSelfTasks() []*kv.MPPTask
SetSelfTasks(tasks []*kv.MPPTask)
SetTargetTasks(tasks []*kv.MPPTask)
AppendTargetTasks(tasks []*kv.MPPTask)
}
MPPSink is the operator to send data to its parent fragment. e.g. ExchangeSender, etc.
type MemTablePredicateExtractor ¶
type MemTablePredicateExtractor interface {
// Extract extracts predicates which can be pushed down and returns the remained predicates
Extract(PlanContext, *expression.Schema, []*types.FieldName, []expression.Expression) (remained []expression.Expression)
// ExplainInfo give the basic desc of this mem extractor, `p` indicates a PhysicalPlan here.
ExplainInfo(p PhysicalPlan) string
}
MemTablePredicateExtractor is used to extract some predicates from `WHERE` clause and push the predicates down to the data retrieving on reading memory table stage.
e.g: SELECT * FROM cluster_config WHERE type='tikv' AND instance='192.168.1.9:2379' We must request all components in the cluster via HTTP API for retrieving configurations and filter them by `type/instance` columns.
The purpose of defining a `MemTablePredicateExtractor` is to optimize this 1. Define a `ClusterConfigTablePredicateExtractor` 2. Extract the `type/instance` columns on the logic optimizing stage and save them via fields. 3. Passing the extractor to the `ClusterReaderExecExec` executor 4. Executor sends requests to the target components instead of all of the components
type PartitionAccesser ¶
type PartitionAccesser interface {
AccessObject(PlanContext) AccessObject
}
PartitionAccesser is a plan that can access partitioned data.
type PartitionTable ¶
type PartitionTable interface {
PartitionExpr() *tables.PartitionExpr
}
PartitionTable is for those tables which implement partition.
type PhysicalJoin ¶
type PhysicalJoin interface {
PhysicalPlan
PhysicalJoinImplement()
GetInnerChildIdx() int
GetJoinType() JoinType
}
PhysicalJoin provides some common methods for join operators. Note that PhysicalApply is deliberately excluded from this interface.
type PhysicalPlan ¶
type PhysicalPlan interface {
Plan
// GetPlanCostVer1 calculates the cost of the plan if it has not been calculated yet and returns the cost on model ver1.
GetPlanCostVer1(taskType property.TaskType, option *costusage.PlanCostOption) (float64, error)
// GetPlanCostVer2 calculates the cost of the plan if it has not been calculated yet and returns the cost on model ver2.
GetPlanCostVer2(taskType property.TaskType, option *costusage.PlanCostOption, isChildOfINL ...bool) (costusage.CostVer2, error)
// Attach2Task makes the current physical plan as the father of task's physicalPlan and updates the cost of
// current task. If the child's task is cop task, some operator may close this task and return a new rootTask.
Attach2Task(...Task) Task
// ToPB converts physical plan to tipb executor.
ToPB(ctx *BuildPBContext, storeType kv.StoreType) (*tipb.Executor, error)
// GetChildReqProps gets the required property by child index.
GetChildReqProps(idx int) *property.PhysicalProperty
// StatsCount returns the count of property.StatsInfo for this plan.
StatsCount() float64
ExtractCorrelatedCols() []*expression.CorrelatedColumn
// Children get all the children.
Children() []PhysicalPlan
// SetChildren sets the children for the plan.
SetChildren(...PhysicalPlan)
// SetChild sets the ith child for the plan.
SetChild(i int, child PhysicalPlan)
// ResolveIndices resolves the indices for columns. After doing this, the columns can evaluate the rows by their indices.
ResolveIndices() error
// StatsInfo returns the StatsInfo of the plan.
StatsInfo() *property.StatsInfo
// SetStats sets basePlan.stats inside the basePhysicalPlan.
SetStats(s *property.StatsInfo)
// ExplainNormalizedInfo returns operator normalized information for generating digest.
ExplainNormalizedInfo() string
// Clone clones this physical plan.
Clone(newCtx PlanContext) (PhysicalPlan, error)
// MemoryUsage return the memory usage of PhysicalPlan
MemoryUsage() int64
// SetProbeParents sets the above stated `probeParents` field.
SetProbeParents([]PhysicalPlan)
// GetEstRowCountForDisplay uses the "single probe" row count in StatsInfo and the probeParents to calculate
// the "all probe" row count.
// All places that display the row count for a PhysicalPlan are expected to use this method.
GetEstRowCountForDisplay() float64
// GetActualProbeCnt uses the runtime stats and the probeParents to calculate the actual "probe" count.
GetActualProbeCnt(*execdetails.RuntimeStatsColl) int64
}
PhysicalPlan is a tree of the physical operators.
type Plan ¶
type Plan interface {
// Get the schema.
Schema() *expression.Schema
// Get the ID.
ID() int
// SetID sets the ID
SetID(id int)
// TP get the plan type.
TP(...bool) string
// Get the ID in explain statement
ExplainID(isChildOfINL ...bool) fmt.Stringer
// ExplainInfo returns operator information to be explained.
ExplainInfo() string
// ReplaceExprColumns replace all the column reference in the plan's expression node.
ReplaceExprColumns(replace map[string]*expression.Column)
SCtx() PlanContext
// StatsInfo will return the property.StatsInfo for this plan.
StatsInfo() *property.StatsInfo
// OutputNames returns the outputting names of each column.
OutputNames() types.NameSlice
// SetOutputNames sets the outputting name by the given slice.
SetOutputNames(names types.NameSlice)
// QueryBlockOffset is query block offset.
// For example, in query
// `select /*+ use_index(@sel_2 t2, a) */ * from t1, (select a*2 as b from t2) tx where a>b`
// the hint should be applied on the sub-query, whose query block is 2.
QueryBlockOffset() int
// CloneForPlanCache clones this Plan for Plan Cache.
// Compared with Clone, CloneForPlanCache doesn't deep clone every fields, fields with tag
// `plan-cache-shallow-clone:"true"` are allowed to be shallow cloned.
CloneForPlanCache(newCtx PlanContext) (cloned Plan, ok bool)
}
Plan is the description of an execution flow. It is created from ast.Node first, then optimized by the optimizer, finally used by the executor to create a Cursor which executes the statement.
type PlanContext ¶
type PlanContext = planctx.PlanContext
PlanContext is the context for building plan.
type ShowPredicateExtractor ¶
type ShowPredicateExtractor interface {
// Extract predicates which can be pushed down and returns whether the extractor can extract predicates.
Extract() bool
ExplainInfo() string
Field() string
FieldPatternLike() collate.WildcardPattern
}
ShowPredicateExtractor is used to extract some predicates from `PatternLikeOrIlikeExpr` clause and push the predicates down to the data retrieving on reading memory table stage when use ShowStmt.
e.g: SHOW COLUMNS FROM t LIKE '%abc%' We must request all components from the memory table, and filter the result by the PatternLikeOrIlikeExpr predicate.
it is a way to fix https://github.com/pingcap/tidb/issues/29910.
type Task ¶
type Task interface {
// Count returns current task's row count.
Count() float64
// Copy return a shallow copy of current task with the same pointer to p.
Copy() Task
// Plan returns current task's plan.
Plan() PhysicalPlan
// Invalid returns whether current task is invalid.
Invalid() bool
// ConvertToRootTask will convert current task as root type.
// Here we change return type as interface to avoid import cycle.
// Basic interface definition shouldn't depend on concrete implementation structure.
ConvertToRootTask(ctx PlanContext) Task
// MemoryUsage returns the memory usage of current task.
MemoryUsage() int64
// AppendWarning appends a warning
AppendWarning(err error)
}
Task is a new version of `PhysicalPlanInfo`. It stores cost information for a task. A task may be CopTask, RootTask, MPPTaskMeta or a ParallelTask.
var InvalidTask Task
InvalidTask is just a common invalid singleton instance initialized by core's empty RootTask.