util

package
v1.1.0-beta.0...-a878e1f Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EvalAstExprWithPlanCtx func(ctx context.PlanContext, expr ast.ExprNode) (types.Datum, error)

EvalAstExprWithPlanCtx evaluates ast expression with plan context. Different with expression.EvalSimpleAst, it uses planner context and is more powerful to build some special expressions like subquery, window function, etc. If you only want to evaluate simple expressions, use `expression.EvalSimpleAst` instead.

View Source
var RewriteAstExprWithPlanCtx func(ctx context.PlanContext, expr ast.ExprNode,
	schema *expression.Schema, names types.NameSlice, allowCastArray bool) (expression.Expression, error)

RewriteAstExprWithPlanCtx rewrites ast expression directly. Different with expression.BuildSimpleExpr, it uses planner context and is more powerful to build some special expressions like subquery, window function, etc. If you only want to build simple expressions, use `expression.BuildSimpleExpr` instead.

Functions

func CloneColInfos

func CloneColInfos(cols []*model.ColumnInfo) []*model.ColumnInfo

CloneColInfos uses (*ColumnInfo).Clone to clone a slice of *ColumnInfo.

func CloneCols

func CloneCols(cols []*expression.Column) []*expression.Column

CloneCols uses (*Column).Clone to clone a slice of *Column.

func CloneExprs

func CloneExprs(exprs []expression.Expression) []expression.Expression

CloneExprs uses Expression.Clone to clone a slice of Expression.

func CloneRanges

func CloneRanges(ranges []*ranger.Range) []*ranger.Range

CloneRanges uses (*Range).Clone to clone a slice of *Range.

func CompareCol2Len

func CompareCol2Len(c1, c2 Col2Len) (int, bool)

CompareCol2Len will compare the two Col2Len maps. The last return value is used to indicate whether they are comparable. When the second return value is true, the first return value: (1) -1 means that c1 is worse than c2; (2) 0 means that c1 equals to c2; (3) 1 means that c1 is better than c2;

func StringifyByItemsWithCtx

func StringifyByItemsWithCtx(byItems []*ByItems) string

StringifyByItemsWithCtx is used to print ByItems slice.

Types

type AccessPath

type AccessPath struct {
	Index          *model.IndexInfo
	FullIdxCols    []*expression.Column
	FullIdxColLens []int
	IdxCols        []*expression.Column
	IdxColLens     []int
	// ConstCols indicates whether the column is constant under the given conditions for all index columns.
	ConstCols []bool
	Ranges    []*ranger.Range
	// CountAfterAccess is the row count after we apply range seek and before we use other filter to filter data.
	// For index merge path, CountAfterAccess is the row count after partial paths and before we apply table filters.
	CountAfterAccess float64
	// CountAfterIndex is the row count after we apply filters on index and before we apply the table filters.
	CountAfterIndex float64
	AccessConds     []expression.Expression
	EqCondCount     int
	EqOrInCondCount int
	IndexFilters    []expression.Expression
	TableFilters    []expression.Expression
	// PartialIndexPaths store all index access paths.
	// If there are extra filters, store them in TableFilters.
	PartialIndexPaths []*AccessPath

	// ************************************************** special field below *********************************************************
	// For every dnf/cnf item, there maybe several matched partial index paths to be determined later in property detecting and cost model.
	// when PartialAlternativeIndexPaths is not empty, it means a special state for index merge path, and it can't have PartialIndexPaths
	// at same time. Normal single index or table path also doesn't use this field.
	PartialAlternativeIndexPaths [][]*AccessPath
	// KeepIndexMergeORSourceFilter and IndexMergeORSourceFilter are only used with PartialAlternativeIndexPaths, which means for
	// the new state/type of access path. (undetermined index merge path)
	KeepIndexMergeORSourceFilter bool
	// IndexMergeORSourceFilter indicates that there are some expression inside this dnf that couldn't be pushed down, and we should keep the entire dnf above.
	IndexMergeORSourceFilter expression.Expression

	// IndexMergeIsIntersection means whether it's intersection type or union type IndexMerge path.
	// It's only valid for a IndexMerge path.
	// Intersection type is for expressions connected by `AND` and union type is for `OR`.
	IndexMergeIsIntersection bool
	// IndexMergeAccessMVIndex indicates whether this IndexMerge path accesses a MVIndex.
	IndexMergeAccessMVIndex bool

	StoreType kv.StoreType

	IsDNFCond bool

	// IsIntHandlePath indicates whether this path is table path.
	IsIntHandlePath    bool
	IsCommonHandlePath bool
	// Forced means this path is generated by `use/force index()`.
	Forced           bool
	ForceKeepOrder   bool
	ForceNoKeepOrder bool
	// IsSingleScan indicates whether the path is a single index/table scan or table access after index scan.
	IsSingleScan bool

	// Maybe added in model.IndexInfo better, but the cache of model.IndexInfo may lead side effect
	IsUkShardIndexPath bool
}

AccessPath indicates the way we access a table: by using single index, or by using multiple indexes, or just by using table scan.

func (*AccessPath) Clone

func (path *AccessPath) Clone() *AccessPath

Clone returns a deep copy of the original AccessPath. Note that we rely on the Expression.Clone(), (*IndexInfo).Clone() and (*Range).Clone() in this method, so there are some fields like FieldType are not deep-copied.

func (*AccessPath) GetCol2LenFromAccessConds

func (path *AccessPath) GetCol2LenFromAccessConds(ctx context.PlanContext) Col2Len

GetCol2LenFromAccessConds returns columns with lengths from path.AccessConds.

func (*AccessPath) IsTablePath

func (path *AccessPath) IsTablePath() bool

IsTablePath returns true if it's IntHandlePath or CommonHandlePath.

func (*AccessPath) OnlyPointRange

func (path *AccessPath) OnlyPointRange(tc types.Context) bool

OnlyPointRange checks whether each range is a point(no interval range exists).

func (*AccessPath) SplitCorColAccessCondFromFilters

func (path *AccessPath) SplitCorColAccessCondFromFilters(ctx context.PlanContext, eqOrInCount int) (access, remained []expression.Expression)

SplitCorColAccessCondFromFilters move the necessary filter in the form of index_col = corrlated_col to access conditions. The function consider the `idx_col_1 = const and index_col_2 = cor_col and index_col_3 = const` case. It enables more index columns to be considered. The range will be rebuilt in 'ResolveCorrelatedColumns'.

type ByItems

type ByItems struct {
	Expr expression.Expression
	Desc bool
}

ByItems wraps a "by" item.

func (*ByItems) Clone

func (by *ByItems) Clone() *ByItems

Clone makes a copy of ByItems.

func (*ByItems) Equal

func (by *ByItems) Equal(ctx expression.EvalContext, other *ByItems) bool

Equal checks whether two ByItems are equal.

func (*ByItems) MemoryUsage

func (by *ByItems) MemoryUsage() (sum int64)

MemoryUsage return the memory usage of ByItems.

func (*ByItems) String

func (by *ByItems) String() string

String implements fmt.Stringer interface.

func (*ByItems) StringWithCtx

func (by *ByItems) StringWithCtx(redact string) string

StringWithCtx implements expression.StringerWithCtx interface.

type Col2Len

type Col2Len map[int64]int

Col2Len maps expression.Column.UniqueID to column length

func ExtractCol2Len

func ExtractCol2Len(ctx expression.EvalContext, exprs []expression.Expression, idxCols []*expression.Column, idxColLens []int) Col2Len

ExtractCol2Len collects index/table columns with lengths from expressions. If idxCols and idxColLens are not nil, it collects index columns with lengths(maybe prefix lengths). Otherwise it collects table columns with full lengths.

type LogicalOptimizeOp

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

LogicalOptimizeOp is logical optimizing option for tracing.

func DefaultLogicalOptimizeOption

func DefaultLogicalOptimizeOption() *LogicalOptimizeOp

DefaultLogicalOptimizeOption returns the default LogicalOptimizeOp.

func (*LogicalOptimizeOp) AppendBeforeRuleOptimize

func (op *LogicalOptimizeOp) AppendBeforeRuleOptimize(index int, name string, build func() *tracing.PlanTrace)

AppendBeforeRuleOptimize just appends a before-rule plan tracer.

func (*LogicalOptimizeOp) AppendStepToCurrent

func (op *LogicalOptimizeOp) AppendStepToCurrent(id int, tp string, reason, action func() string)

AppendStepToCurrent appends a step of current action.

func (*LogicalOptimizeOp) RecordFinalLogicalPlan

func (op *LogicalOptimizeOp) RecordFinalLogicalPlan(build func() *tracing.PlanTrace)

RecordFinalLogicalPlan records the final logical plan.

func (*LogicalOptimizeOp) TracerIsNil

func (op *LogicalOptimizeOp) TracerIsNil() bool

TracerIsNil returns whether inside tracer is nil

func (*LogicalOptimizeOp) WithEnableOptimizeTracer

func (op *LogicalOptimizeOp) WithEnableOptimizeTracer(tracer *tracing.LogicalOptimizeTracer) *LogicalOptimizeOp

WithEnableOptimizeTracer attach the customized tracer to current LogicalOptimizeOp.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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