Documentation
¶
Index ¶
- Constants
- Variables
- func ExplainColumnList(ctx expression.EvalContext, cols []*MPPPartitionColumn) []byte
- func ExplainPartitionBy(ctx expression.EvalContext, buffer *bytes.Buffer, partitionBy []SortItem, ...) *bytes.Buffer
- func GetCollateIDByNameForPartition(coll string) int32
- func GetCollateNameByIDForPartition(collateID int32) string
- func NeedEnforceExchanger(mtp MPPPartitionType, mHashCols []*MPPPartitionColumn, prop *PhysicalProperty, ...) bool
- func ToString(ndvs []GroupNDV) string
- type GroupNDV
- type IndexJoinRuntimeProp
- type LogicalProperty
- type MPPPartitionColumn
- func (partitionCol *MPPPartitionColumn) Clone() *MPPPartitionColumn
- func (partitionCol *MPPPartitionColumn) Equal(other *MPPPartitionColumn) bool
- func (partitionCol *MPPPartitionColumn) MemoryUsage() (sum int64)
- func (partitionCol *MPPPartitionColumn) ResolveIndices(schema *expression.Schema) (*MPPPartitionColumn, error)
- type MPPPartitionType
- type PartialOrderInfo
- type PartialOrderMatchResult
- type PhysicalPropMatchResult
- type PhysicalProperty
- func (p *PhysicalProperty) AllColsFromSchema(schema *expression.Schema) bool
- func (p *PhysicalProperty) AllSameOrder() (isSame bool, desc bool)
- func (p *PhysicalProperty) CloneEssentialFields() *PhysicalProperty
- func (p *PhysicalProperty) GetAllPossibleChildTaskTypes() []TaskType
- func (p *PhysicalProperty) GetSortDescForKeepOrder() bool
- func (p *PhysicalProperty) GetSortItemsForKeepOrder() []SortItem
- func (p *PhysicalProperty) HashCode() []byte
- func (p *PhysicalProperty) IsFlashProp() bool
- func (p *PhysicalProperty) IsPrefix(prop *PhysicalProperty) bool
- func (p *PhysicalProperty) IsSortItemAllForPartition() bool
- func (p *PhysicalProperty) IsSortItemEmpty() bool
- func (p *PhysicalProperty) IsSubsetOf(keys []*MPPPartitionColumn) []int
- func (p *PhysicalProperty) MemoryUsage() (sum int64)
- func (p *PhysicalProperty) NeedKeepOrder() bool
- func (p *PhysicalProperty) NeedMPPExchangeByEquivalence(currentPartitionColumn []*MPPPartitionColumn, fd *funcdep.FDSet) bool
- func (p *PhysicalProperty) String() string
- type SortItem
- type StatsInfo
- func (s *StatsInfo) Count() int64
- func (s *StatsInfo) GetGroupNDV4Cols(cols []*expression.Column) *GroupNDV
- func (s *StatsInfo) Scale(vars *variable.SessionVars, factor float64) *StatsInfo
- func (s *StatsInfo) ScaleByExpectCnt(vars *variable.SessionVars, expectCnt float64) *StatsInfo
- func (s *StatsInfo) String() string
- type TaskType
Constants ¶
const ( NoCTEOrAllProducerCanMPP cteProducerStatus = iota SomeCTEFailedMpp AllCTECanMpp )
Constants for CTE status.
Variables ¶
var ScaleNDVFunc func(vars *variable.SessionVars, originalNDV, originalRows, selectedRows float64) (newNDV float64)
ScaleNDVFunc is used to avoid cycle import. `sctx` should be base.PlanContext, use any to avoid cycle import.
Functions ¶
func ExplainColumnList ¶
func ExplainColumnList(ctx expression.EvalContext, cols []*MPPPartitionColumn) []byte
ExplainColumnList generates explain information for a list of columns.
func ExplainPartitionBy ¶
func ExplainPartitionBy(ctx expression.EvalContext, buffer *bytes.Buffer, partitionBy []SortItem, normalized bool) *bytes.Buffer
ExplainPartitionBy produce text for p.PartitionBy. Common for window functions and TopN.
func GetCollateIDByNameForPartition ¶
GetCollateIDByNameForPartition returns collate id by collation name
func GetCollateNameByIDForPartition ¶
GetCollateNameByIDForPartition returns collate id by collation name
func NeedEnforceExchanger ¶
func NeedEnforceExchanger(mtp MPPPartitionType, mHashCols []*MPPPartitionColumn, prop *PhysicalProperty, fd *funcdep.FDSet) bool
NeedEnforceExchanger checks if we need to enforce an exchange operator on the top of the mpp task.
Types ¶
type IndexJoinRuntimeProp ¶
type IndexJoinRuntimeProp struct {
// for complete the last col range access, cuz its runtime constant.
OtherConditions []expression.Expression
// for filling the range msg info
OuterJoinKeys []*expression.Column
// for inner ds/index to detect the range, cuz its runtime constant.
InnerJoinKeys []*expression.Column
// AvgInnerRowCnt is computed from join.EqualCondCount / outerChild.RowCount.
// since ds only can build empty range before seeing runtime data, the so inner
// ds can get an accurate countAfterAccess. Once index join prop pushed to the
// deeper side like through join, the deeper DS's countAfterAccess should be
// thought twice.
AvgInnerRowCnt float64
// since tableRangeScan and indexRangeScan can't be told which one is better at
// copTask phase because of the latter attached operators into cop and the single
// and double reader cost consideration. Therefore, we introduce another bool to
// indicate prefer tableRangeScan or indexRangeScan each at a time.
TableRangeScan bool
}
IndexJoinRuntimeProp is the inner runtime property for index join.
func (*IndexJoinRuntimeProp) CloneEssentialFields ¶
func (ijr *IndexJoinRuntimeProp) CloneEssentialFields() *IndexJoinRuntimeProp
CloneEssentialFields clone the essential fields for IndexJoinRuntimeProp.
type LogicalProperty ¶
type LogicalProperty struct {
Stats *StatsInfo
Schema *expression.Schema
FD *fd.FDSet
MaxOneRow bool
PossibleProps [][]*expression.Column
HasTiFlash bool
}
LogicalProperty stands for logical properties such as schema of expression, or statistics of columns in schema for output of Group. All group expressions in a group share same logical property.
func NewLogicalProp ¶
func NewLogicalProp() *LogicalProperty
NewLogicalProp returns a new empty LogicalProperty.
type MPPPartitionColumn ¶
type MPPPartitionColumn struct {
Col *expression.Column
CollateID int32
}
MPPPartitionColumn is the column that will be used in MPP Hash Exchange
func ChoosePartitionKeys ¶
func ChoosePartitionKeys(keys []*MPPPartitionColumn, matches []int) []*MPPPartitionColumn
ChoosePartitionKeys chooses partition keys according to the matches.
func (*MPPPartitionColumn) Clone ¶
func (partitionCol *MPPPartitionColumn) Clone() *MPPPartitionColumn
Clone makes a copy of MPPPartitionColumn.
func (*MPPPartitionColumn) Equal ¶
func (partitionCol *MPPPartitionColumn) Equal(other *MPPPartitionColumn) bool
Equal returns true if partitionCol == other
func (*MPPPartitionColumn) MemoryUsage ¶
func (partitionCol *MPPPartitionColumn) MemoryUsage() (sum int64)
MemoryUsage return the memory usage of MPPPartitionColumn
func (*MPPPartitionColumn) ResolveIndices ¶
func (partitionCol *MPPPartitionColumn) ResolveIndices(schema *expression.Schema) (*MPPPartitionColumn, error)
ResolveIndices resolve index for MPPPartitionColumn
type MPPPartitionType ¶
type MPPPartitionType int
MPPPartitionType is the way to partition during mpp data exchanging.
const ( // AnyType will not require any special partition types. AnyType MPPPartitionType = iota // BroadcastType requires current task to broadcast its data. BroadcastType // HashType requires current task to shuffle its data according to some columns. HashType // SinglePartitionType requires all the task pass the data to one node (tidb/tiflash). SinglePartitionType )
func (MPPPartitionType) ToExchangeType ¶
func (t MPPPartitionType) ToExchangeType() tipb.ExchangeType
ToExchangeType generates ExchangeType from MPPPartitionType
type PartialOrderInfo ¶
type PartialOrderInfo struct {
// SortItems are the ORDER BY columns from TopN
SortItems []*SortItem
}
PartialOrderInfo records information needed for partial order optimization. When PhysicalProperty.PartialOrderInfo is not nil, it indicates that prefix index can be used to provide partial order.
func (*PartialOrderInfo) AllSameOrder ¶
func (p *PartialOrderInfo) AllSameOrder() (isSame bool, desc bool)
AllSameOrder checks if all the items have same order.
type PartialOrderMatchResult ¶
type PartialOrderMatchResult struct {
// Matched indicates whether this path can provide partial order
Matched bool
// PrefixCol is the last and only one prefix column ID of index, only used for executor part
// For example:
// Query ORDER BY a,b,c
// Index: a, b, c(10)
// PrefixCol: c, the col c
// PrefixLen: 10, the col length of c in index
PrefixCol *expression.Column
// PrefixLen is the prefix length in bytes for prefix index, only used for executor part
PrefixLen int
}
PartialOrderMatchResult records the result of matching partial order property with an access path. It is stored in candidatePath to allow each path to have its own match result.
type PhysicalPropMatchResult ¶
type PhysicalPropMatchResult int
PhysicalPropMatchResult describes the result of matching PhysicalProperty against an access path.
const ( // PropNotMatched means the access path cannot satisfy the required order. PropNotMatched PhysicalPropMatchResult = iota // PropMatched means the access path can satisfy the required property directly. PropMatched // PropMatchedNeedMergeSort means the access path can satisfy the required property, but a merge sort between range // groups is needed. // Corresponding information will be recorded in AccessPath.GroupedRanges and AccessPath.GroupByColIdxs. PropMatchedNeedMergeSort )
func (PhysicalPropMatchResult) Matched ¶
func (r PhysicalPropMatchResult) Matched() bool
Matched returns true if the required order can be satisfied.
type PhysicalProperty ¶
type PhysicalProperty struct {
// SortItems contains the required sort attributes.
SortItems []SortItem
// TaskTp means the type of task that an operator requires.
//
// It needs to be specified because two different tasks can't be compared
// with cost directly. e.g. If a copTask takes less cost than a rootTask,
// we can't sure that we must choose the former one. Because the copTask
// must be finished and increase its cost in sometime, but we can't make
// sure the finishing time. So the best way to let the comparison fair is
// to add TaskType to required property.
TaskTp TaskType
// ExpectedCnt means this operator may be closed after fetching ExpectedCnt
// records.
ExpectedCnt float64
// indicates that whether we are allowed to add an enforcer.
CanAddEnforcer bool
// If the partition type is hash, the data should be reshuffled by partition cols.
MPPPartitionCols []*MPPPartitionColumn
// which types the exchange sender belongs to, only take effects when it's a mpp task.
MPPPartitionTp MPPPartitionType
// SortItemsForPartition means these sort only need to sort the data of one partition, instead of global.
// It is added only if it is used to sort the sharded data of the window function.
// Non-MPP tasks do not care about it.
SortItemsForPartition []SortItem
CTEProducerStatus cteProducerStatus
VectorProp struct {
*expression.VSInfo
TopK uint32
}
IndexJoinProp *IndexJoinRuntimeProp
// NoCopPushDown indicates if planner must not push this agg down to coprocessor.
// It is true when the agg is in the outer child tree of apply.
NoCopPushDown bool
// PartialOrderInfo is used for TopN's partial order optimization.
// When this field is not nil, it indicates that prefix index can be used
// to provide partial order for TopN.
// For example:
// query: order by a, b limit 10
// partialOrderInfo: sortItems: [a, b]
// The partialOrderInfo property will pass through to the datasource and try to matchPartialOrderProperty such as:
// index: (a, b(10) )
PartialOrderInfo *PartialOrderInfo
// contains filtered or unexported fields
}
PhysicalProperty stands for the required physical property by parents. It contains the orders and the task types.
func NewPhysicalProperty ¶
func NewPhysicalProperty(taskTp TaskType, cols []*expression.Column, desc bool, expectCnt float64, enforced bool) *PhysicalProperty
NewPhysicalProperty builds property from columns.
func (*PhysicalProperty) AllColsFromSchema ¶
func (p *PhysicalProperty) AllColsFromSchema(schema *expression.Schema) bool
AllColsFromSchema checks whether all the columns needed by this physical property can be found in the given schema.
func (*PhysicalProperty) AllSameOrder ¶
func (p *PhysicalProperty) AllSameOrder() (isSame bool, desc bool)
AllSameOrder checks if all the items have same order.
func (*PhysicalProperty) CloneEssentialFields ¶
func (p *PhysicalProperty) CloneEssentialFields() *PhysicalProperty
CloneEssentialFields returns a copy of PhysicalProperty. We only copy the essential fields that really indicate the property, specifically, `CanAddEnforcer` should not be included.
func (*PhysicalProperty) GetAllPossibleChildTaskTypes ¶
func (p *PhysicalProperty) GetAllPossibleChildTaskTypes() []TaskType
GetAllPossibleChildTaskTypes enumrates the possible types of tasks for children.
func (*PhysicalProperty) GetSortDescForKeepOrder ¶
func (p *PhysicalProperty) GetSortDescForKeepOrder() bool
GetSortDescForKeepOrder returns the sort direction (descending or not). It prioritizes PartialOrderInfo over SortItems. This method reuses the existing AllSameOrder methods.
func (*PhysicalProperty) GetSortItemsForKeepOrder ¶
func (p *PhysicalProperty) GetSortItemsForKeepOrder() []SortItem
GetSortItemsForKeepOrder returns the sort items used for KeepOrder. It prioritizes PartialOrderInfo over SortItems. Returns a copy of SortItems (converting from []*SortItem to []SortItem if from PartialOrderInfo).
func (*PhysicalProperty) HashCode ¶
func (p *PhysicalProperty) HashCode() []byte
HashCode calculates hash code for a PhysicalProperty object.
func (*PhysicalProperty) IsFlashProp ¶
func (p *PhysicalProperty) IsFlashProp() bool
IsFlashProp return true if this physical property is only allowed to generate flash related task
func (*PhysicalProperty) IsPrefix ¶
func (p *PhysicalProperty) IsPrefix(prop *PhysicalProperty) bool
IsPrefix checks whether the order property is the prefix of another.
func (*PhysicalProperty) IsSortItemAllForPartition ¶
func (p *PhysicalProperty) IsSortItemAllForPartition() bool
IsSortItemAllForPartition check whether SortItems is same as SortItemsForPartition
func (*PhysicalProperty) IsSortItemEmpty ¶
func (p *PhysicalProperty) IsSortItemEmpty() bool
IsSortItemEmpty checks whether the order property is empty.
func (*PhysicalProperty) IsSubsetOf ¶
func (p *PhysicalProperty) IsSubsetOf(keys []*MPPPartitionColumn) []int
IsSubsetOf check if the keys can match the needs of partition.
func (*PhysicalProperty) MemoryUsage ¶
func (p *PhysicalProperty) MemoryUsage() (sum int64)
MemoryUsage return the memory usage of PhysicalProperty
func (*PhysicalProperty) NeedKeepOrder ¶
func (p *PhysicalProperty) NeedKeepOrder() bool
NeedKeepOrder returns whether the property requires maintaining order. It handles both normal sorting (SortItems) and partial order (PartialOrderInfo).
func (*PhysicalProperty) NeedMPPExchangeByEquivalence ¶
func (p *PhysicalProperty) NeedMPPExchangeByEquivalence( currentPartitionColumn []*MPPPartitionColumn, fd *funcdep.FDSet) bool
NeedMPPExchangeByEquivalence checks if the keys can match the needs of partition with equivalence. "Equivalence" refers to the process where we utilize a hash column to obtain equivalent columns, and then use these equivalent columns to compare with the MPP partition column to determine whether an exchange is necessary.
for example:
- requiredPartitionColumn: [18,13,16]
- currentPartitionColumn: 9
- FD: (1)-->(2-6,8), ()-->(7), (9)-->(10-17), (1,10)==(1,10), (18,21)-->(19,20,22-33), (9,18)==(9,18) In this case, we can see that the child supplied partition keys is subset of parent required partition cols.
func (*PhysicalProperty) String ¶
func (p *PhysicalProperty) String() string
String implements fmt.Stringer interface. Just for test.
type SortItem ¶
type SortItem struct {
Col *expression.Column
Desc bool
}
SortItem wraps the column and its order.
func SortItemsFromCols ¶
func SortItemsFromCols(cols []*expression.Column, desc bool) []SortItem
SortItemsFromCols builds property items from columns.
func (SortItem) MemoryUsage ¶
MemoryUsage return the memory usage of SortItem
type StatsInfo ¶
type StatsInfo struct {
RowCount float64
// Column.UniqueID -> NDV
ColNDVs map[int64]float64
HistColl *statistics.HistColl
// StatsVersion indicates the statistics version of a table.
// If the StatsInfo is calculated using the pseudo statistics on a table, StatsVersion will be PseudoVersion.
StatsVersion uint64
// GroupNDVs stores the NDV of column groups.
GroupNDVs []GroupNDV
}
StatsInfo stores the basic information of statistics for the plan's output. It is used for cost estimation.
func DeriveLimitStats ¶
DeriveLimitStats derives the stats of the top-n plan.
func (*StatsInfo) GetGroupNDV4Cols ¶
func (s *StatsInfo) GetGroupNDV4Cols(cols []*expression.Column) *GroupNDV
GetGroupNDV4Cols gets the GroupNDV for the given columns.
func (*StatsInfo) Scale ¶
func (s *StatsInfo) Scale(vars *variable.SessionVars, factor float64) *StatsInfo
Scale receives a selectivity and multiplies it with RowCount and NDV.
func (*StatsInfo) ScaleByExpectCnt ¶
func (s *StatsInfo) ScaleByExpectCnt(vars *variable.SessionVars, expectCnt float64) *StatsInfo
ScaleByExpectCnt tries to Scale StatsInfo to an expectCnt which must be smaller than the derived cnt. TODO: try to use a better way to do this.
type TaskType ¶
type TaskType int
TaskType is the type of execution task.
const ( // RootTaskType stands for the tasks that executed in the TiDB layer. RootTaskType TaskType = iota // CopSingleReadTaskType stands for the a TableScan or IndexScan tasks // executed in the coprocessor layer. CopSingleReadTaskType // CopMultiReadTaskType stands for the a IndexLookup tasks executed in the // coprocessor layer. CopMultiReadTaskType // MppTaskType stands for task that would run on Mpp nodes, currently meaning the tiflash node. MppTaskType )