util

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

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

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

Documentation

Index

Constants

View Source
const MetricTableTimeFormat = "2006-01-02 15:04:05.999"

MetricTableTimeFormat is the time format for metric table explain and format.

Variables

View Source
var EvalAstExprWithPlanCtx func(ctx planctx.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 planctx.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 CloneAssignments

func CloneAssignments(assignments []*expression.Assignment) []*expression.Assignment

CloneAssignments uses (*Assignment).Clone to clone a slice of *Assignment.

func CloneCIStrs

func CloneCIStrs(strs []pmodel.CIStr) []pmodel.CIStr

CloneCIStrs uses ast.CIStr.Clone to clone a slice of ast.CIStr.

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 CloneConstants

func CloneConstants(constants []*expression.Constant) []*expression.Constant

CloneConstants uses (*Constant).Clone to clone a slice of *Constant.

func CloneDatum2D

func CloneDatum2D(datums [][]types.Datum) [][]types.Datum

CloneDatum2D uses CloneDatums to clone a 2D slice of Datum.

func CloneDatums

func CloneDatums(datums []types.Datum) []types.Datum

CloneDatums uses Datum.Clone to clone a slice of Datum.

func CloneExpressions

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

CloneExpressions uses CloneExprs to clone a slice of expression.Expression.

func CloneExprs

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

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

func CloneFieldNames

func CloneFieldNames(names []*types.FieldName) []*types.FieldName

CloneFieldNames uses types.FieldName.Clone to clone a slice of types.FieldName.

func CloneHandles

func CloneHandles(handles []kv.Handle) []kv.Handle

CloneHandles uses Handle.Copy to clone a slice of Handle.

func CloneRanges

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

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

func CloneSortItems

func CloneSortItems(items []property.SortItem) []property.SortItem

CloneSortItems uses SortItem.Clone to clone a slice of SortItem.

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 DeriveLimitStats

func DeriveLimitStats(childProfile *property.StatsInfo, limitCount float64) *property.StatsInfo

DeriveLimitStats derives the stats of the top-n plan.

func EncodeIntAsUint32

func EncodeIntAsUint32(result []byte, value int) []byte

EncodeIntAsUint32 is used for LogicalPlan Interface

func ExplainByItems

func ExplainByItems(ctx expression.EvalContext, buffer *bytes.Buffer, byItems []*ByItems) *bytes.Buffer

ExplainByItems generates explain information for ByItems.

func ExplainPartitionBy

func ExplainPartitionBy(ctx expression.EvalContext, buffer *bytes.Buffer,
	partitionBy []property.SortItem, normalized bool) *bytes.Buffer

ExplainPartitionBy produce text for p.PartitionBy. Common for window functions and TopN.

func ExtractConstantCols

func ExtractConstantCols(conditions []expression.Expression, sctx base.PlanContext,
	fds *funcdep.FDSet) intset.FastIntSet

ExtractConstantCols extracts constant columns from conditions.

func ExtractEquivalenceCols

func ExtractEquivalenceCols(conditions []expression.Expression, sctx base.PlanContext,
	fds *funcdep.FDSet) [][]intset.FastIntSet

ExtractEquivalenceCols extracts equivalence columns from conditions.

func ExtractNotNullFromConds

func ExtractNotNullFromConds(conditions []expression.Expression, p base.LogicalPlan) intset.FastIntSet

ExtractNotNullFromConds extracts not-null columns from conditions.

func ExtractTableAlias

func ExtractTableAlias(p base.Plan, parentOffset int) *h.HintedTable

ExtractTableAlias returns table alias of the base.LogicalPlan's columns. It will return nil when there are multiple table alias, because the alias is only used to check if the base.LogicalPlan Match some optimizer hints, and hints are not expected to take effect in this case.

func GetCommonHandleDatum

func GetCommonHandleDatum(cols HandleCols, row chunk.Row) []types.Datum

GetCommonHandleDatum gets the original data for the common handle.

func GetMaxSortPrefix

func GetMaxSortPrefix(sortCols, allCols []*expression.Column) []int

GetMaxSortPrefix returns the prefix offset of sortCols in allCols.

func GetPushDownCtx

func GetPushDownCtx(pctx base.PlanContext) expression.PushDownContext

GetPushDownCtx creates a PushDownContext from PlanContext

func GetPushDownCtxFromBuildPBContext

func GetPushDownCtxFromBuildPBContext(bctx *base.BuildPBContext) expression.PushDownContext

GetPushDownCtxFromBuildPBContext creates a PushDownContext from BuildPBContext

func IsNullRejected

func IsNullRejected(ctx base.PlanContext, innerSchema *expression.Schema, predicate expression.Expression) bool

IsNullRejected takes care of complex predicates like this: IsNullRejected(A OR B) = IsNullRejected(A) AND IsNullRejected(B) IsNullRejected(A AND B) = IsNullRejected(A) OR IsNullRejected(B)

func ResetNotNullFlag

func ResetNotNullFlag(schema *expression.Schema, start, end int)

ResetNotNullFlag resets the not null flag of [start, end] columns in the schema.

func StringifyByItemsWithCtx

func StringifyByItemsWithCtx(ctx expression.EvalContext, 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

	// If the top level of the filters is an OR list, IsDNFCond is true.
	// In this case, MinAccessCondsForDNFCond will record the minimum number of access conditions among all DNF items.
	// For example, if the filter is (a=1 and b=2) or (a=3 and b=4) or (a=5 and b=6 and c=7),
	// for index (a) or index (b), MinAccessCondsForDNFCond will be 1;
	// for index (a, b, c), MinAccessCondsForDNFCond will be 2.
	IsDNFCond                bool
	MinAccessCondsForDNFCond int

	// 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 planctx.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. Including tiflash table scan.

func (*AccessPath) IsTiFlashSimpleTablePath

func (path *AccessPath) IsTiFlashSimpleTablePath() bool

IsTiFlashSimpleTablePath returns true if it's a TiFlash path and will not use any special indexes like vector index.

func (*AccessPath) IsTiKVTablePath

func (path *AccessPath) IsTiKVTablePath() bool

IsTiKVTablePath returns true if it's IntHandlePath or CommonHandlePath. And the store type is TiKV.

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 planctx.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 CloneByItemss

func CloneByItemss(byItems []*ByItems) []*ByItems

CloneByItemss uses (*ByItems).Clone to clone a slice of *ByItems.

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

func (by *ByItems) Equals(other any) bool

Equals implements the base.Equaler interface.

func (*ByItems) Hash64

func (by *ByItems) Hash64(h base.Hasher)

Hash64 implements the base.Hasher interface.

func (*ByItems) MemoryUsage

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

MemoryUsage return the memory usage of ByItems.

func (*ByItems) StringWithCtx

func (by *ByItems) StringWithCtx(ctx expression.ParamValues, 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 CommonHandleCols

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

CommonHandleCols implements the kv.HandleCols interface.

func NewCommonHandleCols

func NewCommonHandleCols(sc *stmtctx.StatementContext, tblInfo *model.TableInfo, idxInfo *model.IndexInfo,
	tableColumns []*expression.Column) *CommonHandleCols

NewCommonHandleCols creates a new CommonHandleCols.

func NewCommonHandlesColsWithoutColsAlign

func NewCommonHandlesColsWithoutColsAlign(sc *stmtctx.StatementContext, tblInfo *model.TableInfo,
	idxInfo *model.IndexInfo, cols []*expression.Column) *CommonHandleCols

NewCommonHandlesColsWithoutColsAlign creates a new CommonHandleCols without internal col align.

func (*CommonHandleCols) BuildHandle

func (cb *CommonHandleCols) BuildHandle(row chunk.Row) (kv.Handle, error)

BuildHandle implements the kv.HandleCols interface.

func (*CommonHandleCols) BuildHandleByDatums

func (cb *CommonHandleCols) BuildHandleByDatums(row []types.Datum) (kv.Handle, error)

BuildHandleByDatums implements the kv.HandleCols interface.

func (*CommonHandleCols) BuildHandleFromIndexRow

func (cb *CommonHandleCols) BuildHandleFromIndexRow(row chunk.Row) (kv.Handle, error)

BuildHandleFromIndexRow implements the kv.HandleCols interface.

func (*CommonHandleCols) BuildPartitionHandleFromIndexRow

func (cb *CommonHandleCols) BuildPartitionHandleFromIndexRow(row chunk.Row) (kv.PartitionHandle, error)

BuildPartitionHandleFromIndexRow implements the kv.HandleCols interface.

func (*CommonHandleCols) Clone

Clone implements the kv.HandleCols interface.

func (*CommonHandleCols) Compare

func (cb *CommonHandleCols) Compare(a, b []types.Datum, ctors []collate.Collator) (int, error)

Compare implements the kv.HandleCols interface.

func (*CommonHandleCols) Equals

func (cb *CommonHandleCols) Equals(other any) bool

Equals implements HashEquals interface.

func (*CommonHandleCols) GetCol

func (cb *CommonHandleCols) GetCol(idx int) *expression.Column

GetCol implements the kv.HandleCols interface.

func (*CommonHandleCols) GetColumns

func (cb *CommonHandleCols) GetColumns() []*expression.Column

GetColumns returns all the internal columns out.

func (*CommonHandleCols) GetFieldsTypes

func (cb *CommonHandleCols) GetFieldsTypes() []*types.FieldType

GetFieldsTypes implements the kv.HandleCols interface.

func (*CommonHandleCols) Hash64

func (cb *CommonHandleCols) Hash64(h base.Hasher)

Hash64 implements HashEquals interface.

func (*CommonHandleCols) IsInt

func (*CommonHandleCols) IsInt() bool

IsInt implements the kv.HandleCols interface.

func (*CommonHandleCols) MemoryUsage

func (cb *CommonHandleCols) MemoryUsage() (sum int64)

MemoryUsage return the memory usage of CommonHandleCols

func (*CommonHandleCols) NumCols

func (cb *CommonHandleCols) NumCols() int

NumCols implements the kv.HandleCols interface.

func (*CommonHandleCols) ResolveIndices

func (cb *CommonHandleCols) ResolveIndices(schema *expression.Schema) (HandleCols, error)

ResolveIndices implements the kv.HandleCols interface.

func (*CommonHandleCols) StringWithCtx

func (cb *CommonHandleCols) StringWithCtx(ctx expression.ParamValues, _ string) string

StringWithCtx implements the kv.HandleCols interface.

type HandleCols

type HandleCols interface {
	expression.StringerWithCtx
	base.HashEquals

	// BuildHandle builds a Handle from a row.
	BuildHandle(row chunk.Row) (kv.Handle, error)
	// BuildHandleByDatums builds a Handle from a datum slice.
	BuildHandleByDatums(row []types.Datum) (kv.Handle, error)
	// BuildHandleFromIndexRow builds a Handle from index row data.
	// The last column(s) of `row` must be the handle column(s).
	BuildHandleFromIndexRow(row chunk.Row) (kv.Handle, error)
	// BuildHandleFromIndexRow builds a Handle from index row data.
	// The last column of `row` must be the pids,
	// and the second to last column(s) of `row` must be the handle column(s).
	BuildPartitionHandleFromIndexRow(row chunk.Row) (kv.PartitionHandle, error)
	// ResolveIndices resolves handle column indices.
	ResolveIndices(schema *expression.Schema) (HandleCols, error)
	// IsInt returns if the HandleCols is a single int column.
	IsInt() bool
	// GetCol gets the column by idx.
	GetCol(idx int) *expression.Column
	// NumCols returns the number of columns.
	NumCols() int
	// Compare compares two datum rows by handle order.
	Compare(a, b []types.Datum, ctors []collate.Collator) (int, error)
	// GetFieldsTypes return field types of columns.
	GetFieldsTypes() []*types.FieldType
	// MemoryUsage return the memory usage
	MemoryUsage() int64
	// Clone clones the HandleCols.
	Clone(newCtx *stmtctx.StatementContext) HandleCols
}

HandleCols is the interface that holds handle columns.

func CloneHandleCols

func CloneHandleCols(newCtx *stmtctx.StatementContext, handles []HandleCols) []HandleCols

CloneHandleCols uses HandleCols.Clone to clone a slice of HandleCols.

func NewIntHandleCols

func NewIntHandleCols(col *expression.Column) HandleCols

NewIntHandleCols creates a new IntHandleCols.

type IntHandleCols

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

IntHandleCols implements the kv.HandleCols interface.

func (*IntHandleCols) BuildHandle

func (ib *IntHandleCols) BuildHandle(row chunk.Row) (kv.Handle, error)

BuildHandle implements the kv.HandleCols interface.

func (*IntHandleCols) BuildHandleByDatums

func (ib *IntHandleCols) BuildHandleByDatums(row []types.Datum) (kv.Handle, error)

BuildHandleByDatums implements the kv.HandleCols interface.

func (*IntHandleCols) BuildHandleFromIndexRow

func (*IntHandleCols) BuildHandleFromIndexRow(row chunk.Row) (kv.Handle, error)

BuildHandleFromIndexRow implements the kv.HandleCols interface.

func (*IntHandleCols) BuildPartitionHandleFromIndexRow

func (*IntHandleCols) BuildPartitionHandleFromIndexRow(row chunk.Row) (kv.PartitionHandle, error)

BuildPartitionHandleFromIndexRow implements the kv.HandleCols interface.

func (*IntHandleCols) Clone

Clone implements the kv.HandleCols interface.

func (*IntHandleCols) Compare

func (ib *IntHandleCols) Compare(a, b []types.Datum, ctors []collate.Collator) (int, error)

Compare implements the kv.HandleCols interface.

func (*IntHandleCols) Equals

func (ib *IntHandleCols) Equals(other any) bool

Equals implements HashEquals interface.

func (*IntHandleCols) GetCol

func (ib *IntHandleCols) GetCol(idx int) *expression.Column

GetCol implements the kv.HandleCols interface.

func (*IntHandleCols) GetFieldsTypes

func (*IntHandleCols) GetFieldsTypes() []*types.FieldType

GetFieldsTypes implements the kv.HandleCols interface.

func (*IntHandleCols) Hash64

func (ib *IntHandleCols) Hash64(h base.Hasher)

Hash64 implements HashEquals interface.

func (*IntHandleCols) IsInt

func (*IntHandleCols) IsInt() bool

IsInt implements the kv.HandleCols interface.

func (*IntHandleCols) MemoryUsage

func (ib *IntHandleCols) MemoryUsage() (sum int64)

MemoryUsage return the memory usage of IntHandleCols

func (*IntHandleCols) NumCols

func (*IntHandleCols) NumCols() int

NumCols implements the kv.HandleCols interface.

func (*IntHandleCols) ResolveIndices

func (ib *IntHandleCols) ResolveIndices(schema *expression.Schema) (HandleCols, error)

ResolveIndices implements the kv.HandleCols interface.

func (*IntHandleCols) StringWithCtx

func (ib *IntHandleCols) StringWithCtx(ctx expression.ParamValues, _ string) string

StringWithCtx implements the kv.HandleCols interface.

type QueryTimeRange

type QueryTimeRange struct {
	From time.Time
	To   time.Time
}

QueryTimeRange represents a time range specified by TIME_RANGE hint

func (*QueryTimeRange) Condition

func (tr *QueryTimeRange) Condition() string

Condition returns a WHERE clause base on it's value

func (*QueryTimeRange) MemoryUsage

func (tr *QueryTimeRange) MemoryUsage() (sum int64)

MemoryUsage return the memory usage of QueryTimeRange

Jump to

Keyboard shortcuts

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