expression

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

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

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

Documentation

Index

Constants

View Source
const (
	SHA0   = 0
	SHA224 = 224
	SHA256 = 256
	SHA384 = 384
	SHA512 = 512
)

Supported hash length of SHA-2 family

View Source
const (
	// ASCII is pure ASCII U+0000..U+007F.
	ASCII Repertoire = 0x01
	// EXTENDED is extended characters: U+0080..U+FFFF
	EXTENDED = ASCII << 1
	// UNICODE is ASCII | EXTENDED
	UNICODE = ASCII | EXTENDED
)
View Source
const InternalFuncFromBinary = "from_binary"

InternalFuncFromBinary accepts a string and returns another string decode in a given charset.

View Source
const InternalFuncToBinary = "to_binary"

InternalFuncToBinary accepts a string and returns another string encoded in a given charset.

View Source
const (
	ScalarSubQFlag byte = 5
)

These are byte flags used for `HashCode()`.

Variables

View Source
var (
	// CollationStrictnessGroup group collation by strictness
	CollationStrictnessGroup = map[string]int{
		"utf8_general_ci":        1,
		"utf8mb4_general_ci":     1,
		"utf8_unicode_ci":        2,
		"utf8mb4_unicode_ci":     2,
		charset.CollationASCII:   3,
		charset.CollationLatin1:  3,
		charset.CollationUTF8:    3,
		charset.CollationUTF8MB4: 3,
		charset.CollationBin:     4,
	}

	// CollationStrictness indicates the strictness of comparison of the collation. The unequal order in a weak collation also holds in a strict collation.
	// For example, if a != b in a weak collation(e.g. general_ci), then there must be a != b in a strict collation(e.g. _bin).
	// collation group id in value is stricter than collation group id in key
	CollationStrictness = map[int][]int{
		1: {3, 4},
		2: {3, 4},
		3: {4},
		4: {},
	}
)
View Source
var (
	// All the exported errors are defined here:
	ErrIncorrectParameterCount     = dbterror.ClassExpression.NewStd(mysql.ErrWrongParamcountToNativeFct)
	ErrDivisionByZero              = dbterror.ClassExpression.NewStd(mysql.ErrDivisionByZero)
	ErrRegexp                      = dbterror.ClassExpression.NewStd(mysql.ErrRegexp)
	ErrOperandColumns              = dbterror.ClassExpression.NewStd(mysql.ErrOperandColumns)
	ErrCutValueGroupConcat         = dbterror.ClassExpression.NewStd(mysql.ErrCutValueGroupConcat)
	ErrFunctionsNoopImpl           = dbterror.ClassExpression.NewStdErr(mysql.ErrNotSupportedYet, pmysql.Message("function %s has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions", nil))
	ErrInvalidArgumentForLogarithm = dbterror.ClassExpression.NewStd(mysql.ErrInvalidArgumentForLogarithm)
	ErrIncorrectType               = dbterror.ClassExpression.NewStd(mysql.ErrIncorrectType)
	ErrInvalidTypeForJSON          = dbterror.ClassExpression.NewStd(mysql.ErrInvalidTypeForJSON)
	ErrInvalidTableSample          = dbterror.ClassExpression.NewStd(mysql.ErrInvalidTableSample)
	ErrNotSupportedYet             = dbterror.ClassExpression.NewStd(mysql.ErrNotSupportedYet)
	ErrInvalidJSONForFuncIndex     = dbterror.ClassExpression.NewStd(mysql.ErrInvalidJSONValueForFuncIndex)
	ErrDataOutOfRangeFuncIndex     = dbterror.ClassExpression.NewStd(mysql.ErrDataOutOfRangeFunctionalIndex)
	ErrFuncIndexDataIsTooLong      = dbterror.ClassExpression.NewStd(mysql.ErrFunctionalIndexDataIsTooLong)
	ErrFunctionNotExists           = dbterror.ClassExpression.NewStd(mysql.ErrSpDoesNotExist)
)

Error instances.

View Source
var AllowedPartition4BinaryOpMap = map[opcode.Op]struct{}{
	opcode.Plus:   {},
	opcode.Minus:  {},
	opcode.Mul:    {},
	opcode.IntDiv: {},
	opcode.Mod:    {},
}

AllowedPartition4BinaryOpMap store the operator for Binary Expr See https://dev.mysql.com/doc/refman/5.7/en/partitioning-limitations.html for more details

View Source
var AllowedPartition4UnaryOpMap = map[opcode.Op]struct{}{
	opcode.Plus:  {},
	opcode.Minus: {},
}

AllowedPartition4UnaryOpMap store the operator for Unary Expr

View Source
var AllowedPartitionFuncMap = map[string]struct{}{
	ast.ToDays:        {},
	ast.ToSeconds:     {},
	ast.DayOfMonth:    {},
	ast.Month:         {},
	ast.DayOfYear:     {},
	ast.Quarter:       {},
	ast.YearWeek:      {},
	ast.Year:          {},
	ast.Weekday:       {},
	ast.DayOfWeek:     {},
	ast.Day:           {},
	ast.Hour:          {},
	ast.Minute:        {},
	ast.Second:        {},
	ast.TimeToSec:     {},
	ast.MicroSecond:   {},
	ast.UnixTimestamp: {},
	ast.FromDays:      {},
	ast.Extract:       {},
	ast.Abs:           {},
	ast.Ceiling:       {},
	ast.DateDiff:      {},
	ast.Floor:         {},
	ast.Mod:           {},
}

AllowedPartitionFuncMap stores functions which can be used in the partition expression.

View Source
var BuildSimpleExpr func(ctx BuildContext, expr ast.ExprNode, opts ...BuildOption) (Expression, error)

BuildSimpleExpr builds a simple expression from an ast node. This function is used to build some "simple" expressions with limited context. The below expressions are not supported:

  • Subquery
  • System Variables (e.g. `@tidb_enable_async_commit`)
  • Window functions
  • Aggregate functions
  • Other special functions used in some specified queries such as `GROUPING`, `VALUES` ...

If you want to build a more complex expression, you should use `EvalAstExprWithPlanCtx` or `RewriteAstExprWithPlanCtx` in `github.com/pingcap/tidb/pkg/planner/util`. They are more powerful but need planner context to build expressions.

DecodeKeyFromString is used to decode key by expressions

View Source
var DefaultExprPushDownBlacklist *atomic.Value

DefaultExprPushDownBlacklist indicates the expressions which can not be pushed down to TiKV.

View Source
var DisableFoldFunctions = map[string]struct{}{
	ast.Benchmark: {},
}

DisableFoldFunctions stores functions which prevent child scope functions from being constant folded. Typically, these functions shall also exist in unFoldableFunctions, to stop from being folded when they themselves are in child scope of an outer function, and the outer function is recursively folding its children.

View Source
var EncodeIndexKeyFromRow func(ctx EvalContext, checker expropt.PrivilegeChecker, is infoschema.MetaOnlyInfoSchema, args []Expression, row chunk.Row) ([]byte, bool, error)

EncodeIndexKeyFromRow is used to encode index key by expressions.

View Source
var EncodeRecordKeyFromRow func(ctx EvalContext, checker expropt.PrivilegeChecker, is infoschema.MetaOnlyInfoSchema, args []Expression, row chunk.Row) ([]byte, bool, error)

EncodeRecordKeyFromRow is used to encode record key by expressions.

View Source
var EvalSimpleAst func(ctx BuildContext, expr ast.ExprNode) (types.Datum, error)

EvalSimpleAst evaluates a simple ast expression directly. This function is used to evaluate some "simple" expressions with limited context. See `BuildSimpleExpr` for more details about the differences.

View Source
var ExprPushDownBlackListReloadTimeStamp *atomic.Int64

ExprPushDownBlackListReloadTimeStamp is used to record the last time when the push-down black list is reloaded. This is for plan cache, when the push-down black list is updated, we invalid all cached plans to avoid error.

View Source
var IllegalFunctions4GeneratedColumns = map[string]struct{}{
	ast.ConnectionID:     {},
	ast.LoadFile:         {},
	ast.LastInsertId:     {},
	ast.Rand:             {},
	ast.UUID:             {},
	ast.UUIDShort:        {},
	ast.Curdate:          {},
	ast.CurrentDate:      {},
	ast.Curtime:          {},
	ast.CurrentTime:      {},
	ast.CurrentTimestamp: {},
	ast.LocalTime:        {},
	ast.LocalTimestamp:   {},
	ast.Now:              {},
	ast.UnixTimestamp:    {},
	ast.UTCDate:          {},
	ast.UTCTime:          {},
	ast.UTCTimestamp:     {},
	ast.Benchmark:        {},
	ast.CurrentUser:      {},
	ast.Database:         {},
	ast.FoundRows:        {},
	ast.GetLock:          {},
	ast.IsFreeLock:       {},
	ast.IsUsedLock:       {},
	ast.MasterPosWait:    {},
	ast.NameConst:        {},
	ast.ReleaseLock:      {},
	ast.RowFunc:          {},
	ast.RowCount:         {},
	ast.Schema:           {},
	ast.SessionUser:      {},
	ast.Sleep:            {},
	ast.Sysdate:          {},
	ast.SystemUser:       {},
	ast.User:             {},
	ast.Values:           {},
	ast.Encrypt:          {},
	ast.Version:          {},
	ast.JSONMerge:        {},
	ast.SetVar:           {},
	ast.GetVar:           {},
	ast.ReleaseAllLocks:  {},
}

IllegalFunctions4GeneratedColumns stores functions that is illegal for generated columns. See https://github.com/mysql/mysql-server/blob/5.7/mysql-test/suite/gcol/inc/gcol_blocked_sql_funcs_main.inc for details

View Source
var MaxPropagateColsCnt = 100

MaxPropagateColsCnt means the max number of columns that can participate propagation.

View Source
var TryFoldFunctions = map[string]struct{}{
	ast.If:       {},
	ast.Ifnull:   {},
	ast.Case:     {},
	ast.LogicAnd: {},
	ast.LogicOr:  {},
	ast.Coalesce: {},
	ast.Interval: {},
}

TryFoldFunctions stores functions which try to fold constant in child scope functions if without errors/warnings, otherwise, the child functions do not fold constant. Note: the function itself should fold constant.

View Source
var UnCacheableFunctions = map[string]struct{}{
	ast.Database:             {},
	ast.CurrentUser:          {},
	ast.CurrentRole:          {},
	ast.CurrentResourceGroup: {},
	ast.User:                 {},
	ast.ConnectionID:         {},
	ast.LastInsertId:         {},
	ast.RowCount:             {},
	ast.Version:              {},
	ast.Like:                 {},

	ast.JSONExtract:      {},
	ast.JSONObject:       {},
	ast.JSONArray:        {},
	ast.Coalesce:         {},
	ast.Convert:          {},
	ast.TimeLiteral:      {},
	ast.DateLiteral:      {},
	ast.TimestampLiteral: {},
	ast.AesEncrypt:       {},
	ast.AesDecrypt:       {},
}

UnCacheableFunctions stores functions which can not be cached to plan cache.

Functions

func AdjustNullabilityFromGroupingSets

func AdjustNullabilityFromGroupingSets(gss GroupingSets, schema *Schema)

AdjustNullabilityFromGroupingSets adjust the nullability of the Expand schema out.

func CalAppropriateTime

func CalAppropriateTime(minTime, maxTime, minSafeTime time.Time) time.Time

CalAppropriateTime directly calls calAppropriateTime

func CanExprsPushDown

func CanExprsPushDown(ctx PushDownContext, exprs []Expression, storeType kv.StoreType) bool

CanExprsPushDown return true if all the expr in exprs can be pushed down

func CanExprsPushDownWithExtraInfo

func CanExprsPushDownWithExtraInfo(ctx PushDownContext, exprs []Expression, storeType kv.StoreType, canEnumPush bool) bool

CanExprsPushDownWithExtraInfo return true if all the expr in exprs can be pushed down

func CanImplicitEvalInt

func CanImplicitEvalInt(expr Expression) bool

CanImplicitEvalInt represents the builtin functions that have an implicit path to evaluate as integer, regardless of the type that type inference decides it to be. This is a nasty way to match the weird behavior of MySQL functions like `dayname()` being implicitly evaluated as integer. See https://github.com/mysql/mysql-server/blob/ee4455a33b10f1b1886044322e4893f587b319ed/sql/item_timefunc.h#L423 for details.

func CanImplicitEvalReal

func CanImplicitEvalReal(expr Expression) bool

CanImplicitEvalReal represents the builtin functions that have an implicit path to evaluate as real, regardless of the type that type inference decides it to be. This is a nasty way to match the weird behavior of MySQL functions like `dayname()` being implicitly evaluated as real. See https://github.com/mysql/mysql-server/blob/ee4455a33b10f1b1886044322e4893f587b319ed/sql/item_timefunc.h#L423 for details.

func CheckArgsNotMultiColumnRow

func CheckArgsNotMultiColumnRow(args ...Expression) error

CheckArgsNotMultiColumnRow checks the args are not multi-column row.

func CheckFuncInExpr

func CheckFuncInExpr(e Expression, funcName string) bool

CheckFuncInExpr checks whether there's a given function in the expression.

func CheckNonDeterministic

func CheckNonDeterministic(e Expression) bool

CheckNonDeterministic checks whether the current expression contains a non-deterministic func.

func CompareDecimal

func CompareDecimal(sctx EvalContext, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row) (int64, bool, error)

CompareDecimal compares two decimals.

func CompareDuration

func CompareDuration(sctx EvalContext, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row) (int64, bool, error)

CompareDuration compares two durations.

func CompareInt

func CompareInt(sctx EvalContext, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row) (int64, bool, error)

CompareInt compares two integers.

func CompareJSON

func CompareJSON(sctx EvalContext, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row) (int64, bool, error)

CompareJSON compares two JSONs.

func CompareReal

func CompareReal(sctx EvalContext, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row) (int64, bool, error)

CompareReal compares two float-point values.

func CompareStringWithCollationInfo

func CompareStringWithCollationInfo(sctx EvalContext, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row, collation string) (int64, bool, error)

CompareStringWithCollationInfo compares two strings with the specified collation information.

func CompareTime

func CompareTime(sctx EvalContext, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row) (int64, bool, error)

CompareTime compares two datetime or timestamps.

func CompareVectorFloat32

func CompareVectorFloat32(sctx EvalContext, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row) (int64, bool, error)

CompareVectorFloat32 compares two float32 vectors.

func ConstExprConsiderPlanCache

func ConstExprConsiderPlanCache(expr Expression, inPlanCache bool) bool

ConstExprConsiderPlanCache indicates whether the expression can be considered as a constant expression considering planCache. If the expression is in plan cache, it should have a const level `ConstStrict` because it can be shared across statements. If the expression is not in plan cache, `ConstOnlyInContext` is enough because it is only used in one statement. Please notice that if the expression may be cached in other ways except plan cache, we should not use this function.

func ConstructPositionExpr

func ConstructPositionExpr(p *driver.ParamMarkerExpr) *ast.PositionExpr

ConstructPositionExpr constructs PositionExpr with the given ParamMarkerExpr.

func ContainCorrelatedColumn

func ContainCorrelatedColumn(exprs []Expression) bool

ContainCorrelatedColumn checks if the expressions contain a correlated column

func ContainOuterNot

func ContainOuterNot(expr Expression) bool

ContainOuterNot checks if there is an outer `not`.

func ContainVirtualColumn

func ContainVirtualColumn(exprs []Expression) bool

ContainVirtualColumn checks if the expressions contain a virtual column

func Contains

func Contains(ectx EvalContext, exprs []Expression, e Expression) bool

Contains tests if `exprs` contains `e`.

func ConvertJSON2Tp

func ConvertJSON2Tp(v types.BinaryJSON, targetType *types.FieldType) (any, error)

ConvertJSON2Tp converts JSON to the specified type.

func DisableParseJSONFlag4Expr

func DisableParseJSONFlag4Expr(ctx EvalContext, expr Expression)

DisableParseJSONFlag4Expr disables ParseToJSONFlag for `expr` except Column. We should not *PARSE* a string as JSON under some scenarios. ParseToJSONFlag is 0 for JSON column yet(as well as JSON correlated column), so we can skip it. Moreover, Column.RetType refers to the infoschema, if we modify it, data race may happen if another goroutine read from the infoschema at the same time.

func EvalBool

func EvalBool(ctx EvalContext, exprList CNFExprs, row chunk.Row) (bool, bool, error)

EvalBool evaluates expression list to a boolean value. The first returned value indicates bool result of the expression list, the second returned value indicates whether the result of the expression list is null, it can only be true when the first returned values is false.

func EvalExpr

func EvalExpr(ctx EvalContext, vecEnabled bool, expr Expression, evalType types.EvalType, input *chunk.Chunk, result *chunk.Column) (err error)

EvalExpr evaluates this expr according to its type. And it selects the method for evaluating expression based on the environment variables and whether the expression can be vectorized. Note: the input argument `evalType` is needed because of that when `expr` is of the hybrid type(ENUM/SET/BIT), we need the invoker decide the actual EvalType.

func ExplainColumnList

func ExplainColumnList(ctx EvalContext, cols []*Column) []byte

ExplainColumnList generates explain information for a list of columns.

func ExplainExpressionList

func ExplainExpressionList(ctx EvalContext, exprs []Expression, schema *Schema, redactMode string) string

ExplainExpressionList generates explain information for a list of expressions.

func ExprFromSchema

func ExprFromSchema(expr Expression, schema *Schema) bool

ExprFromSchema checks if all columns of this expression are from the same schema.

func ExprHasSetVarOrSleep

func ExprHasSetVarOrSleep(expr Expression) bool

ExprHasSetVarOrSleep checks if the expression has SetVar function or Sleep function.

func ExprNotNull

func ExprNotNull(ctx EvalContext, expr Expression) bool

ExprNotNull checks if an expression is possible to be null.

func ExprReferenceSchema

func ExprReferenceSchema(expr Expression, schema *Schema) bool

ExprReferenceSchema checks if any column of this expression are from the schema.

func ExpressionsSemanticEqual

func ExpressionsSemanticEqual(expr1, expr2 Expression) bool

ExpressionsSemanticEqual is used to judge whether two expression tree is semantic equivalent.

func ExpressionsToPBList

func ExpressionsToPBList(ctx EvalContext, exprs []Expression, client kv.Client) (pbExpr []*tipb.Expr, err error)

ExpressionsToPBList converts expressions to tipb.Expr list for new plan.

func ExprsHasSideEffects

func ExprsHasSideEffects(exprs []Expression) bool

ExprsHasSideEffects checks if any of the expressions has side effects.

func ExprsToStringsForDisplay

func ExprsToStringsForDisplay(ctx EvalContext, exprs []Expression) []string

ExprsToStringsForDisplay convert a slice of Expression to a slice of string using Expression.String(), and to make it better for display and debug, it also escapes the string to corresponding golang string literal, which means using \t, \n, \x??, \u????, ... to represent newline, control character, non-printable character, invalid utf-8 bytes and so on.

func ExtractColumnSet

func ExtractColumnSet(exprs ...Expression) intset.FastIntSet

ExtractColumnSet extracts the different values of `UniqueId` for columns in expressions.

func ExtractEquivalenceColumns

func ExtractEquivalenceColumns(result [][]Expression, exprs []Expression) [][]Expression

ExtractEquivalenceColumns detects the equivalence from CNF exprs.

func FieldTypeFromPB

func FieldTypeFromPB(ft *tipb.FieldType) *types.FieldType

FieldTypeFromPB converts *tipb.FieldType to *types.FieldType.

func FindFieldName

func FindFieldName(names types.NameSlice, astCol *ast.ColumnName) (int, error)

FindFieldName finds the column name from NameSlice.

func FindFieldNameIdxByColName

func FindFieldNameIdxByColName(names []*types.FieldName, colName string) int

FindFieldNameIdxByColName finds the index of corresponding name in the given slice. -1 for not found.

func GcColumnExprIsTidbShard

func GcColumnExprIsTidbShard(virtualExpr Expression) bool

GcColumnExprIsTidbShard check whether the expression is tidb_shard()

func GetAccurateCmpType

func GetAccurateCmpType(ctx EvalContext, lhs, rhs Expression) types.EvalType

GetAccurateCmpType uses a more complex logic to decide the EvalType of the two args when compare with each other than getBaseCmpType does.

func GetBuiltinList

func GetBuiltinList() []string

GetBuiltinList returns a list of builtin functions

func GetColumn

func GetColumn(_ types.EvalType, _ int) (*chunk.Column, error)

GetColumn allocates a column. The allocator is not responsible for initializing the column, so please initialize it before using.

func GetDisplayName

func GetDisplayName(name string) string

GetDisplayName translate a function name to its display name

func GetFormatBytes

func GetFormatBytes(bytes float64) string

GetFormatBytes convert byte count to value with units.

func GetFormatNanoTime

func GetFormatNanoTime(time float64) string

GetFormatNanoTime convert time in nanoseconds to value with units.

func GetIntFromConstant

func GetIntFromConstant(ctx EvalContext, value Expression) (int, bool, error)

GetIntFromConstant gets an integer value from the Constant expression.

func GetOptionalEvalPropsForExpr

func GetOptionalEvalPropsForExpr(expr Expression) exprctx.OptionalEvalPropKeySet

GetOptionalEvalPropsForExpr gets all optional evaluation properties that this expression requires.

func GetRowLen

func GetRowLen(e Expression) int

GetRowLen gets the length if the func is row, returns 1 if not row.

func GetStmtMinSafeTime

func GetStmtMinSafeTime(sc *stmtctx.StatementContext, store kv.Storage, timeZone *time.Location) time.Time

GetStmtMinSafeTime get minSafeTime

func GetStmtTimestamp

func GetStmtTimestamp(ctx EvalContext) (time.Time, error)

GetStmtTimestamp directly calls getTimeZone with timezone

func GetStringFromConstant

func GetStringFromConstant(ctx EvalContext, value Expression) (string, bool, error)

GetStringFromConstant gets a string value from the Constant expression.

func GetTimeCurrentTimestamp

func GetTimeCurrentTimestamp(ctx EvalContext, tp byte, fsp int) (d types.Datum, err error)

GetTimeCurrentTimestamp is used for generating a timestamp for some special cases: cast null value to timestamp type with not null flag.

func GetTimeValue

func GetTimeValue(ctx BuildContext, v any, tp byte, fsp int, explicitTz *time.Location) (d types.Datum, err error)

GetTimeValue gets the time value with type tp.

func GetUint64FromConstant

func GetUint64FromConstant(ctx EvalContext, expr Expression) (uint64, bool, bool)

GetUint64FromConstant gets a uint64 from constant expression.

func GetUsedList

func GetUsedList(ctx EvalContext, usedCols []*Column, schema *Schema) []bool

GetUsedList shows whether each column in schema is contained in usedCols.

func GroupByItemToPB

func GroupByItemToPB(ctx EvalContext, client kv.Client, expr Expression) *tipb.ByItem

GroupByItemToPB converts group by items to pb.

func HasAssignSetVarFunc

func HasAssignSetVarFunc(expr Expression) bool

HasAssignSetVarFunc checks whether an expression contains SetVar function and assign a value

func HasGetSetVarFunc

func HasGetSetVarFunc(expr Expression) bool

HasGetSetVarFunc checks whether an expression contains SetVar/GetVar function.

func InferType4ControlFuncs

func InferType4ControlFuncs(ctx BuildContext, funcName string, args ...Expression) (*types.FieldType, error)

InferType4ControlFuncs infer result type for builtin IF, IFNULL, NULLIF, CASEWHEN, COALESCE, LEAD and LAG.

func IsBinaryLiteral

func IsBinaryLiteral(expr Expression) bool

IsBinaryLiteral checks whether an expression is a binary literal

func IsDeferredFunctions

func IsDeferredFunctions(ctx BuildContext, fn string) bool

IsDeferredFunctions checks whether the function is in DeferredFunctions. DeferredFunctions stores functions which are foldable but should be deferred as well when plan cache is enabled. Note that, these functions must be foldable at first place, i.e, they are not in `unFoldableFunctions`.

func IsEQCondFromIn

func IsEQCondFromIn(expr Expression) bool

IsEQCondFromIn checks if an expression is equal condition converted from `[not] in (subq)`.

func IsFunctionSupported

func IsFunctionSupported(name string) bool

IsFunctionSupported check if given function name is a builtin sql function.

func IsImmutableFunc

func IsImmutableFunc(expr Expression) bool

IsImmutableFunc checks whether this expression only consists of foldable functions. This expression can be evaluated by using `expr.Eval(chunk.Row{})` directly and the result won't change if it's immutable.

func IsMutableEffectsExpr

func IsMutableEffectsExpr(expr Expression) bool

IsMutableEffectsExpr checks if expr contains function which is mutable or has side effects.

func IsPushDownEnabled

func IsPushDownEnabled(name string, storeType kv.StoreType) bool

IsPushDownEnabled returns true if the input expr is not in the expr_pushdown_blacklist

func IsRuntimeConstExpr

func IsRuntimeConstExpr(expr Expression) bool

IsRuntimeConstExpr checks if a expr can be treated as a constant in **executor**.

func IsValidCurrentTimestampExpr

func IsValidCurrentTimestampExpr(exprNode ast.ExprNode, fieldType *types.FieldType) bool

IsValidCurrentTimestampExpr returns true if exprNode is a valid CurrentTimestamp expression. Here `valid` means it is consistent with the given fieldType's decimal.

func LowerAlphaASCII

func LowerAlphaASCII(loweredCol *chunk.Column, rowNum int)

LowerAlphaASCII only lowers alpha ascii

func LowerAlphaASCIIExcludeEscapeChar

func LowerAlphaASCIIExcludeEscapeChar(loweredCol *chunk.Column, rowNum int, excludedChar int64) int64

LowerAlphaASCIIExcludeEscapeChar lower alpha ascii exclude escape char

func MaybeOverOptimized4PlanCache

func MaybeOverOptimized4PlanCache(ctx BuildContext, exprs []Expression) bool

MaybeOverOptimized4PlanCache used to check whether an optimization can work for the statement when we enable the plan cache. In some situations, some optimizations maybe over-optimize and cache an overOptimized plan. The cached plan may not get the correct result when we reuse the plan for other statements. For example, `pk>=$a and pk<=$b` can be optimized to a PointGet when `$a==$b`, but it will cause wrong results when `$a!=$b`. So we need to do the check here. The check includes the following aspects: 1. Whether the plan cache switch is enable. 2. Whether the statement can be cached. 3. Whether the expressions contain a lazy constant. TODO: Do more careful check here.

func PbTypeToFieldType

func PbTypeToFieldType(tp *tipb.FieldType) *types.FieldType

PbTypeToFieldType converts tipb.FieldType to FieldType

func PosFromPositionExpr

func PosFromPositionExpr(ctx BuildContext, v *ast.PositionExpr) (int, bool, error)

PosFromPositionExpr generates a position value from PositionExpr.

func ProjectionBenefitsFromPushedDown

func ProjectionBenefitsFromPushedDown(exprs []Expression, inputSchemaLen int) bool

ProjectionBenefitsFromPushedDown evaluates if the expressions can improve performance when pushed down to TiKV Projections are not pushed down to tikv by default, thus we need to check strictly here to avoid potential performance degradation. Note: virtual column is not considered here, since this function cares performance instead of functionality

func ProjectionExpressionsToPBList

func ProjectionExpressionsToPBList(ctx EvalContext, exprs []Expression, client kv.Client) (pbExpr []*tipb.Expr, err error)

ProjectionExpressionsToPBList converts PhysicalProjection's expressions to tipb.Expr list for new plan. It doesn't check type for top level column expression, since top level column expression doesn't imply any calculations

func PropConstOverOuterJoin

func PropConstOverOuterJoin(ctx exprctx.ExprContext, joinConds, filterConds []Expression,
	outerSchema, innerSchema *Schema, nullSensitive bool) ([]Expression, []Expression)

PropConstOverOuterJoin propagate constant equal and column equal conditions over outer join. First step is to extract `outerCol = const` from join conditions and filter conditions, and substitute `outerCol` in join conditions with `const`; Second step is to extract `outerCol = innerCol` from join conditions, and derive new join conditions based on this column equal condition and `outerCol` related expressions in join conditions and filter conditions;

func PropagateType

func PropagateType(ctx EvalContext, evalType types.EvalType, args ...Expression)

PropagateType propagates the type information to the `expr`. Note: For now, we only propagate type for the function CastDecimalAsDouble.

e.g. > create table t(a decimal(9, 8)); > insert into t values(5.04600000) > select a/36000 from t; Type: NEWDECIMAL Length: 15 Decimals: 12 +------------------+ | 5.04600000/36000 | +------------------+ | 0.000140166667 | +------------------+

> select cast(a/36000 as double) as result from t; Type: DOUBLE Length: 23 Decimals: 31 +----------------------+ | result | +----------------------+ | 0.000140166666666666 | +----------------------+ The expected `decimal` and `length` of the outer cast_as_double need to be propagated to the inner div.

func PushDownExprs

func PushDownExprs(ctx PushDownContext, exprs []Expression, storeType kv.StoreType) (pushed []Expression, remained []Expression)

PushDownExprs split the input exprs into pushed and remained, pushed include all the exprs that can be pushed down

func PushDownExprsWithExtraInfo

func PushDownExprsWithExtraInfo(ctx PushDownContext, exprs []Expression, storeType kv.StoreType, canEnumPush bool) (pushed []Expression, remained []Expression)

PushDownExprsWithExtraInfo split the input exprs into pushed and remained, pushed include all the exprs that can be pushed down

func PutColumn

func PutColumn(buf *chunk.Column)

PutColumn releases a column buffer.

func Quote

func Quote(str string) string

Quote produce a result that can be used as a properly escaped data value in an SQL statement.

func ReHashCode

func ReHashCode(sf *ScalarFunction)

ReHashCode is used after we change the argument in place.

func RemoveMutableConst

func RemoveMutableConst(ctx BuildContext, exprs []Expression) (err error)

RemoveMutableConst used to remove the `ParamMarker` and `DeferredExpr` in the `Constant` expr.

func ResolveType4Between

func ResolveType4Between(ctx EvalContext, args [3]Expression) types.EvalType

ResolveType4Between resolves eval type for between expression.

func SetBinFlagOrBinStr

func SetBinFlagOrBinStr(argTp *types.FieldType, resTp *types.FieldType)

SetBinFlagOrBinStr sets resTp to binary string if argTp is a binary string, if not, sets the binary flag of resTp to true if argTp has binary flag. We need to check if the tp is enum or set, if so, don't add binary flag directly unless it has binary flag.

func SortByItemToPB

func SortByItemToPB(ctx EvalContext, client kv.Client, expr Expression, desc bool) *tipb.ByItem

SortByItemToPB converts order by items to pb.

func SortedExplainExpressionList

func SortedExplainExpressionList(ctx EvalContext, exprs []Expression) []byte

SortedExplainExpressionList generates explain information for a list of expressions in order. In some scenarios, the expr's order may not be stable when executing multiple times. So we add a sort to make its explain result stable.

func SortedExplainExpressionListIgnoreInlist

func SortedExplainExpressionListIgnoreInlist(exprs []Expression) []byte

SortedExplainExpressionListIgnoreInlist generates explain information for a list of expressions in order.

func SortedExplainNormalizedExpressionList

func SortedExplainNormalizedExpressionList(exprs []Expression) []byte

SortedExplainNormalizedExpressionList is same like SortedExplainExpressionList, but use for generating normalized information.

func SortedExplainNormalizedScalarFuncList

func SortedExplainNormalizedScalarFuncList(exprs []*ScalarFunction) []byte

SortedExplainNormalizedScalarFuncList is same like SortedExplainExpressionList, but use for generating normalized information.

func StringifyExpressionsWithCtx

func StringifyExpressionsWithCtx(ctx EvalContext, exprs []Expression) string

StringifyExpressionsWithCtx turns a slice of expressions into string

func ToPBFieldType

func ToPBFieldType(ft *types.FieldType) *tipb.FieldType

ToPBFieldType converts *types.FieldType to *tipb.FieldType.

func ToPBFieldTypeWithCheck

func ToPBFieldTypeWithCheck(ft *types.FieldType, storeType kv.StoreType) (*tipb.FieldType, error)

ToPBFieldTypeWithCheck converts *types.FieldType to *tipb.FieldType with checking the valid decimal for TiFlash

func ValidCompareConstantPredicate

func ValidCompareConstantPredicate(ctx EvalContext, candidatePredicate Expression) bool

ValidCompareConstantPredicate checks if the predicate is an expression like [column '>'|'>='|'<'|'<='|'=' constant]. return param1: return true, if the predicate is a compare constant predicate. return param2: return the column side of predicate.

func ValidCompareConstantPredicateHelper

func ValidCompareConstantPredicateHelper(ctx EvalContext, eq *ScalarFunction, colIsLeft bool) (*Column, *Constant)

ValidCompareConstantPredicateHelper checks if the predicate is a compare constant predicate, like "Column xxx Constant"

func VecEvalBool

func VecEvalBool(ctx EvalContext, vecEnabled bool, exprList CNFExprs, input *chunk.Chunk, selected, nulls []bool) ([]bool, []bool, error)

VecEvalBool does the same thing as EvalBool but it works in a vectorized manner.

func Vectorizable

func Vectorizable(exprs []Expression) bool

Vectorizable checks whether a list of expressions can employ vectorized execution.

func VectorizedExecute

func VectorizedExecute(ctx EvalContext, exprs []Expression, iterator *chunk.Iterator4Chunk, output *chunk.Chunk) error

VectorizedExecute evaluates a list of expressions column by column and append their results to "output" Chunk.

func VectorizedFilter

func VectorizedFilter(ctx EvalContext, vecEnabled bool, filters []Expression, iterator *chunk.Iterator4Chunk, selected []bool) (_ []bool, err error)

VectorizedFilter applies a list of filters to a Chunk and returns a bool slice, which indicates whether a row is passed the filters. Filters is executed vectorized.

func VectorizedFilterConsiderNull

func VectorizedFilterConsiderNull(ctx EvalContext, vecEnabled bool, filters []Expression, iterator *chunk.Iterator4Chunk, selected []bool, isNull []bool) ([]bool, []bool, error)

VectorizedFilterConsiderNull applies a list of filters to a Chunk and returns two bool slices, `selected` indicates whether a row passed the filters, `isNull` indicates whether the result of the filter is null. Filters is executed vectorized.

func VerifyArgsWrapper

func VerifyArgsWrapper(name string, l int) error

VerifyArgsWrapper verifies a function by its name and the count of the arguments. Note that this function assumes that the function is supported.

Types

type AggFuncBuildContext

type AggFuncBuildContext = exprctx.ExprContext

AggFuncBuildContext is used to build an aggregation expression

type Assignment

type Assignment struct {
	Col *Column
	// ColName indicates its original column name in table schema. It's used for outputting helping message when executing meets some errors.
	ColName pmodel.CIStr
	Expr    Expression
	// LazyErr is used in statement like `INSERT INTO t1 (a) VALUES (1) ON DUPLICATE KEY UPDATE a= (SELECT b FROM source);`, ErrSubqueryMoreThan1Row
	// should be evaluated after the duplicate situation is detected in the executing procedure.
	LazyErr error
}

Assignment represents a set assignment in Update, such as Update t set c1 = hex(12), c2 = c3 where c2 = 1

func (*Assignment) Clone

func (a *Assignment) Clone() *Assignment

Clone clones the Assignment.

func (*Assignment) MemoryUsage

func (a *Assignment) MemoryUsage() (sum int64)

MemoryUsage return the memory usage of Assignment

type BuildContext

type BuildContext = exprctx.BuildContext

BuildContext is used to build an expression

type BuildOption

type BuildOption func(*BuildOptions)

BuildOption is a function to apply optional settings

func WithAllowCastArray

func WithAllowCastArray(allow bool) BuildOption

WithAllowCastArray specifies whether to allow casting to an array type.

func WithCastExprTo

func WithCastExprTo(targetFt *types.FieldType) BuildOption

WithCastExprTo indicates that we need to the cast the generated expression to the target type

func WithInputSchemaAndNames

func WithInputSchemaAndNames(schema *Schema, names types.NameSlice, table *model.TableInfo) BuildOption

WithInputSchemaAndNames specifies the input schema and names for the expression to build.

func WithTableInfo

func WithTableInfo(db string, tblInfo *model.TableInfo) BuildOption

WithTableInfo specifies table meta for the expression to build. When this option is specified, it will use the table meta to resolve column names.

type BuildOptions

type BuildOptions struct {
	// InputSchema is the input schema for expression to build
	InputSchema *Schema
	// InputNames is the input names for expression to build
	InputNames types.NameSlice
	// SourceTableDB is the database that the source table located
	SourceTableDB pmodel.CIStr
	// SourceTable is used to provide some extra column info.
	SourceTable *model.TableInfo
	// AllowCastArray specifies whether to allow casting to an array type.
	AllowCastArray bool
	// TargetFieldType indicates to cast the expression to the target field type if it is not nil
	TargetFieldType *types.FieldType
}

BuildOptions is used to provide optional settings to build an expression

type BuiltinGroupingImplSig

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

BuiltinGroupingImplSig grouping functions called by user is actually executed by this. Users will designate a column as parameter to pass into the grouping function, and tidb will rewrite it to convert the parameter to the meta info. Then, tidb will generate grouping id which is a indicator to be calculated with meta info, these grouping id are actually what BuiltinGroupingImplSig receives.

func (*BuiltinGroupingImplSig) Clone

func (b *BuiltinGroupingImplSig) Clone() builtinFunc

Clone implementing the builtinFunc interface.

func (*BuiltinGroupingImplSig) MemoryUsage

func (b *BuiltinGroupingImplSig) MemoryUsage() (sum int64)

MemoryUsage return the memory usage of baseBuiltinFunc

func (*BuiltinGroupingImplSig) PbCode

func (b *BuiltinGroupingImplSig) PbCode() tipb.ScalarFuncSig

func (*BuiltinGroupingImplSig) RequiredOptionalEvalProps

func (*BuiltinGroupingImplSig) RequiredOptionalEvalProps() (set OptionalEvalPropKeySet)

func (*BuiltinGroupingImplSig) SafeToShareAcrossSession

func (*BuiltinGroupingImplSig) SafeToShareAcrossSession() bool

SafeToShareAcrossSession implements the builtinFunc interface.

func (*BuiltinGroupingImplSig) SetMetadata

func (b *BuiltinGroupingImplSig) SetMetadata(mode tipb.GroupingMode, groupingMarks []map[uint64]struct{}) error

SetMetadata will fill grouping function with comparison groupingMarks when rewriting grouping function.

type CNFExprs

type CNFExprs []Expression

CNFExprs stands for a CNF expression.

func (CNFExprs) Clone

func (e CNFExprs) Clone() CNFExprs

Clone clones itself.

func (CNFExprs) Shallow

func (e CNFExprs) Shallow() CNFExprs

Shallow makes a shallow copy of itself.

type Coercibility

type Coercibility int32

Coercibility values are used to check whether the collation of one item can be coerced to the collation of other. See https://dev.mysql.com/doc/refman/8.0/en/charset-collation-coercibility.html

const (
	// CoercibilityExplicit is derived from an explicit COLLATE clause.
	CoercibilityExplicit Coercibility = 0
	// CoercibilityNone is derived from the concatenation of two strings with different collations.
	CoercibilityNone Coercibility = 1
	// CoercibilityImplicit is derived from a column or a stored routine parameter or local variable or cast() function.
	CoercibilityImplicit Coercibility = 2
	// CoercibilitySysconst is derived from a “system constant” (the string returned by functions such as USER() or VERSION()).
	CoercibilitySysconst Coercibility = 3
	// CoercibilityCoercible is derived from a literal.
	CoercibilityCoercible Coercibility = 4
	// CoercibilityNumeric is derived from a numeric or temporal value.
	CoercibilityNumeric Coercibility = 5
	// CoercibilityIgnorable is derived from NULL or an expression that is derived from NULL.
	CoercibilityIgnorable Coercibility = 6
)

type CollationInfo

type CollationInfo interface {
	// HasCoercibility returns if the Coercibility value is initialized.
	HasCoercibility() bool

	// Coercibility returns the coercibility value which is used to check collations.
	Coercibility() Coercibility

	// SetCoercibility sets a specified coercibility for this expression.
	SetCoercibility(val Coercibility)

	// Repertoire returns the repertoire value which is used to check collations.
	Repertoire() Repertoire

	// SetRepertoire sets a specified repertoire for this expression.
	SetRepertoire(r Repertoire)

	// CharsetAndCollation gets charset and collation.
	CharsetAndCollation() (string, string)

	// SetCharsetAndCollation sets charset and collation.
	SetCharsetAndCollation(chs, coll string)

	// IsExplicitCharset return the charset is explicit set or not.
	IsExplicitCharset() bool

	// SetExplicitCharset set the charset is explicit or not.
	SetExplicitCharset(bool)
}

CollationInfo contains all interfaces about dealing with collation.

type Column

type Column struct {
	RetType *types.FieldType `plan-cache-clone:"shallow"`
	// ID is used to specify whether this column is ExtraHandleColumn or to access histogram.
	// We'll try to remove it in the future.
	ID int64
	// UniqueID is the unique id of this column.
	UniqueID int64

	// Index is used for execution, to tell the column's position in the given row.
	Index int

	// VirtualExpr is used to save expression for virtual column
	VirtualExpr Expression

	OrigName string
	IsHidden bool

	// IsPrefix indicates whether this column is a prefix column in index.
	//
	// for example:
	// 	pk(col1, col2), index(col1(10)), key: col1(10)_col1_col2 => index's col1 will be true
	// 	pk(col1(10), col2), index(col1), key: col1_col1(10)_col2 => pk's col1 will be true
	IsPrefix bool

	// InOperand indicates whether this column is the inner operand of column equal condition converted
	// from `[not] in (subq)`.
	InOperand bool

	CorrelatedColUniqueID int64
	// contains filtered or unexported fields
}

Column represents a column.

func ColInfo2Col

func ColInfo2Col(cols []*Column, col *model.ColumnInfo) *Column

ColInfo2Col finds the corresponding column of the ColumnInfo in a column slice.

func ColumnInfos2ColumnsAndNames

func ColumnInfos2ColumnsAndNames(ctx BuildContext, dbName, tblName pmodel.CIStr, colInfos []*model.ColumnInfo, tblInfo *model.TableInfo) ([]*Column, types.NameSlice, error)

ColumnInfos2ColumnsAndNames converts the ColumnInfo to the *Column and NameSlice.

func ExtractColumns

func ExtractColumns(expr Expression) []*Column

ExtractColumns extracts all columns from an expression.

func ExtractColumnsAndCorColumnsFromExpressions

func ExtractColumnsAndCorColumnsFromExpressions(result []*Column, list []Expression) []*Column

ExtractColumnsAndCorColumnsFromExpressions extracts columns and correlated columns from expressions and append them to `result`.

func ExtractColumnsFromExpressions

func ExtractColumnsFromExpressions(result []*Column, exprs []Expression, filter func(*Column) bool) []*Column

ExtractColumnsFromExpressions is a more efficient version of ExtractColumns for batch operation. filter can be nil, or a function to filter the result column. It's often observed that the pattern of the caller like this:

cols := ExtractColumns(...)

for _, col := range cols {
    if xxx(col) {...}
}

Provide an additional filter argument, this can be done in one step. To avoid allocation for cols that not need.

func ExtractDependentColumns

func ExtractDependentColumns(expr Expression) []*Column

ExtractDependentColumns extracts all dependent columns from a virtual column.

func FindPrefixOfIndex

func FindPrefixOfIndex(cols []*Column, idxColIDs []int64) []*Column

FindPrefixOfIndex will find columns in index by checking the unique id. So it will return at once no matching column is found.

func FindUpperBound

func FindUpperBound(expr Expression) (*Column, int64)

FindUpperBound looks for column < constant or column <= constant and returns both the column and constant. It return nil, 0 if the expression is not of this form. It is used by derived Top N pattern and it is put here since it looks like a general purpose routine. Similar routines can be added to find lower bound as well.

func IndexCol2Col

func IndexCol2Col(colInfos []*model.ColumnInfo, cols []*Column, col *model.IndexColumn) *Column

IndexCol2Col finds the corresponding column of the IndexColumn in a column slice.

func IndexInfo2Cols

func IndexInfo2Cols(colInfos []*model.ColumnInfo, cols []*Column, index *model.IndexInfo) ([]*Column, []int)

IndexInfo2Cols gets the corresponding []*Column of the indexInfo's []*IndexColumn, together with a []int containing their lengths. If this index has three IndexColumn that the 1st and 3rd IndexColumn has corresponding *Column, the return value will be [col1, nil, col2].

func IndexInfo2PrefixCols

func IndexInfo2PrefixCols(colInfos []*model.ColumnInfo, cols []*Column, index *model.IndexInfo) ([]*Column, []int)

IndexInfo2PrefixCols gets the corresponding []*Column of the indexInfo's []*IndexColumn, together with a []int containing their lengths. If this index has three IndexColumn that the 1st and 3rd IndexColumn has corresponding *Column, the return value will be only the 1st corresponding *Column and its length. TODO: Use a struct to represent {*Column, int}. And merge IndexInfo2PrefixCols and IndexInfo2Cols.

func SortColumns

func SortColumns(cols []*Column) []*Column

SortColumns sort columns based on UniqueID.

func (*Column) CanonicalHashCode

func (col *Column) CanonicalHashCode() []byte

CanonicalHashCode implements Expression interface.

func (*Column) CharsetAndCollation

func (c *Column) CharsetAndCollation() (string, string)

func (*Column) CleanHashCode

func (col *Column) CleanHashCode()

CleanHashCode will clean the hashcode you may be cached before. It's used especially in schema-cloned & reallocated-uniqueID's cases.

func (*Column) Clone

func (col *Column) Clone() Expression

Clone implements Expression interface.

func (*Column) Coercibility

func (col *Column) Coercibility() Coercibility

Coercibility returns the coercibility value which is used to check collations.

func (*Column) ColumnExplainInfo

func (col *Column) ColumnExplainInfo(ctx ParamValues, normalized bool) string

ColumnExplainInfo returns the explained info for column.

func (*Column) ColumnExplainInfoNormalized

func (col *Column) ColumnExplainInfoNormalized() string

ColumnExplainInfoNormalized returns the normalized explained info for column.

func (*Column) ConstLevel

func (col *Column) ConstLevel() ConstLevel

ConstLevel returns the const level for the expression

func (*Column) Decorrelate

func (col *Column) Decorrelate(_ *Schema) Expression

Decorrelate implements Expression interface.

func (*Column) Equal

func (col *Column) Equal(_ EvalContext, expr Expression) bool

Equal implements Expression interface.

func (*Column) EqualByExprAndID

func (col *Column) EqualByExprAndID(ctx EvalContext, expr Expression) bool

EqualByExprAndID extends Equal by comparing virtual expression

func (*Column) EqualColumn

func (col *Column) EqualColumn(expr Expression) bool

EqualColumn returns whether two column is equal

func (*Column) Equals

func (col *Column) Equals(other any) bool

Equals implements HashEquals.<1st> interface.

func (*Column) Eval

func (col *Column) Eval(_ EvalContext, row chunk.Row) (types.Datum, error)

Eval implements Expression interface.

func (*Column) EvalDecimal

func (col *Column) EvalDecimal(ctx EvalContext, row chunk.Row) (*types.MyDecimal, bool, error)

EvalDecimal returns decimal representation of Column.

func (*Column) EvalDuration

func (col *Column) EvalDuration(ctx EvalContext, row chunk.Row) (types.Duration, bool, error)

EvalDuration returns Duration representation of Column.

func (*Column) EvalInt

func (col *Column) EvalInt(ctx EvalContext, row chunk.Row) (int64, bool, error)

EvalInt returns int representation of Column.

func (*Column) EvalJSON

func (col *Column) EvalJSON(ctx EvalContext, row chunk.Row) (types.BinaryJSON, bool, error)

EvalJSON returns JSON representation of Column.

func (*Column) EvalReal

func (col *Column) EvalReal(ctx EvalContext, row chunk.Row) (float64, bool, error)

EvalReal returns real representation of Column.

func (*Column) EvalString

func (col *Column) EvalString(ctx EvalContext, row chunk.Row) (string, bool, error)

EvalString returns string representation of Column.

func (*Column) EvalTime

func (col *Column) EvalTime(ctx EvalContext, row chunk.Row) (types.Time, bool, error)

EvalTime returns DATE/DATETIME/TIMESTAMP representation of Column.

func (*Column) EvalVectorFloat32

func (col *Column) EvalVectorFloat32(ctx EvalContext, row chunk.Row) (types.VectorFloat32, bool, error)

EvalVectorFloat32 returns VectorFloat32 representation of Column.

func (*Column) EvalVirtualColumn

func (col *Column) EvalVirtualColumn(ctx EvalContext, row chunk.Row) (types.Datum, error)

EvalVirtualColumn evals the virtual column

func (*Column) ExplainInfo

func (col *Column) ExplainInfo(ctx EvalContext) string

ExplainInfo implements the Expression interface.

func (*Column) ExplainNormalizedInfo

func (col *Column) ExplainNormalizedInfo() string

ExplainNormalizedInfo implements the Expression interface.

func (*Column) ExplainNormalizedInfo4InList

func (col *Column) ExplainNormalizedInfo4InList() string

ExplainNormalizedInfo4InList implements the Expression interface.

func (*Column) GetStaticType

func (col *Column) GetStaticType() *types.FieldType

GetStaticType returns the type without considering the context.

func (*Column) GetType

func (col *Column) GetType(_ EvalContext) *types.FieldType

GetType implements Expression interface.

func (*Column) HasCoercibility

func (c *Column) HasCoercibility() bool

func (*Column) Hash64

func (col *Column) Hash64(h base.Hasher)

Hash64 implements HashEquals.<0th> interface.

func (*Column) HashCode

func (col *Column) HashCode() []byte

HashCode implements Expression interface.

func (*Column) InColumnArray

func (col *Column) InColumnArray(cols []*Column) bool

InColumnArray check whether the col is in the cols array

func (*Column) IsCorrelated

func (col *Column) IsCorrelated() bool

IsCorrelated implements Expression interface.

func (*Column) IsExplicitCharset

func (c *Column) IsExplicitCharset() bool

func (*Column) MemoryUsage

func (col *Column) MemoryUsage() (sum int64)

MemoryUsage return the memory usage of Column

func (*Column) RemapColumn

func (col *Column) RemapColumn(m map[int64]*Column) (Expression, error)

RemapColumn remaps columns with provided mapping and returns new expression

func (*Column) Repertoire

func (col *Column) Repertoire() Repertoire

Repertoire returns the repertoire value which is used to check collations.

func (*Column) ResolveIndices

func (col *Column) ResolveIndices(schema *Schema) (Expression, error)

ResolveIndices implements Expression interface.

func (*Column) ResolveIndicesByVirtualExpr

func (col *Column) ResolveIndicesByVirtualExpr(ctx EvalContext, schema *Schema) (Expression, bool)

ResolveIndicesByVirtualExpr implements Expression interface.

func (*Column) SafeToShareAcrossSession

func (col *Column) SafeToShareAcrossSession() bool

SafeToShareAcrossSession returns if the function can be shared across different sessions.

func (*Column) SetCharsetAndCollation

func (c *Column) SetCharsetAndCollation(chs, coll string)

func (*Column) SetCoercibility

func (c *Column) SetCoercibility(val Coercibility)

SetCoercibility implements CollationInfo SetCoercibility interface.

func (*Column) SetExplicitCharset

func (c *Column) SetExplicitCharset(explicit bool)

func (*Column) SetRepertoire

func (c *Column) SetRepertoire(r Repertoire)

func (*Column) String

func (col *Column) String() string

String implements Stringer interface.

func (*Column) StringWithCtx

func (col *Column) StringWithCtx(_ ParamValues, redact string) string

StringWithCtx implements Expression interface.

func (*Column) ToInfo

func (col *Column) ToInfo() *model.ColumnInfo

ToInfo converts the expression.Column to model.ColumnInfo for casting values, beware it doesn't fill all the fields of the model.ColumnInfo.

func (*Column) Traverse

func (col *Column) Traverse(action TraverseAction) Expression

Traverse implements the TraverseDown interface.

func (*Column) VecEvalDecimal

func (col *Column) VecEvalDecimal(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalDecimal evaluates this expression in a vectorized manner.

func (*Column) VecEvalDuration

func (col *Column) VecEvalDuration(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalDuration evaluates this expression in a vectorized manner.

func (*Column) VecEvalInt

func (col *Column) VecEvalInt(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalInt evaluates this expression in a vectorized manner.

func (*Column) VecEvalJSON

func (col *Column) VecEvalJSON(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalJSON evaluates this expression in a vectorized manner.

func (*Column) VecEvalReal

func (col *Column) VecEvalReal(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalReal evaluates this expression in a vectorized manner.

func (*Column) VecEvalString

func (col *Column) VecEvalString(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalString evaluates this expression in a vectorized manner.

func (*Column) VecEvalTime

func (col *Column) VecEvalTime(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalTime evaluates this expression in a vectorized manner.

func (*Column) VecEvalVectorFloat32

func (col *Column) VecEvalVectorFloat32(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalVectorFloat32 evaluates this expression in a vectorized manner.

func (*Column) Vectorized

func (col *Column) Vectorized() bool

Vectorized returns if this expression supports vectorized evaluation.

type CompareFunc

type CompareFunc = func(sctx EvalContext, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row) (int64, bool, error)

CompareFunc defines the compare function prototype.

func GetCmpFunction

func GetCmpFunction(ctx BuildContext, lhs, rhs Expression) CompareFunc

GetCmpFunction get the compare function according to two arguments.

type ConstLevel

type ConstLevel uint

ConstLevel indicates the const level for an expression

const (
	// ConstNone indicates the expression is not a constant expression.
	// The evaluation result may be different for different input rows.
	// e.g. `col_a * 2`, `substring(col_b, 5, 3)`.
	ConstNone ConstLevel = iota
	// ConstOnlyInContext indicates the expression is only a constant for a same context.
	// This is mainly for Plan Cache, e.g. `prepare st from 'select * from t where a<1+?'`, where
	// the value of `?` may change between different Contexts (executions).
	ConstOnlyInContext
	// ConstStrict indicates the expression is a constant expression.
	// The evaluation result is always the same no matter the input context or rows.
	// e.g. `1 + 2`, `substring("TiDB SQL Tutorial", 5, 3) + 'abcde'`
	ConstStrict
)

type Constant

type Constant struct {
	Value   types.Datum
	RetType *types.FieldType `plan-cache-clone:"shallow"`
	// DeferredExpr holds deferred function in PlanCache cached plan.
	// it's only used to represent non-deterministic functions(see expression.DeferredFunctions)
	// in PlanCache cached plan, so let them can be evaluated until cached item be used.
	DeferredExpr Expression
	// ParamMarker holds param index inside sessionVars.PreparedParams.
	// It's only used to reference a user variable provided in the `EXECUTE` statement or `COM_EXECUTE` binary protocol.
	ParamMarker *ParamMarker
	// contains filtered or unexported fields
}

Constant stands for a constant value.

func DatumToConstant

func DatumToConstant(d types.Datum, tp byte, flag uint) *Constant

DatumToConstant generates a Constant expression from a Datum.

func NewInt64Const

func NewInt64Const(num int64) *Constant

NewInt64Const stands for constant of a given number.

func NewNull

func NewNull() *Constant

NewNull stands for null constant.

func NewNullWithFieldType

func NewNullWithFieldType(fieldType *types.FieldType) *Constant

NewNullWithFieldType stands for null constant with specified fieldType.

func NewOne

func NewOne() *Constant

NewOne stands for an unsigned number 1.

func NewSignedOne

func NewSignedOne() *Constant

NewSignedOne stands for a signed number 1.

func NewSignedZero

func NewSignedZero() *Constant

NewSignedZero stands for a signed number 0.

func NewStrConst

func NewStrConst(str string) *Constant

NewStrConst stands for constant of a given string. used in test only now.

func NewUInt64Const

func NewUInt64Const(num int) *Constant

NewUInt64Const stands for constant of a given number.

func NewUInt64ConstWithFieldType

func NewUInt64ConstWithFieldType(num uint64, fieldType *types.FieldType) *Constant

NewUInt64ConstWithFieldType stands for constant of a given number with specified fieldType.

func NewZero

func NewZero() *Constant

NewZero stands for an unsigned number 0.

func ParamMarkerExpression

func ParamMarkerExpression(ctx BuildContext, v *driver.ParamMarkerExpr, needParam bool) (*Constant, error)

ParamMarkerExpression generate a getparam function expression.

func RefineComparedConstant

func RefineComparedConstant(ctx BuildContext, targetFieldType types.FieldType, con *Constant, op opcode.Op) (_ *Constant, isExceptional bool)

RefineComparedConstant changes a non-integer constant argument to its ceiling or floor result by the given op. isExceptional indicates whether the 'int column cmp const' might be true/false. If isExceptional is true, ExceptionalVal is returned. Or, CorrectVal is returned. CorrectVal: The computed result. If the constant can be converted to int without exception, return the val. Else return 'con'(the input). ExceptionalVal : It is used to get more information to check whether 'int column cmp const' is true/false

If the op == LT,LE,GT,GE and it gets an Overflow when converting, return inf/-inf.
If the op == EQ,NullEQ and the constant can never be equal to the int column, return ‘con’(the input, a non-int constant).

func (*Constant) CanonicalHashCode

func (c *Constant) CanonicalHashCode() []byte

CanonicalHashCode implements Expression interface.

func (*Constant) CharsetAndCollation

func (c *Constant) CharsetAndCollation() (string, string)

func (*Constant) Clone

func (c *Constant) Clone() Expression

Clone implements Expression interface.

func (*Constant) Coercibility

func (c *Constant) Coercibility() Coercibility

Coercibility returns the coercibility value which is used to check collations.

func (*Constant) ConstLevel

func (c *Constant) ConstLevel() ConstLevel

ConstLevel returns the const level for the expression

func (*Constant) Decorrelate

func (c *Constant) Decorrelate(_ *Schema) Expression

Decorrelate implements Expression interface.

func (*Constant) Equal

func (c *Constant) Equal(ctx EvalContext, b Expression) bool

Equal implements Expression interface.

func (*Constant) Equals

func (c *Constant) Equals(other any) bool

Equals implements HashEquals.<1st> interface.

func (*Constant) Eval

func (c *Constant) Eval(ctx EvalContext, row chunk.Row) (types.Datum, error)

Eval implements Expression interface.

func (*Constant) EvalDecimal

func (c *Constant) EvalDecimal(ctx EvalContext, row chunk.Row) (*types.MyDecimal, bool, error)

EvalDecimal returns decimal representation of Constant.

func (*Constant) EvalDuration

func (c *Constant) EvalDuration(ctx EvalContext, row chunk.Row) (val types.Duration, isNull bool, err error)

EvalDuration returns Duration representation of Constant.

func (*Constant) EvalInt

func (c *Constant) EvalInt(ctx EvalContext, row chunk.Row) (int64, bool, error)

EvalInt returns int representation of Constant.

func (*Constant) EvalJSON

func (c *Constant) EvalJSON(ctx EvalContext, row chunk.Row) (types.BinaryJSON, bool, error)

EvalJSON returns JSON representation of Constant.

func (*Constant) EvalReal

func (c *Constant) EvalReal(ctx EvalContext, row chunk.Row) (float64, bool, error)

EvalReal returns real representation of Constant.

func (*Constant) EvalString

func (c *Constant) EvalString(ctx EvalContext, row chunk.Row) (string, bool, error)

EvalString returns string representation of Constant.

func (*Constant) EvalTime

func (c *Constant) EvalTime(ctx EvalContext, row chunk.Row) (val types.Time, isNull bool, err error)

EvalTime returns DATE/DATETIME/TIMESTAMP representation of Constant.

func (*Constant) EvalVectorFloat32

func (c *Constant) EvalVectorFloat32(ctx EvalContext, row chunk.Row) (types.VectorFloat32, bool, error)

EvalVectorFloat32 returns VectorFloat32 representation of Constant.

func (*Constant) ExplainInfo

func (expr *Constant) ExplainInfo(ctx EvalContext) string

ExplainInfo implements the Expression interface.

func (*Constant) ExplainNormalizedInfo

func (expr *Constant) ExplainNormalizedInfo() string

ExplainNormalizedInfo implements the Expression interface.

func (*Constant) ExplainNormalizedInfo4InList

func (expr *Constant) ExplainNormalizedInfo4InList() string

ExplainNormalizedInfo4InList implements the Expression interface.

func (*Constant) GetType

func (c *Constant) GetType(ctx EvalContext) *types.FieldType

GetType implements Expression interface.

func (*Constant) HasCoercibility

func (c *Constant) HasCoercibility() bool

func (*Constant) Hash64

func (c *Constant) Hash64(h base.Hasher)

Hash64 implements HashEquals.<0th> interface.

func (*Constant) HashCode

func (c *Constant) HashCode() []byte

HashCode implements Expression interface.

func (*Constant) IsCorrelated

func (c *Constant) IsCorrelated() bool

IsCorrelated implements Expression interface.

func (*Constant) IsExplicitCharset

func (c *Constant) IsExplicitCharset() bool

func (*Constant) MemoryUsage

func (c *Constant) MemoryUsage() (sum int64)

MemoryUsage return the memory usage of Constant

func (*Constant) RemapColumn

func (c *Constant) RemapColumn(_ map[int64]*Column) (Expression, error)

RemapColumn remaps columns with provided mapping and returns new expression

func (*Constant) Repertoire

func (c *Constant) Repertoire() Repertoire

func (*Constant) ResolveIndices

func (c *Constant) ResolveIndices(_ *Schema) (Expression, error)

ResolveIndices implements Expression interface.

func (*Constant) ResolveIndicesByVirtualExpr

func (c *Constant) ResolveIndicesByVirtualExpr(_ EvalContext, _ *Schema) (Expression, bool)

ResolveIndicesByVirtualExpr implements Expression interface.

func (*Constant) SafeToShareAcrossSession

func (c *Constant) SafeToShareAcrossSession() bool

SafeToShareAcrossSession returns if the function can be shared across different sessions.

func (*Constant) SetCharsetAndCollation

func (c *Constant) SetCharsetAndCollation(chs, coll string)

func (*Constant) SetCoercibility

func (c *Constant) SetCoercibility(val Coercibility)

SetCoercibility implements CollationInfo SetCoercibility interface.

func (*Constant) SetExplicitCharset

func (c *Constant) SetExplicitCharset(explicit bool)

func (*Constant) SetRepertoire

func (c *Constant) SetRepertoire(r Repertoire)

func (*Constant) StringWithCtx

func (c *Constant) StringWithCtx(ctx ParamValues, redact string) string

StringWithCtx implements Expression interface.

func (*Constant) Traverse

func (c *Constant) Traverse(action TraverseAction) Expression

Traverse implements the TraverseDown interface.

func (*Constant) VecEvalDecimal

func (c *Constant) VecEvalDecimal(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalDecimal evaluates this expression in a vectorized manner.

func (*Constant) VecEvalDuration

func (c *Constant) VecEvalDuration(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalDuration evaluates this expression in a vectorized manner.

func (*Constant) VecEvalInt

func (c *Constant) VecEvalInt(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalInt evaluates this expression in a vectorized manner.

func (*Constant) VecEvalJSON

func (c *Constant) VecEvalJSON(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalJSON evaluates this expression in a vectorized manner.

func (*Constant) VecEvalReal

func (c *Constant) VecEvalReal(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalReal evaluates this expression in a vectorized manner.

func (*Constant) VecEvalString

func (c *Constant) VecEvalString(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalString evaluates this expression in a vectorized manner.

func (*Constant) VecEvalTime

func (c *Constant) VecEvalTime(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalTime evaluates this expression in a vectorized manner.

func (*Constant) VecEvalVectorFloat32

func (c *Constant) VecEvalVectorFloat32(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalVectorFloat32 evaluates this expression in a vectorized manner.

func (*Constant) Vectorized

func (c *Constant) Vectorized() bool

Vectorized returns if this expression supports vectorized evaluation.

type CorrelatedColumn

type CorrelatedColumn struct {
	Column

	Data *types.Datum
}

CorrelatedColumn stands for a column in a correlated sub query.

func ExtractCorColumns

func ExtractCorColumns(expr Expression) (cols []*CorrelatedColumn)

ExtractCorColumns extracts correlated column from given expression.

func (*CorrelatedColumn) CharsetAndCollation

func (c *CorrelatedColumn) CharsetAndCollation() (string, string)

func (*CorrelatedColumn) Clone

func (col *CorrelatedColumn) Clone() Expression

Clone implements Expression interface.

func (*CorrelatedColumn) ConstLevel

func (col *CorrelatedColumn) ConstLevel() ConstLevel

ConstLevel returns the const level for the expression

func (*CorrelatedColumn) Decorrelate

func (col *CorrelatedColumn) Decorrelate(schema *Schema) Expression

Decorrelate implements Expression interface.

func (*CorrelatedColumn) Equal

func (col *CorrelatedColumn) Equal(_ EvalContext, expr Expression) bool

Equal implements Expression interface.

func (*CorrelatedColumn) EqualColumn

func (col *CorrelatedColumn) EqualColumn(expr Expression) bool

EqualColumn returns whether two column is equal

func (*CorrelatedColumn) Equals

func (col *CorrelatedColumn) Equals(other any) bool

Equals implements HashEquals.<1st> interface.

func (*CorrelatedColumn) Eval

func (col *CorrelatedColumn) Eval(_ EvalContext, _ chunk.Row) (types.Datum, error)

Eval implements Expression interface.

func (*CorrelatedColumn) EvalDecimal

func (col *CorrelatedColumn) EvalDecimal(ctx EvalContext, row chunk.Row) (*types.MyDecimal, bool, error)

EvalDecimal returns decimal representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalDuration

func (col *CorrelatedColumn) EvalDuration(ctx EvalContext, row chunk.Row) (types.Duration, bool, error)

EvalDuration returns Duration representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalInt

func (col *CorrelatedColumn) EvalInt(ctx EvalContext, row chunk.Row) (int64, bool, error)

EvalInt returns int representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalJSON

func (col *CorrelatedColumn) EvalJSON(ctx EvalContext, row chunk.Row) (types.BinaryJSON, bool, error)

EvalJSON returns JSON representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalReal

func (col *CorrelatedColumn) EvalReal(ctx EvalContext, row chunk.Row) (float64, bool, error)

EvalReal returns real representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalString

func (col *CorrelatedColumn) EvalString(ctx EvalContext, row chunk.Row) (string, bool, error)

EvalString returns string representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalTime

func (col *CorrelatedColumn) EvalTime(ctx EvalContext, row chunk.Row) (types.Time, bool, error)

EvalTime returns DATE/DATETIME/TIMESTAMP representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalVectorFloat32

func (col *CorrelatedColumn) EvalVectorFloat32(ctx EvalContext, row chunk.Row) (types.VectorFloat32, bool, error)

EvalVectorFloat32 returns VectorFloat32 representation of CorrelatedColumn.

func (*CorrelatedColumn) HasCoercibility

func (c *CorrelatedColumn) HasCoercibility() bool

func (*CorrelatedColumn) Hash64

func (col *CorrelatedColumn) Hash64(h base.Hasher)

Hash64 implements HashEquals.<0th> interface.

func (*CorrelatedColumn) IsCorrelated

func (col *CorrelatedColumn) IsCorrelated() bool

IsCorrelated implements Expression interface.

func (*CorrelatedColumn) IsExplicitCharset

func (c *CorrelatedColumn) IsExplicitCharset() bool

func (*CorrelatedColumn) MemoryUsage

func (col *CorrelatedColumn) MemoryUsage() (sum int64)

MemoryUsage return the memory usage of CorrelatedColumn

func (*CorrelatedColumn) RemapColumn

func (col *CorrelatedColumn) RemapColumn(m map[int64]*Column) (Expression, error)

RemapColumn remaps columns with provided mapping and returns new expression

func (*CorrelatedColumn) ResolveIndices

func (col *CorrelatedColumn) ResolveIndices(_ *Schema) (Expression, error)

ResolveIndices implements Expression interface.

func (*CorrelatedColumn) ResolveIndicesByVirtualExpr

func (col *CorrelatedColumn) ResolveIndicesByVirtualExpr(_ EvalContext, _ *Schema) (Expression, bool)

ResolveIndicesByVirtualExpr implements Expression interface.

func (*CorrelatedColumn) SafeToShareAcrossSession

func (col *CorrelatedColumn) SafeToShareAcrossSession() bool

SafeToShareAcrossSession returns if the function can be shared across different sessions.

func (*CorrelatedColumn) SetCharsetAndCollation

func (c *CorrelatedColumn) SetCharsetAndCollation(chs, coll string)

func (*CorrelatedColumn) SetCoercibility

func (c *CorrelatedColumn) SetCoercibility(val Coercibility)

SetCoercibility implements CollationInfo SetCoercibility interface.

func (*CorrelatedColumn) SetExplicitCharset

func (c *CorrelatedColumn) SetExplicitCharset(explicit bool)

func (*CorrelatedColumn) SetRepertoire

func (c *CorrelatedColumn) SetRepertoire(r Repertoire)

func (*CorrelatedColumn) Traverse

func (col *CorrelatedColumn) Traverse(action TraverseAction) Expression

Traverse implements the TraverseDown interface.

func (*CorrelatedColumn) VecEvalDecimal

func (col *CorrelatedColumn) VecEvalDecimal(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalDecimal evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalDuration

func (col *CorrelatedColumn) VecEvalDuration(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalDuration evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalInt

func (col *CorrelatedColumn) VecEvalInt(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalInt evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalJSON

func (col *CorrelatedColumn) VecEvalJSON(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalJSON evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalReal

func (col *CorrelatedColumn) VecEvalReal(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalReal evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalString

func (col *CorrelatedColumn) VecEvalString(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalString evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalTime

func (col *CorrelatedColumn) VecEvalTime(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalTime evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalVectorFloat32

func (col *CorrelatedColumn) VecEvalVectorFloat32(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalVectorFloat32 evaluates this expression in a vectorized manner.

type EvalContext

type EvalContext = exprctx.EvalContext

EvalContext is used to evaluate an expression

type EvaluatorSuite

type EvaluatorSuite struct {
	ColumnSwapHelper *chunk.ColumnSwapHelper // Evaluator for column expressions.
	// contains filtered or unexported fields
}

EvaluatorSuite is responsible for the evaluation of a list of expressions. It separates them to "column" and "other" expressions and evaluates "other" expressions before "column" expressions.

func NewEvaluatorSuite

func NewEvaluatorSuite(exprs []Expression, avoidColumnEvaluator bool) *EvaluatorSuite

NewEvaluatorSuite creates an EvaluatorSuite to evaluate all the exprs. avoidColumnEvaluator can be removed after column pool is supported.

func (*EvaluatorSuite) RequiredOptionalEvalProps

func (e *EvaluatorSuite) RequiredOptionalEvalProps() exprctx.OptionalEvalPropKeySet

RequiredOptionalEvalProps exposes all optional evaluation properties that this evaluator requires.

func (*EvaluatorSuite) Run

func (e *EvaluatorSuite) Run(ctx EvalContext, vecEnabled bool, input, output *chunk.Chunk) error

Run evaluates all the expressions hold by this EvaluatorSuite. NOTE: "defaultEvaluator" must be evaluated before "columnEvaluator".

func (*EvaluatorSuite) Vectorizable

func (e *EvaluatorSuite) Vectorizable() bool

Vectorizable checks whether this EvaluatorSuite can use vectorizd execution mode.

type ExprCollation

type ExprCollation struct {
	Coer      Coercibility
	Repe      Repertoire
	Charset   string
	Collation string
}

ExprCollation is a struct that store the collation related information.

func CheckAndDeriveCollationFromExprs

func CheckAndDeriveCollationFromExprs(ctx BuildContext, funcName string, evalType types.EvalType, args ...Expression) (et *ExprCollation, err error)

CheckAndDeriveCollationFromExprs derives collation information from these expressions, return error if derives collation error.

type Expression

type Expression interface {
	VecExpr
	CollationInfo
	base.HashEquals
	SafeToShareAcrossSession

	Traverse(TraverseAction) Expression

	// Eval evaluates an expression through a row.
	Eval(ctx EvalContext, row chunk.Row) (types.Datum, error)

	// EvalInt returns the int64 representation of expression.
	EvalInt(ctx EvalContext, row chunk.Row) (val int64, isNull bool, err error)

	// EvalReal returns the float64 representation of expression.
	EvalReal(ctx EvalContext, row chunk.Row) (val float64, isNull bool, err error)

	// EvalString returns the string representation of expression.
	EvalString(ctx EvalContext, row chunk.Row) (val string, isNull bool, err error)

	// EvalDecimal returns the decimal representation of expression.
	EvalDecimal(ctx EvalContext, row chunk.Row) (val *types.MyDecimal, isNull bool, err error)

	// EvalTime returns the DATE/DATETIME/TIMESTAMP representation of expression.
	EvalTime(ctx EvalContext, row chunk.Row) (val types.Time, isNull bool, err error)

	// EvalDuration returns the duration representation of expression.
	EvalDuration(ctx EvalContext, row chunk.Row) (val types.Duration, isNull bool, err error)

	// EvalJSON returns the JSON representation of expression.
	EvalJSON(ctx EvalContext, row chunk.Row) (val types.BinaryJSON, isNull bool, err error)

	// EvalVectorFloat32 returns the VectorFloat32 representation of expression.
	EvalVectorFloat32(ctx EvalContext, row chunk.Row) (val types.VectorFloat32, isNull bool, err error)

	// GetType gets the type that the expression returns.
	GetType(ctx EvalContext) *types.FieldType

	// Clone copies an expression totally.
	Clone() Expression

	// Equal checks whether two expressions are equal.
	Equal(ctx EvalContext, e Expression) bool

	// IsCorrelated checks if this expression has correlated key.
	IsCorrelated() bool

	// ConstLevel returns the const level of the expression.
	ConstLevel() ConstLevel

	// Decorrelate try to decorrelate the expression by schema.
	Decorrelate(schema *Schema) Expression

	// ResolveIndices resolves indices by the given schema. It will copy the original expression and return the copied one.
	ResolveIndices(schema *Schema) (Expression, error)

	// ResolveIndicesByVirtualExpr resolves indices by the given schema in terms of virtual expression. It will copy the original expression and return the copied one.
	ResolveIndicesByVirtualExpr(ctx EvalContext, schema *Schema) (Expression, bool)

	// RemapColumn remaps columns with provided mapping and returns new expression
	RemapColumn(map[int64]*Column) (Expression, error)

	// ExplainInfo returns operator information to be explained.
	ExplainInfo(ctx EvalContext) string

	// ExplainNormalizedInfo returns operator normalized information for generating digest.
	ExplainNormalizedInfo() string

	// ExplainNormalizedInfo4InList returns operator normalized information for plan digest.
	ExplainNormalizedInfo4InList() string

	// HashCode creates the hashcode for expression which can be used to identify itself from other expression.
	// It generated as the following:
	// Constant: ConstantFlag+encoded value
	// Column: ColumnFlag+encoded value
	// ScalarFunction: SFFlag+encoded function name + encoded arg_1 + encoded arg_2 + ...
	HashCode() []byte

	// CanonicalHashCode creates the canonical hashcode for expression.
	// Different with `HashCode`, this method will produce the same hashcode for expressions with the same semantic.
	// For example, `a + b` and `b + a` have the same return value of this method.
	CanonicalHashCode() []byte

	// MemoryUsage return the memory usage of Expression
	MemoryUsage() int64

	StringerWithCtx
	// contains filtered or unexported methods
}

Expression represents all scalar expression in SQL.

func Args2Expressions4Test

func Args2Expressions4Test(args ...any) []Expression

Args2Expressions4Test converts these values to an expression list. This conversion is incomplete, so only use for test.

func BuildCastCollationFunction

func BuildCastCollationFunction(ctx BuildContext, expr Expression, ec *ExprCollation, enumOrSetRealTypeIsStr bool) Expression

BuildCastCollationFunction builds a ScalarFunction which casts the collation.

func BuildCastFunction

func BuildCastFunction(ctx BuildContext, expr Expression, tp *types.FieldType) (res Expression)

BuildCastFunction builds a CAST ScalarFunction from the Expression.

func BuildCastFunction4Union

func BuildCastFunction4Union(ctx BuildContext, expr Expression, tp *types.FieldType) (res Expression)

BuildCastFunction4Union build a implicitly CAST ScalarFunction from the Union Expression.

func BuildCastFunctionWithCheck

func BuildCastFunctionWithCheck(ctx BuildContext, expr Expression, tp *types.FieldType, inUnion bool, isExplicitCharset bool) (res Expression, err error)

BuildCastFunctionWithCheck builds a CAST ScalarFunction from the Expression and return error if any.

func BuildFromBinaryFunction

func BuildFromBinaryFunction(ctx BuildContext, expr Expression, tp *types.FieldType, cannotConvertStringAsWarning bool) (res Expression)

BuildFromBinaryFunction builds from_binary function.

func BuildGetVarFunction

func BuildGetVarFunction(ctx BuildContext, expr Expression, retType *types.FieldType) (Expression, error)

BuildGetVarFunction builds a GetVar ScalarFunction from the Expression.

func BuildNotNullExpr

func BuildNotNullExpr(ctx BuildContext, expr Expression) Expression

BuildNotNullExpr wraps up `not(isnull())` for given expression.

func BuildToBinaryFunction

func BuildToBinaryFunction(ctx BuildContext, expr Expression) (res Expression)

BuildToBinaryFunction builds to_binary function.

func Column2Exprs

func Column2Exprs(cols []*Column) []Expression

Column2Exprs will transfer column slice to expression slice.

func ColumnSubstitute

func ColumnSubstitute(ctx BuildContext, expr Expression, schema *Schema, newExprs []Expression) Expression

ColumnSubstitute substitutes the columns in filter to expressions in select fields. e.g. select * from (select b as a from t) k where a < 10 => select * from (select b as a from t where b < 10) k. TODO: remove this function and only use ColumnSubstituteImpl since this function swallows the error, which seems unsafe.

func ColumnSubstituteAll

func ColumnSubstituteAll(ctx BuildContext, expr Expression, schema *Schema, newExprs []Expression) (bool, Expression)

ColumnSubstituteAll substitutes the columns just like ColumnSubstitute, but we don't accept partial substitution. Only accept:

1: substitute them all once find col in schema.
2: nothing in expr can be substituted.

func ColumnSubstituteImpl

func ColumnSubstituteImpl(ctx BuildContext, expr Expression, schema *Schema, newExprs []Expression, fail1Return bool) (bool, bool, Expression)

ColumnSubstituteImpl tries to substitute column expr using newExprs, the newFunctionInternal is only called if its child is substituted @return bool means whether the expr has changed. @return bool means whether the expr should change (has the dependency in schema, while the corresponding expr has some compatibility), but finally fallback. @return Expression, the original expr or the changed expr, it depends on the first @return bool.

func ComposeCNFCondition

func ComposeCNFCondition(ctx BuildContext, conditions ...Expression) Expression

ComposeCNFCondition composes CNF items into a balance deep CNF tree, which benefits a lot for pb decoder/encoder.

func ComposeDNFCondition

func ComposeDNFCondition(ctx BuildContext, conditions ...Expression) Expression

ComposeDNFCondition composes DNF items into a balance deep DNF tree.

func DeduplicateGbyExpression

func DeduplicateGbyExpression(exprs []Expression) ([]Expression, []int)

DeduplicateGbyExpression is try to detect the semantic equivalence expression, and mark them into same position. eg: group by a+b, b+a, b with rollup. the 1st and 2nd expression is semantically equivalent, so we only need to keep the distinct expression: [a+b, b] down, and output another position slice out, the [0, 0, 1] for the case above.

func DeriveRelaxedFiltersFromDNF

func DeriveRelaxedFiltersFromDNF(ctx BuildContext, expr Expression, schema *Schema) Expression

DeriveRelaxedFiltersFromDNF given a DNF expression, derive a relaxed DNF expression which only contains columns in specified schema; the derived expression is a superset of original expression, i.e, any tuple satisfying the original expression must satisfy the derived expression. Return nil when the derived expression is universal set. A running example is: for schema of t1, `(t1.a=1 and t2.a=1) or (t1.a=2 and t2.a=2)` would be derived as `t1.a=1 or t1.a=2`, while `t1.a=1 or t2.a=1` would get nil.

func EliminateNoPrecisionLossCast

func EliminateNoPrecisionLossCast(sctx BuildContext, expr Expression) Expression

EliminateNoPrecisionLossCast remove the redundant cast function for range build convenience. 1: deeper cast embedded in other complicated function will not be considered. 2: cast args should be one for original base column and one for constant. 3: some collation compatibility and precision loss will be considered when remove this cast func.

func EvaluateExprWithNull

func EvaluateExprWithNull(ctx BuildContext, schema *Schema, expr Expression) (Expression, error)

EvaluateExprWithNull sets columns in schema as null and calculate the final result of the scalar function. If the Expression is a non-constant value, it means the result is unknown.

func ExecBinaryParam

func ExecBinaryParam(typectx types.Context, binaryParams []param.BinaryParam) (params []Expression, err error)

ExecBinaryParam parse execute binary param arguments to datum slice.

func ExtractConstantEqColumnsOrScalar

func ExtractConstantEqColumnsOrScalar(ctx BuildContext, result []Expression, exprs []Expression) []Expression

ExtractConstantEqColumnsOrScalar detects the constant equal relationship from CNF exprs.

func ExtractFiltersFromDNFs

func ExtractFiltersFromDNFs(ctx BuildContext, conditions []Expression) []Expression

ExtractFiltersFromDNFs checks whether the cond is DNF. If so, it will get the extracted part and the remained part. The original DNF will be replaced by the remained part or just be deleted if remained part is nil. And the extracted part will be appended to the end of the original slice.

func Filter

func Filter(result []Expression, input []Expression, filter func(Expression) bool) []Expression

Filter the input expressions, append the results to result.

func FilterOutInPlace

func FilterOutInPlace(input []Expression, filter func(Expression) bool) (remained, filteredOut []Expression)

FilterOutInPlace do the filtering out in place. The remained are the ones who doesn't match the filter, storing in the original slice. The filteredOut are the ones match the filter, storing in a new slice.

func FlattenCNFConditions

func FlattenCNFConditions(CNFCondition *ScalarFunction) []Expression

FlattenCNFConditions extracts CNF expression's leaf item. e.g. and(and(a>1, a>2), and(a>3, a>4)), we'll get [a>1, a>2, a>3, a>4].

func FlattenDNFConditions

func FlattenDNFConditions(DNFCondition *ScalarFunction) []Expression

FlattenDNFConditions extracts DNF expression's leaf item. e.g. or(or(a=1, a=2), or(a=3, a=4)), we'll get [a=1, a=2, a=3, a=4].

func FoldConstant

func FoldConstant(ctx BuildContext, expr Expression) Expression

FoldConstant does constant folding optimization on an expression excluding deferred ones.

func GetExprInsideIsTruth

func GetExprInsideIsTruth(expr Expression) Expression

GetExprInsideIsTruth get the expression inside the `istrue_with_null` and `istrue`. This is useful when handling expressions from "not" or "!", because we might wrap `istrue_with_null` or `istrue` when handling them. See pushNotAcrossExpr() and wrapWithIsTrue() for details.

func GetFuncArg

func GetFuncArg(e Expression, idx int) Expression

GetFuncArg gets the argument of the function at idx.

func HandleBinaryLiteral

func HandleBinaryLiteral(ctx BuildContext, expr Expression, ec *ExprCollation, funcName string, explicitCast bool) Expression

HandleBinaryLiteral wraps `expr` with to_binary or from_binary sig.

func NewFunction

func NewFunction(ctx BuildContext, funcName string, retType *types.FieldType, args ...Expression) (Expression, error)

NewFunction creates a new scalar function or constant via a constant folding.

func NewFunctionBase

func NewFunctionBase(ctx BuildContext, funcName string, retType *types.FieldType, args ...Expression) (Expression, error)

NewFunctionBase creates a new scalar function with no constant folding.

func NewFunctionInternal

func NewFunctionInternal(ctx BuildContext, funcName string, retType *types.FieldType, args ...Expression) Expression

NewFunctionInternal is similar to NewFunction, but do not return error, should only be used internally. Deprecated: use NewFunction instead, old logic here is for the convenience of go linter error check. while for the new function creation, some errors can also be thrown out, for example, args verification error, collation derivation error, special function with meta doesn't be initialized error and so on. only threw the these internal error out, then we can debug and dig it out quickly rather than in a confusion of index out of range / nil pointer error / function execution error.

func NewFunctionTryFold

func NewFunctionTryFold(ctx BuildContext, funcName string, retType *types.FieldType, args ...Expression) (Expression, error)

NewFunctionTryFold creates a new scalar function with trying constant folding.

func NewFunctionWithInit

func NewFunctionWithInit(ctx BuildContext, funcName string, retType *types.FieldType, init ScalarFunctionCallBack, args ...Expression) (Expression, error)

NewFunctionWithInit creates a new scalar function with callback init function.

func PBToExpr

func PBToExpr(ctx BuildContext, expr *tipb.Expr, tps []*types.FieldType) (Expression, error)

PBToExpr converts pb structure to expression.

func PBToExprs

func PBToExprs(ctx BuildContext, pbExprs []*tipb.Expr, fieldTps []*types.FieldType) ([]Expression, error)

PBToExprs converts pb structures to expressions.

func ParseSimpleExpr

func ParseSimpleExpr(ctx BuildContext, exprStr string, opts ...BuildOption) (Expression, error)

ParseSimpleExpr parses simple expression string to Expression. The expression string must only reference the column in table Info.

func ParseSimpleExprWithTableInfo

func ParseSimpleExprWithTableInfo(ctx BuildContext, exprStr string, tableInfo *model.TableInfo) (Expression, error)

ParseSimpleExprWithTableInfo now is only used by some external repo like tiflow to make sure they are not break. Deprecated: please use ParseSimpleExpr instead.

func PopRowFirstArg

func PopRowFirstArg(ctx BuildContext, e Expression) (ret Expression, err error)

PopRowFirstArg pops the first element and returns the rest of row. e.g. After this function (1, 2, 3) becomes (2, 3).

func PropagateConstant

func PropagateConstant(ctx exprctx.ExprContext, conditions []Expression) []Expression

PropagateConstant propagate constant values of deterministic predicates in a condition. This is a constant propagation logic for expression list such as ['a=1', 'a=b']

func PushDownNot

func PushDownNot(ctx BuildContext, expr Expression) Expression

PushDownNot pushes the `not` function down to the expression's arguments.

func RemoveDupExprs

func RemoveDupExprs(exprs []Expression) []Expression

RemoveDupExprs removes identical exprs. Not that if expr contains functions which are mutable or have side effects, we cannot remove it even if it has duplicates; if the plan is going to be cached, we cannot remove expressions containing `?` neither.

func RestoreGbyExpression

func RestoreGbyExpression(exprs []*Column, idxes []int) []Expression

RestoreGbyExpression restore the new gby expression according to recorded idxes reference.

func ScalarFuncs2Exprs

func ScalarFuncs2Exprs(funcs []*ScalarFunction) []Expression

ScalarFuncs2Exprs converts []*ScalarFunction to []Expression.

func SetExprColumnInOperand

func SetExprColumnInOperand(expr Expression) Expression

SetExprColumnInOperand is used to set columns in expr as InOperand.

func SplitCNFItems

func SplitCNFItems(onExpr Expression) []Expression

SplitCNFItems splits CNF items. CNF means conjunctive normal form, e.g. "a and b and c".

func SplitDNFItems

func SplitDNFItems(onExpr Expression) []Expression

SplitDNFItems splits DNF items. DNF means disjunctive normal form, e.g. "a or b or c".

func SubstituteCorCol2Constant

func SubstituteCorCol2Constant(ctx BuildContext, expr Expression) (Expression, error)

SubstituteCorCol2Constant will substitute correlated column to constant value which it contains. If the args of one scalar function are all constant, we will substitute it to constant.

func TryPushCastIntoControlFunctionForHybridType

func TryPushCastIntoControlFunctionForHybridType(ctx BuildContext, expr Expression, tp *types.FieldType) (res Expression)

TryPushCastIntoControlFunctionForHybridType try to push cast into control function for Hybrid Type. If necessary, it will rebuild control function using changed args. When a hybrid type is the output of a control function, the result may be as a numeric type to subsequent calculation We should perform the `Cast` operation early to avoid using the wrong type for calculation For example, the condition `if(1, e, 'a') = 1`, `if` function will output `e` and compare with `1`. If the evaltype is ETString, it will get wrong result. So we can rewrite the condition to `IfInt(1, cast(e as int), cast('a' as int)) = 1` to get the correct result.

func WrapWithCastAsDecimal

func WrapWithCastAsDecimal(ctx BuildContext, expr Expression) Expression

WrapWithCastAsDecimal wraps `expr` with `cast` if the return type of expr is not type decimal, otherwise, returns `expr` directly.

func WrapWithCastAsDuration

func WrapWithCastAsDuration(ctx BuildContext, expr Expression) Expression

WrapWithCastAsDuration wraps `expr` with `cast` if the return type of expr is not type duration, otherwise, returns `expr` directly.

func WrapWithCastAsInt

func WrapWithCastAsInt(ctx BuildContext, expr Expression) Expression

WrapWithCastAsInt wraps `expr` with `cast` if the return type of expr is not type int, otherwise, returns `expr` directly.

func WrapWithCastAsJSON

func WrapWithCastAsJSON(ctx BuildContext, expr Expression) Expression

WrapWithCastAsJSON wraps `expr` with `cast` if the return type of expr is not type json, otherwise, returns `expr` directly.

func WrapWithCastAsReal

func WrapWithCastAsReal(ctx BuildContext, expr Expression) Expression

WrapWithCastAsReal wraps `expr` with `cast` if the return type of expr is not type real, otherwise, returns `expr` directly.

func WrapWithCastAsString

func WrapWithCastAsString(ctx BuildContext, expr Expression) Expression

WrapWithCastAsString wraps `expr` with `cast` if the return type of expr is not type string, otherwise, returns `expr` directly.

func WrapWithCastAsTime

func WrapWithCastAsTime(ctx BuildContext, expr Expression, tp *types.FieldType) Expression

WrapWithCastAsTime wraps `expr` with `cast` if the return type of expr is not same as type of the specified `tp` , otherwise, returns `expr` directly.

func WrapWithCastAsVectorFloat32

func WrapWithCastAsVectorFloat32(ctx BuildContext, expr Expression) Expression

WrapWithCastAsVectorFloat32 wraps `expr` with `cast` if the return type of expr is not type VectorFloat32, otherwise, returns `expr` directly.

type GLCmpStringMode

type GLCmpStringMode uint8

GLCmpStringMode represents Greatest/Least integral string comparison mode

const (
	// GLCmpStringDirectly Greatest and Least function compares string directly
	GLCmpStringDirectly GLCmpStringMode = iota
	// GLCmpStringAsDate Greatest/Least function compares string as 'yyyy-mm-dd' format
	GLCmpStringAsDate
	// GLCmpStringAsDatetime Greatest/Least function compares string as 'yyyy-mm-dd hh:mm:ss' format
	GLCmpStringAsDatetime
)

type GLRetTimeType

type GLRetTimeType uint8

GLRetTimeType represents Greatest/Least return time type

const (
	// GLRetNoneTemporal Greatest/Least function returns non temporal time
	GLRetNoneTemporal GLRetTimeType = iota
	// GLRetDate Greatest/Least function returns date type, 'yyyy-mm-dd'
	GLRetDate
	// GLRetDatetime Greatest/Least function returns datetime type, 'yyyy-mm-dd hh:mm:ss'
	GLRetDatetime
)

type GroupingExprs

type GroupingExprs []Expression

GroupingExprs indicates one grouping-expressions inside a grouping set.

func (GroupingExprs) Clone

func (g GroupingExprs) Clone() GroupingExprs

Clone is used to clone a copy of current grouping expressions.

func (GroupingExprs) IDSet

func (g GroupingExprs) IDSet() *intset.FastIntSet

IDSet is used to collect column ids inside grouping expressions into a fast int set.

func (GroupingExprs) IsEmpty

func (g GroupingExprs) IsEmpty() bool

IsEmpty indicates whether current grouping expressions are empty.

func (GroupingExprs) MemoryUsage

func (g GroupingExprs) MemoryUsage() int64

MemoryUsage is used to output current memory usage by current grouping expressions.

func (GroupingExprs) StringWithCtx

func (g GroupingExprs) StringWithCtx(ctx ParamValues, redact string) string

StringWithCtx is used to output a string which simply described current grouping expressions.

func (GroupingExprs) SubSetOf

func (g GroupingExprs) SubSetOf(other GroupingExprs) bool

SubSetOf is used to do the logical computation of subset between two grouping expressions.

type GroupingSet

type GroupingSet []GroupingExprs

GroupingSet indicates one grouping set definition.

func (GroupingSet) AllColIDs

func (gs GroupingSet) AllColIDs() *intset.FastIntSet

AllColIDs collect all the grouping col's uniqueID. (here assuming that all the grouping expressions are single col)

func (GroupingSet) Clone

func (gs GroupingSet) Clone() GroupingSet

Clone is used to clone a copy of current grouping set.

func (GroupingSet) ExtractCols

func (gs GroupingSet) ExtractCols() []*Column

ExtractCols is used to extract basic columns from one grouping set.

func (GroupingSet) IsEmpty

func (gs GroupingSet) IsEmpty() bool

IsEmpty indicates whether current grouping set is empty.

func (GroupingSet) MemoryUsage

func (gs GroupingSet) MemoryUsage() int64

MemoryUsage is used to output current memory usage by current grouping set.

func (GroupingSet) StringWithCtx

func (gs GroupingSet) StringWithCtx(ctx ParamValues, redact string) string

StringWithCtx is used to output a string which simply described current grouping set.

func (GroupingSet) ToPB

func (gs GroupingSet) ToPB(ctx EvalContext, client kv.Client) (*tipb.GroupingSet, error)

ToPB is used to convert current grouping set to pb constructor.

type GroupingSets

type GroupingSets []GroupingSet

GroupingSets indicates the grouping sets definition.

func NewGroupingSets

func NewGroupingSets(groupCols []Expression) GroupingSets

NewGroupingSets new a grouping sets from a slice of expression.

func RollupGroupingSets

func RollupGroupingSets(rollupExprs []Expression) GroupingSets

RollupGroupingSets roll up the given expressions, and iterate out a slice of grouping set expressions.

func (GroupingSets) AllSetsColIDs

func (gss GroupingSets) AllSetsColIDs() *intset.FastIntSet

AllSetsColIDs is used to collect all the column id inside into a fast int set.

func (GroupingSets) DistinctSize

func (gss GroupingSets) DistinctSize() (int, []uint64, map[int]map[uint64]struct{})

DistinctSize judge whether there exist duplicate grouping set and output the distinct grouping set size. for example: grouping set{a, a, b}, and grouping set{a, b}, they actually group on the same thing --- (a,b) we can tell that from its unique id set equation. Note: group item here must be a column at instant.

func (GroupingSets) DistinctSizeWithThreshold

func (gss GroupingSets) DistinctSizeWithThreshold(N int) (int, []uint64, map[int]map[uint64]struct{})

DistinctSizeWithThreshold is exported for test with smaller injected N rather constructing a large grouping sets.

func (GroupingSets) IsEmpty

func (gss GroupingSets) IsEmpty() bool

IsEmpty indicates whether current grouping sets is empty.

func (GroupingSets) Merge

func (gss GroupingSets) Merge() GroupingSets

Merge function will explore the internal grouping expressions and try to find the minimum grouping sets. (prefix merging)

func (GroupingSets) MergeOne

func (gss GroupingSets) MergeOne(targetOne GroupingExprs) GroupingSets

MergeOne is used to merge one grouping expressions into current grouping sets.

func (GroupingSets) NeedCloneColumn

func (gss GroupingSets) NeedCloneColumn() bool

NeedCloneColumn indicate whether we need to copy column to when expanding datasource.

func (GroupingSets) StringWithCtx

func (gss GroupingSets) StringWithCtx(ctx ParamValues, redact string) string

StringWithCtx is used to output a string which simply described current grouping sets.

func (GroupingSets) TargetOne

func (gss GroupingSets) TargetOne(normalAggArgs []Expression) int

TargetOne is used to find a valid group layout for normal agg, note that: the args in normal agg are not necessary to be column.

func (GroupingSets) ToPB

func (gss GroupingSets) ToPB(ctx EvalContext, client kv.Client) ([]*tipb.GroupingSet, error)

ToPB is used to convert current grouping sets to pb constructor.

type Instruction

type Instruction struct {
	// If not negative, perform substitution of n-th subpattern from the regexp match.
	SubstitutionNum int

	// Otherwise, paste this literal string verbatim.
	Literal []byte
}

Instruction contains content that used to replace the origin string

type KeyInfo

type KeyInfo []*Column

KeyInfo stores the columns of one unique key or primary key.

func (KeyInfo) Clone

func (ki KeyInfo) Clone() KeyInfo

Clone copies the entire UniqueKey.

func (KeyInfo) String

func (ki KeyInfo) String() string

String implements fmt.Stringer interface.

type OptionalEvalPropDesc

type OptionalEvalPropDesc = exprctx.OptionalEvalPropDesc

OptionalEvalPropDesc is an alias of context.OptionalEvalPropDesc

type OptionalEvalPropKey

type OptionalEvalPropKey = exprctx.OptionalEvalPropKey

OptionalEvalPropKey is an alias of context.OptionalEvalPropKey

type OptionalEvalPropKeySet

type OptionalEvalPropKeySet = exprctx.OptionalEvalPropKeySet

OptionalEvalPropKeySet is an alias of context.OptionalEvalPropKeySet

type OptionalEvalPropProvider

type OptionalEvalPropProvider = exprctx.OptionalEvalPropProvider

OptionalEvalPropProvider is an alias of context.OptionalEvalPropProvider

type ParamMarker

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

ParamMarker indicates param provided by COM_STMT_EXECUTE.

func (*ParamMarker) GetUserVar

func (d *ParamMarker) GetUserVar(ctx ParamValues) (types.Datum, error)

GetUserVar returns the corresponding user variable presented in the `EXECUTE` statement or `COM_EXECUTE` command.

type ParamMarkerInPrepareChecker

type ParamMarkerInPrepareChecker struct {
	InPrepareStmt bool
}

ParamMarkerInPrepareChecker checks whether the given ast tree has paramMarker and is in prepare statement.

func (*ParamMarkerInPrepareChecker) Enter

func (pc *ParamMarkerInPrepareChecker) Enter(in ast.Node) (out ast.Node, skipChildren bool)

Enter implements Visitor Interface.

func (*ParamMarkerInPrepareChecker) Leave

func (pc *ParamMarkerInPrepareChecker) Leave(in ast.Node) (out ast.Node, ok bool)

Leave implements Visitor Interface.

type ParamValues

type ParamValues = exprctx.ParamValues

ParamValues is used to store the values of params in context

type PbConverter

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

PbConverter supplies methods to convert TiDB expressions to TiPB.

func NewPBConverter

func NewPBConverter(client kv.Client, ctx EvalContext) PbConverter

NewPBConverter creates a PbConverter.

func (PbConverter) ExprToPB

func (pc PbConverter) ExprToPB(expr Expression) *tipb.Expr

ExprToPB converts Expression to TiPB.

type PropagateConstantSolver

type PropagateConstantSolver interface {
	PropagateConstant(ctx exprctx.ExprContext, conditions []Expression) []Expression
}

PropagateConstantSolver is a constant propagate solver.

type PushDownContext

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

PushDownContext is the context used for push down expressions

func NewPushDownContext

func NewPushDownContext(evalCtx EvalContext, client kv.Client, inExplainStmt bool,
	warnHandler contextutil.WarnAppender, extraWarnHandler contextutil.WarnAppender, groupConcatMaxLen uint64) PushDownContext

NewPushDownContext returns a new PushDownContext

func NewPushDownContextFromSessionVars

func NewPushDownContextFromSessionVars(evalCtx EvalContext, sessVars *variable.SessionVars, client kv.Client) PushDownContext

NewPushDownContextFromSessionVars builds a new PushDownContext from session vars.

func (PushDownContext) AppendWarning

func (ctx PushDownContext) AppendWarning(err error)

AppendWarning appends a warning to be handled by the internal handler

func (PushDownContext) Client

func (ctx PushDownContext) Client() kv.Client

Client returns the kv client

func (PushDownContext) EvalCtx

func (ctx PushDownContext) EvalCtx() EvalContext

EvalCtx returns the eval context

func (PushDownContext) GetGroupConcatMaxLen

func (ctx PushDownContext) GetGroupConcatMaxLen() uint64

GetGroupConcatMaxLen returns the max length of group_concat

func (PushDownContext) PbConverter

func (ctx PushDownContext) PbConverter() PbConverter

PbConverter returns a new PbConverter

type Repertoire

type Repertoire int

The Repertoire of a character set is the collection of characters in the set. See https://dev.mysql.com/doc/refman/8.0/en/charset-repertoire.html. Only String expression has Repertoire, for non-string expression, it does not matter what the value it is.

type SQLDigestTextRetriever

type SQLDigestTextRetriever struct {
	// SQLDigestsMap is the place to put the digests that's requested for getting SQL text and also the place to put
	// the query result.
	SQLDigestsMap map[string]string
	// contains filtered or unexported fields
}

SQLDigestTextRetriever is used to find the normalized SQL statement text by SQL digests in statements_summary table. It's exported for test purposes. It's used by the `tidb_decode_sql_digests` builtin function, but also exposed to be used in other modules.

func NewSQLDigestTextRetriever

func NewSQLDigestTextRetriever() *SQLDigestTextRetriever

NewSQLDigestTextRetriever creates a new SQLDigestTextRetriever.

func (*SQLDigestTextRetriever) RetrieveGlobal

func (r *SQLDigestTextRetriever) RetrieveGlobal(ctx context.Context, exec expropt.SQLExecutor) error

RetrieveGlobal tries to retrieve the SQL text of the SQL digests from the information of the whole cluster.

func (*SQLDigestTextRetriever) RetrieveLocal

func (r *SQLDigestTextRetriever) RetrieveLocal(ctx context.Context, exec expropt.SQLExecutor) error

RetrieveLocal tries to retrieve the SQL text of the SQL digests from local information.

type SafeToShareAcrossSession

type SafeToShareAcrossSession interface {
	SafeToShareAcrossSession() bool
}

SafeToShareAcrossSession indicates whether the expression can be shared across different sessions. In Instance Plan Cache, we'll share the same Plan/Expression across different sessions, and this interface is used to check whether the expression is safe to share without cloning.

type ScalarFunction

type ScalarFunction struct {
	FuncName model.CIStr
	// RetType is the type that ScalarFunction returns.
	// TODO: Implement type inference here, now we use ast's return type temporarily.
	RetType  *types.FieldType `plan-cache-clone:"shallow"`
	Function builtinFunc
	// contains filtered or unexported fields
}

ScalarFunction is the function that returns a value.

func NewValuesFunc

func NewValuesFunc(ctx BuildContext, offset int, retTp *types.FieldType) *ScalarFunction

NewValuesFunc creates a new values function.

func (*ScalarFunction) CanonicalHashCode

func (sf *ScalarFunction) CanonicalHashCode() []byte

CanonicalHashCode implements Expression interface.

func (*ScalarFunction) CharsetAndCollation

func (sf *ScalarFunction) CharsetAndCollation() (string, string)

CharsetAndCollation gets charset and collation.

func (*ScalarFunction) Clone

func (sf *ScalarFunction) Clone() Expression

Clone implements Expression interface.

func (*ScalarFunction) Coercibility

func (sf *ScalarFunction) Coercibility() Coercibility

Coercibility returns the coercibility value which is used to check collations.

func (*ScalarFunction) ConstLevel

func (sf *ScalarFunction) ConstLevel() ConstLevel

ConstLevel returns the const level for the expression

func (*ScalarFunction) Decorrelate

func (sf *ScalarFunction) Decorrelate(schema *Schema) Expression

Decorrelate implements Expression interface.

func (*ScalarFunction) Equal

func (sf *ScalarFunction) Equal(ctx EvalContext, e Expression) bool

Equal implements Expression interface.

func (*ScalarFunction) Equals

func (sf *ScalarFunction) Equals(other any) bool

Equals implements HashEquals.<1th> interface.

func (*ScalarFunction) Eval

func (sf *ScalarFunction) Eval(ctx EvalContext, row chunk.Row) (d types.Datum, err error)

Eval implements Expression interface.

func (*ScalarFunction) EvalDecimal

func (sf *ScalarFunction) EvalDecimal(ctx EvalContext, row chunk.Row) (*types.MyDecimal, bool, error)

EvalDecimal implements Expression interface.

func (*ScalarFunction) EvalDuration

func (sf *ScalarFunction) EvalDuration(ctx EvalContext, row chunk.Row) (types.Duration, bool, error)

EvalDuration implements Expression interface.

func (*ScalarFunction) EvalInt

func (sf *ScalarFunction) EvalInt(ctx EvalContext, row chunk.Row) (int64, bool, error)

EvalInt implements Expression interface.

func (*ScalarFunction) EvalJSON

func (sf *ScalarFunction) EvalJSON(ctx EvalContext, row chunk.Row) (types.BinaryJSON, bool, error)

EvalJSON implements Expression interface.

func (*ScalarFunction) EvalReal

func (sf *ScalarFunction) EvalReal(ctx EvalContext, row chunk.Row) (float64, bool, error)

EvalReal implements Expression interface.

func (*ScalarFunction) EvalString

func (sf *ScalarFunction) EvalString(ctx EvalContext, row chunk.Row) (string, bool, error)

EvalString implements Expression interface.

func (*ScalarFunction) EvalTime

func (sf *ScalarFunction) EvalTime(ctx EvalContext, row chunk.Row) (types.Time, bool, error)

EvalTime implements Expression interface.

func (*ScalarFunction) EvalVectorFloat32

func (sf *ScalarFunction) EvalVectorFloat32(ctx EvalContext, row chunk.Row) (types.VectorFloat32, bool, error)

EvalVectorFloat32 implements Expression interface.

func (*ScalarFunction) ExplainInfo

func (expr *ScalarFunction) ExplainInfo(ctx EvalContext) string

ExplainInfo implements the Expression interface.

func (*ScalarFunction) ExplainNormalizedInfo

func (expr *ScalarFunction) ExplainNormalizedInfo() string

ExplainNormalizedInfo implements the Expression interface.

func (*ScalarFunction) ExplainNormalizedInfo4InList

func (expr *ScalarFunction) ExplainNormalizedInfo4InList() string

ExplainNormalizedInfo4InList implements the Expression interface.

func (*ScalarFunction) GetArgs

func (sf *ScalarFunction) GetArgs() []Expression

GetArgs gets arguments of function.

func (*ScalarFunction) GetSingleColumn

func (sf *ScalarFunction) GetSingleColumn(reverse bool) (*Column, bool)

GetSingleColumn returns (Col, Desc) when the ScalarFunction is equivalent to (Col, Desc) when used as a sort key, otherwise returns (nil, false).

Can only handle: - ast.Plus - ast.Minus - ast.UnaryMinus

func (*ScalarFunction) GetStaticType

func (sf *ScalarFunction) GetStaticType() *types.FieldType

GetStaticType returns the static type of the scalar function.

func (*ScalarFunction) GetType

func (sf *ScalarFunction) GetType(_ EvalContext) *types.FieldType

GetType implements Expression interface.

func (*ScalarFunction) HasCoercibility

func (sf *ScalarFunction) HasCoercibility() bool

HasCoercibility ...

func (*ScalarFunction) Hash64

func (sf *ScalarFunction) Hash64(h base.Hasher)

Hash64 implements HashEquals.<0th> interface.

func (*ScalarFunction) HashCode

func (sf *ScalarFunction) HashCode() []byte

HashCode implements Expression interface.

func (*ScalarFunction) IsCorrelated

func (sf *ScalarFunction) IsCorrelated() bool

IsCorrelated implements Expression interface.

func (*ScalarFunction) IsExplicitCharset

func (sf *ScalarFunction) IsExplicitCharset() bool

IsExplicitCharset return the charset is explicit set or not.

func (*ScalarFunction) MemoryUsage

func (sf *ScalarFunction) MemoryUsage() (sum int64)

MemoryUsage return the memory usage of ScalarFunction

func (*ScalarFunction) RemapColumn

func (sf *ScalarFunction) RemapColumn(m map[int64]*Column) (Expression, error)

RemapColumn remaps columns with provided mapping and returns new expression

func (*ScalarFunction) Repertoire

func (sf *ScalarFunction) Repertoire() Repertoire

Repertoire returns the repertoire value which is used to check collations.

func (*ScalarFunction) ResolveIndices

func (sf *ScalarFunction) ResolveIndices(schema *Schema) (Expression, error)

ResolveIndices implements Expression interface.

func (*ScalarFunction) ResolveIndicesByVirtualExpr

func (sf *ScalarFunction) ResolveIndicesByVirtualExpr(ctx EvalContext, schema *Schema) (Expression, bool)

ResolveIndicesByVirtualExpr implements Expression interface.

func (*ScalarFunction) SafeToShareAcrossSession

func (sf *ScalarFunction) SafeToShareAcrossSession() bool

SafeToShareAcrossSession returns if the function can be shared across different sessions.

func (*ScalarFunction) SetCharsetAndCollation

func (sf *ScalarFunction) SetCharsetAndCollation(chs, coll string)

SetCharsetAndCollation sets charset and collation.

func (*ScalarFunction) SetCoercibility

func (sf *ScalarFunction) SetCoercibility(val Coercibility)

SetCoercibility sets a specified coercibility for this expression.

func (*ScalarFunction) SetExplicitCharset

func (sf *ScalarFunction) SetExplicitCharset(explicit bool)

SetExplicitCharset set the charset is explicit or not.

func (*ScalarFunction) SetRepertoire

func (sf *ScalarFunction) SetRepertoire(r Repertoire)

SetRepertoire sets a specified repertoire for this expression.

func (*ScalarFunction) String

func (sf *ScalarFunction) String() string

String returns the string representation of the function

func (*ScalarFunction) StringWithCtx

func (sf *ScalarFunction) StringWithCtx(ctx ParamValues, redact string) string

StringWithCtx implements Expression interface.

func (*ScalarFunction) Traverse

func (sf *ScalarFunction) Traverse(action TraverseAction) Expression

Traverse implements the TraverseDown interface.

func (*ScalarFunction) VecEvalDecimal

func (sf *ScalarFunction) VecEvalDecimal(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalDecimal evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalDuration

func (sf *ScalarFunction) VecEvalDuration(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalDuration evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalInt

func (sf *ScalarFunction) VecEvalInt(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalInt evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalJSON

func (sf *ScalarFunction) VecEvalJSON(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalJSON evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalReal

func (sf *ScalarFunction) VecEvalReal(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalReal evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalString

func (sf *ScalarFunction) VecEvalString(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalString evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalTime

func (sf *ScalarFunction) VecEvalTime(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalTime evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalVectorFloat32

func (sf *ScalarFunction) VecEvalVectorFloat32(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

VecEvalVectorFloat32 evaluates this expression in a vectorized manner.

func (*ScalarFunction) Vectorized

func (sf *ScalarFunction) Vectorized() bool

Vectorized returns if this expression supports vectorized evaluation.

type ScalarFunctionCallBack

type ScalarFunctionCallBack func(function *ScalarFunction) (Expression, error)

ScalarFunctionCallBack is the definition of callback of calling a newFunction.

type Schema

type Schema struct {
	Columns []*Column
	PKOrUK  []KeyInfo // this fields stores the primary key or unique key.
	// NullableUK stores those unique indexes that allow null values, but PKOrUK does not allow null values.
	// Since equivalence conditions can filter out null values, in this case a unique index with null values can be a Key.
	NullableUK []KeyInfo
}

Schema stands for the row schema and unique key information get from input.

func MergeSchema

func MergeSchema(lSchema, rSchema *Schema) *Schema

MergeSchema will merge two schema into one schema. We shouldn't need to consider unique keys. That will be processed in build_key_info.go.

func NewSchema

func NewSchema(cols ...*Column) *Schema

NewSchema returns a schema made by its parameter.

func TableInfo2SchemaAndNames

func TableInfo2SchemaAndNames(ctx BuildContext, dbName pmodel.CIStr, tbl *model.TableInfo) (*Schema, []*types.FieldName, error)

TableInfo2SchemaAndNames converts the TableInfo to the schema and name slice.

func (*Schema) Append

func (s *Schema) Append(col ...*Column)

Append append new column to the columns stored in schema.

func (*Schema) Clone

func (s *Schema) Clone() *Schema

Clone copies the total schema.

func (*Schema) ColumnIndex

func (s *Schema) ColumnIndex(col *Column) int

ColumnIndex finds the index for a column.

func (*Schema) ColumnsByIndices

func (s *Schema) ColumnsByIndices(offsets []int) []*Column

ColumnsByIndices returns columns by multiple offsets. Callers should guarantee that all the offsets provided should be valid, which means offset should: 1. not smaller than 0, and 2. not exceed len(s.Columns)

func (*Schema) ColumnsIndices

func (s *Schema) ColumnsIndices(cols []*Column) (ret []int)

ColumnsIndices will return a slice which contains the position of each column in schema. If there is one column that doesn't match, nil will be returned.

func (*Schema) Contains

func (s *Schema) Contains(col *Column) bool

Contains checks if the schema contains the column.

func (*Schema) ExtractColGroups

func (s *Schema) ExtractColGroups(colGroups [][]*Column) ([][]int, []int)

ExtractColGroups checks if column groups are from current schema, and returns offsets of those satisfied column groups.

func (*Schema) GetExtraHandleColumn

func (s *Schema) GetExtraHandleColumn() *Column

GetExtraHandleColumn gets the extra handle column.

func (*Schema) IsUnique

func (s *Schema) IsUnique(strong bool, cols ...*Column) bool

IsUnique checks if the column is unique key. Pass strong=true to check strong contraint: unique && notnull. Pass strong=false to check weak contraint: unique && nullable.

func (*Schema) Len

func (s *Schema) Len() int

Len returns the number of columns in schema.

func (*Schema) MemoryUsage

func (s *Schema) MemoryUsage() (sum int64)

MemoryUsage return the memory usage of Schema

func (*Schema) RetrieveColumn

func (s *Schema) RetrieveColumn(col *Column) *Column

RetrieveColumn retrieves column in expression from the columns in schema.

func (*Schema) SetKeys

func (s *Schema) SetKeys(keys []KeyInfo)

SetKeys will set the value of Schema.Keys.

func (*Schema) SetUniqueKeys

func (s *Schema) SetUniqueKeys(keys []KeyInfo)

SetUniqueKeys will set the value of Schema.UniqueKeys.

func (*Schema) String

func (s *Schema) String() string

String implements fmt.Stringer interface.

type StringerWithCtx

type StringerWithCtx interface {
	// StringWithCtx returns the string representation of the expression with context.
	// NOTE: any implementation of `StringWithCtx` should not panic if the context is nil.
	StringWithCtx(ctx ParamValues, redact string) string
}

StringerWithCtx is the interface for expressions that can be stringified with context.

type TraverseAction

type TraverseAction interface {
	Transform(Expression) Expression
}

TraverseAction define the interface for action when traversing down an expression.

type VSInfo

type VSInfo struct {
	DistanceFnName model.CIStr
	FnPbCode       tipb.ScalarFuncSig
	Vec            types.VectorFloat32
	Column         *Column
}

VSInfo is an easy to use struct for interpreting a VectorSearch expression. NOTE: not all VectorSearch functions are supported by the index. The caller needs to check the distance function name.

func InterpretVectorSearchExpr

func InterpretVectorSearchExpr(expr Expression) *VSInfo

InterpretVectorSearchExpr try to interpret a VectorSearch expression. If interpret successfully, return a VSInfo struct, otherwise return nil. NOTE: not all VectorSearch functions are supported by the index. The caller needs to check the distance function name.

type VarAssignment

type VarAssignment struct {
	Name        string
	Expr        Expression
	IsDefault   bool
	IsGlobal    bool
	IsSystem    bool
	ExtendValue *Constant
}

VarAssignment represents a variable assignment in Set, such as set global a = 1.

type VecExpr

type VecExpr interface {
	// Vectorized returns if this expression supports vectorized evaluation.
	Vectorized() bool

	// VecEvalInt evaluates this expression in a vectorized manner.
	VecEvalInt(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

	// VecEvalReal evaluates this expression in a vectorized manner.
	VecEvalReal(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

	// VecEvalString evaluates this expression in a vectorized manner.
	VecEvalString(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

	// VecEvalDecimal evaluates this expression in a vectorized manner.
	VecEvalDecimal(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

	// VecEvalTime evaluates this expression in a vectorized manner.
	VecEvalTime(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

	// VecEvalDuration evaluates this expression in a vectorized manner.
	VecEvalDuration(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

	// VecEvalJSON evaluates this expression in a vectorized manner.
	VecEvalJSON(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error

	// VecEvalBool evaluates this expression in a vectorized manner.
	VecEvalVectorFloat32(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error
}

VecExpr contains all vectorized evaluation methods.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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