tidb: github.com/pingcap/tidb/expression Index | Files | Directories

package expression

import "github.com/pingcap/tidb/expression"

Index

Package Files

builtin.go builtin_arithmetic.go builtin_arithmetic_vec.go builtin_cast.go builtin_cast_vec.go builtin_compare.go builtin_compare_vec.go builtin_compare_vec_generated.go builtin_control.go builtin_control_vec_generated.go builtin_encryption.go builtin_encryption_vec.go builtin_info.go builtin_info_vec.go builtin_json.go builtin_json_vec.go builtin_like.go builtin_like_vec.go builtin_math.go builtin_math_vec.go builtin_miscellaneous.go builtin_miscellaneous_vec.go builtin_op.go builtin_op_vec.go builtin_other.go builtin_other_vec.go builtin_other_vec_generated.go builtin_string.go builtin_string_vec.go builtin_string_vec_generated.go builtin_time.go builtin_time_vec.go builtin_time_vec_generated.go builtin_vectorized.go chunk_executor.go column.go constant.go constant_fold.go constant_propagation.go constraint_propagation.go distsql_builtin.go errors.go evaluator.go explain.go expr_to_pb.go expression.go function_traits.go helper.go scalar_function.go schema.go simple_rewriter.go util.go vectorized.go

Constants

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

Supported hash length of SHA-2 family

Variables

var (
    // One stands for a number 1.
    One = &Constant{
        Value:   types.NewDatum(1),
        RetType: types.NewFieldType(mysql.TypeTiny),
    }

    // Zero stands for a number 0.
    Zero = &Constant{
        Value:   types.NewDatum(0),
        RetType: types.NewFieldType(mysql.TypeTiny),
    }

    // Null stands for null constant.
    Null = &Constant{
        Value:   types.NewDatum(nil),
        RetType: types.NewFieldType(mysql.TypeTiny),
    }
)
var (
    // All the exported errors are defined here:
    ErrIncorrectParameterCount = terror.ClassExpression.New(mysql.ErrWrongParamcountToNativeFct, mysql.MySQLErrName[mysql.ErrWrongParamcountToNativeFct])
    ErrDivisionByZero          = terror.ClassExpression.New(mysql.ErrDivisionByZero, mysql.MySQLErrName[mysql.ErrDivisionByZero])
    ErrRegexp                  = terror.ClassExpression.New(mysql.ErrRegexp, mysql.MySQLErrName[mysql.ErrRegexp])
    ErrOperandColumns          = terror.ClassExpression.New(mysql.ErrOperandColumns, mysql.MySQLErrName[mysql.ErrOperandColumns])
    ErrCutValueGroupConcat     = terror.ClassExpression.New(mysql.ErrCutValueGroupConcat, mysql.MySQLErrName[mysql.ErrCutValueGroupConcat])
    ErrFunctionsNoopImpl       = terror.ClassExpression.New(mysql.ErrNotSupportedYet, "function %s has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions")
)

Error instances.

var DefaultExprPushdownBlacklist *atomic.Value

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

var DeferredFunctions = map[string]struct{}{
    ast.Now:              {},
    ast.CurrentTimestamp: {},
    ast.UTCTime:          {},
    ast.Curtime:          {},
    ast.CurrentTime:      {},
    ast.UTCTimestamp:     {},
    ast.UnixTimestamp:    {},
    ast.Sysdate:          {},
    ast.Curdate:          {},
    ast.CurrentDate:      {},
    ast.UTCDate:          {},
    ast.Rand:             {},
    ast.UUID:             {},
}

DeferredFunctions stores non-deterministic functions, which can be deferred only when the plan cache is enabled.

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.

var EvalAstExpr func(sctx sessionctx.Context, expr ast.ExprNode) (types.Datum, error)

EvalAstExpr evaluates ast expression directly.

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

var MaxPropagateColsCnt = 100

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

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

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

func CheckArgsNotMultiColumnRow Uses

func CheckArgsNotMultiColumnRow(args ...Expression) error

CheckArgsNotMultiColumnRow checks the args are not multi-column row.

func CompareDecimal Uses

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

CompareDecimal compares two decimals.

func CompareDuration Uses

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

CompareDuration compares two durations.

func CompareInt Uses

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

CompareInt compares two integers.

func CompareJSON Uses

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

CompareJSON compares two JSONs.

func CompareReal Uses

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

CompareReal compares two float-point values.

func CompareString Uses

func CompareString(sctx sessionctx.Context, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row) (int64, bool, error)

CompareString compares two strings.

func CompareTime Uses

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

CompareTime compares two datetime or timestamps.

func ConstructPositionExpr Uses

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

ConstructPositionExpr constructs PositionExpr with the given ParamMarkerExpr.

func ContainVirtualColumn Uses

func ContainVirtualColumn(exprs []Expression) bool

ContainVirtualColumn checks if the expressions contain a virtual column

func Contains Uses

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

Contains tests if `exprs` contains `e`.

func DisableParseJSONFlag4Expr Uses

func DisableParseJSONFlag4Expr(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 Uses

func EvalBool(ctx sessionctx.Context, 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 ExplainColumnList Uses

func ExplainColumnList(cols []*Column) []byte

ExplainColumnList generates explain information for a list of columns.

func ExplainExpressionList Uses

func ExplainExpressionList(exprs []Expression) []byte

ExplainExpressionList generates explain information for a list of expressions.

func ExprFromSchema Uses

func ExprFromSchema(expr Expression, schema *Schema) bool

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

func ExpressionsToPB Uses

func ExpressionsToPB(sc *stmtctx.StatementContext, exprs []Expression, client kv.Client) (pbCNF *tipb.Expr, pushed []Expression, remained []Expression)

ExpressionsToPB converts expression to tipb.Expr.

func ExpressionsToPBList Uses

func ExpressionsToPBList(sc *stmtctx.StatementContext, exprs []Expression, client kv.Client) (pbExpr []*tipb.Expr)

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

func ExtractColumnSet Uses

func ExtractColumnSet(exprs []Expression) *intsets.Sparse

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

func FindFieldName Uses

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

FindFieldName finds the column name from NameSlice.

func FindFieldNameIdxByColName Uses

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

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

func GetAccurateCmpType Uses

func GetAccurateCmpType(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 GetCmpTp4MinMax Uses

func GetCmpTp4MinMax(args []Expression) (argTp types.EvalType)

GetCmpTp4MinMax gets compare type for GREATEST and LEAST and BETWEEN (mainly for datetime).

func GetColumn Uses

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

GetColumn allocates a column buffer with the specific eval type and capacity. the allocator is not responsible for initializing the column, so please initialize it before using.

func GetIntFromConstant Uses

func GetIntFromConstant(ctx sessionctx.Context, value Expression) (int, bool, error)

GetIntFromConstant gets an interger value from the Constant expression.

func GetRowLen Uses

func GetRowLen(e Expression) int

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

func GetStringFromConstant Uses

func GetStringFromConstant(ctx sessionctx.Context, value Expression) (string, bool, error)

GetStringFromConstant gets a string value from the Constant expression.

func GetTimeValue Uses

func GetTimeValue(ctx sessionctx.Context, v interface{}, tp byte, fsp int8) (d types.Datum, err error)

GetTimeValue gets the time value with type tp.

func GetUint64FromConstant Uses

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

GetUint64FromConstant gets a uint64 from constant expression.

func GroupByItemToPB Uses

func GroupByItemToPB(sc *stmtctx.StatementContext, client kv.Client, expr Expression) *tipb.ByItem

GroupByItemToPB converts group by items to pb.

func HasAssignSetVarFunc Uses

func HasAssignSetVarFunc(expr Expression) bool

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

func HasGetSetVarFunc Uses

func HasGetSetVarFunc(expr Expression) bool

HasGetSetVarFunc checks whether an expression contains SetVar/GetVar function.

func InferType4ControlFuncs Uses

func InferType4ControlFuncs(lhs, rhs *types.FieldType) *types.FieldType

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

func IsBinaryLiteral Uses

func IsBinaryLiteral(expr Expression) bool

IsBinaryLiteral checks whether an expression is a binary literal

func IsEQCondFromIn Uses

func IsEQCondFromIn(expr Expression) bool

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

func IsFunctionSupported Uses

func IsFunctionSupported(name string) bool

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

func IsMutableEffectsExpr Uses

func IsMutableEffectsExpr(expr Expression) bool

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

func IsValidCurrentTimestampExpr Uses

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 NewPartitionPruneSolver Uses

func NewPartitionPruneSolver() constraintSolver

NewPartitionPruneSolver returns a constraintSolver for partition pruning.

func PbTypeToFieldType Uses

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

PbTypeToFieldType converts tipb.FieldType to FieldType

func PosFromPositionExpr Uses

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

PosFromPositionExpr generates a position value from PositionExpr.

func PropConstOverOuterJoin Uses

func PropConstOverOuterJoin(ctx sessionctx.Context, 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 PutColumn Uses

func PutColumn(buf *chunk.Column)

PutColumn releases a column buffer.

func Quote Uses

func Quote(str string) string

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

func SetBinFlagOrBinStr Uses

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.

func SortByItemToPB Uses

func SortByItemToPB(sc *stmtctx.StatementContext, client kv.Client, expr Expression, desc bool) *tipb.ByItem

SortByItemToPB converts order by items to pb.

func SortedExplainExpressionList Uses

func SortedExplainExpressionList(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 ToPBFieldType Uses

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

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

func VecEval Uses

func VecEval(ctx sessionctx.Context, expr Expression, input *chunk.Chunk, result *chunk.Column) (err error)

VecEval evaluates this expr according to its type.

func VecEvalBool Uses

func VecEvalBool(ctx sessionctx.Context, 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 Uses

func Vectorizable(exprs []Expression) bool

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

func VectorizedExecute Uses

func VectorizedExecute(ctx sessionctx.Context, 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 Uses

func VectorizedFilter(ctx sessionctx.Context, 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 Uses

func VectorizedFilterConsiderNull(ctx sessionctx.Context, 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.

type Assignment Uses

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 model.CIStr
    Expr    Expression
}

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

type CNFExprs Uses

type CNFExprs []Expression

CNFExprs stands for a CNF expression.

func (CNFExprs) Clone Uses

func (e CNFExprs) Clone() CNFExprs

Clone clones itself.

func (CNFExprs) Shallow Uses

func (e CNFExprs) Shallow() CNFExprs

Shallow makes a shallow copy of itself.

type Column Uses

type Column struct {
    RetType *types.FieldType
    // 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

    // InOperand indicates whether this column is the inner operand of column equal condition converted
    // from `[not] in (subq)`.
    InOperand bool
    // VirtualExpr is used to save expression for virtual column
    VirtualExpr Expression
    // contains filtered or unexported fields
}

Column represents a column.

func ColInfo2Col Uses

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

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

func ColumnInfos2ColumnsAndNames Uses

func ColumnInfos2ColumnsAndNames(ctx sessionctx.Context, dbName, tblName model.CIStr, colInfos []*model.ColumnInfo) ([]*Column, types.NameSlice)

ColumnInfos2ColumnsAndNames converts the ColumnInfo to the *Column and NameSlice.

func ExtractColumns Uses

func ExtractColumns(expr Expression) []*Column

ExtractColumns extracts all columns from an expression.

func ExtractColumnsFromExpressions Uses

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 Uses

func ExtractDependentColumns(expr Expression) []*Column

ExtractDependentColumns extracts all dependent columns from a virtual column.

func FindPrefixOfIndex Uses

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 IndexInfo2Cols Uses

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 Uses

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 (*Column) Clone Uses

func (col *Column) Clone() Expression

Clone implements Expression interface.

func (*Column) ConstItem Uses

func (col *Column) ConstItem() bool

ConstItem implements Expression interface.

func (*Column) Decorrelate Uses

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

Decorrelate implements Expression interface.

func (*Column) Equal Uses

func (col *Column) Equal(_ sessionctx.Context, expr Expression) bool

Equal implements Expression interface.

func (*Column) Eval Uses

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

Eval implements Expression interface.

func (*Column) EvalDecimal Uses

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

EvalDecimal returns decimal representation of Column.

func (*Column) EvalDuration Uses

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

EvalDuration returns Duration representation of Column.

func (*Column) EvalInt Uses

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

EvalInt returns int representation of Column.

func (*Column) EvalJSON Uses

func (col *Column) EvalJSON(ctx sessionctx.Context, row chunk.Row) (json.BinaryJSON, bool, error)

EvalJSON returns JSON representation of Column.

func (*Column) EvalReal Uses

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

EvalReal returns real representation of Column.

func (*Column) EvalString Uses

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

EvalString returns string representation of Column.

func (*Column) EvalTime Uses

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

EvalTime returns DATE/DATETIME/TIMESTAMP representation of Column.

func (*Column) EvalVirtualColumn Uses

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

EvalVirtualColumn evals the virtual column

func (*Column) ExplainInfo Uses

func (col *Column) ExplainInfo() string

ExplainInfo implements the Expression interface.

func (*Column) GetType Uses

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

GetType implements Expression interface.

func (*Column) HashCode Uses

func (col *Column) HashCode(_ *stmtctx.StatementContext) []byte

HashCode implements Expression interface.

func (*Column) IsCorrelated Uses

func (col *Column) IsCorrelated() bool

IsCorrelated implements Expression interface.

func (*Column) MarshalJSON Uses

func (col *Column) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Column) ResolveIndices Uses

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

ResolveIndices implements Expression interface.

func (*Column) String Uses

func (col *Column) String() string

String implements Stringer interface.

func (*Column) ToInfo Uses

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) VecEvalDecimal Uses

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

VecEvalDecimal evaluates this expression in a vectorized manner.

func (*Column) VecEvalDuration Uses

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

VecEvalDuration evaluates this expression in a vectorized manner.

func (*Column) VecEvalInt Uses

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

VecEvalInt evaluates this expression in a vectorized manner.

func (*Column) VecEvalJSON Uses

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

VecEvalJSON evaluates this expression in a vectorized manner.

func (*Column) VecEvalReal Uses

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

VecEvalReal evaluates this expression in a vectorized manner.

func (*Column) VecEvalString Uses

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

VecEvalString evaluates this expression in a vectorized manner.

func (*Column) VecEvalTime Uses

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

VecEvalTime evaluates this expression in a vectorized manner.

func (*Column) Vectorized Uses

func (col *Column) Vectorized() bool

Vectorized returns if this expression supports vectorized evaluation.

type CompareFunc Uses

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

CompareFunc defines the compare function prototype.

func GetCmpFunction Uses

func GetCmpFunction(lhs, rhs Expression) CompareFunc

GetCmpFunction get the compare function according to two arguments.

type Constant Uses

type Constant struct {
    Value   types.Datum
    RetType *types.FieldType
    // 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 Uses

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

DatumToConstant generates a Constant expression from a Datum.

func RefineComparedConstant Uses

func RefineComparedConstant(ctx sessionctx.Context, 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, ExecptionalVal 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) Clone Uses

func (c *Constant) Clone() Expression

Clone implements Expression interface.

func (*Constant) ConstItem Uses

func (c *Constant) ConstItem() bool

ConstItem implements Expression interface.

func (*Constant) Decorrelate Uses

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

Decorrelate implements Expression interface.

func (*Constant) Equal Uses

func (c *Constant) Equal(ctx sessionctx.Context, b Expression) bool

Equal implements Expression interface.

func (*Constant) Eval Uses

func (c *Constant) Eval(_ chunk.Row) (types.Datum, error)

Eval implements Expression interface.

func (*Constant) EvalDecimal Uses

func (c *Constant) EvalDecimal(ctx sessionctx.Context, _ chunk.Row) (*types.MyDecimal, bool, error)

EvalDecimal returns decimal representation of Constant.

func (*Constant) EvalDuration Uses

func (c *Constant) EvalDuration(ctx sessionctx.Context, _ chunk.Row) (val types.Duration, isNull bool, err error)

EvalDuration returns Duration representation of Constant.

func (*Constant) EvalInt Uses

func (c *Constant) EvalInt(ctx sessionctx.Context, _ chunk.Row) (int64, bool, error)

EvalInt returns int representation of Constant.

func (*Constant) EvalJSON Uses

func (c *Constant) EvalJSON(ctx sessionctx.Context, _ chunk.Row) (json.BinaryJSON, bool, error)

EvalJSON returns JSON representation of Constant.

func (*Constant) EvalReal Uses

func (c *Constant) EvalReal(ctx sessionctx.Context, _ chunk.Row) (float64, bool, error)

EvalReal returns real representation of Constant.

func (*Constant) EvalString Uses

func (c *Constant) EvalString(ctx sessionctx.Context, _ chunk.Row) (string, bool, error)

EvalString returns string representation of Constant.

func (*Constant) EvalTime Uses

func (c *Constant) EvalTime(ctx sessionctx.Context, _ chunk.Row) (val types.Time, isNull bool, err error)

EvalTime returns DATE/DATETIME/TIMESTAMP representation of Constant.

func (*Constant) ExplainInfo Uses

func (expr *Constant) ExplainInfo() string

ExplainInfo implements the Expression interface.

func (*Constant) GetType Uses

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

GetType implements Expression interface.

func (*Constant) HashCode Uses

func (c *Constant) HashCode(sc *stmtctx.StatementContext) []byte

HashCode implements Expression interface.

func (*Constant) IsCorrelated Uses

func (c *Constant) IsCorrelated() bool

IsCorrelated implements Expression interface.

func (*Constant) MarshalJSON Uses

func (c *Constant) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Constant) ResolveIndices Uses

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

ResolveIndices implements Expression interface.

func (*Constant) String Uses

func (c *Constant) String() string

String implements fmt.Stringer interface.

func (*Constant) VecEvalDecimal Uses

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

VecEvalDecimal evaluates this expression in a vectorized manner.

func (*Constant) VecEvalDuration Uses

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

VecEvalDuration evaluates this expression in a vectorized manner.

func (*Constant) VecEvalInt Uses

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

VecEvalInt evaluates this expression in a vectorized manner.

func (*Constant) VecEvalJSON Uses

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

VecEvalJSON evaluates this expression in a vectorized manner.

func (*Constant) VecEvalReal Uses

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

VecEvalReal evaluates this expression in a vectorized manner.

func (*Constant) VecEvalString Uses

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

VecEvalString evaluates this expression in a vectorized manner.

func (*Constant) VecEvalTime Uses

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

VecEvalTime evaluates this expression in a vectorized manner.

func (*Constant) Vectorized Uses

func (c *Constant) Vectorized() bool

Vectorized returns if this expression supports vectorized evaluation.

type CorrelatedColumn Uses

type CorrelatedColumn struct {
    Column

    Data *types.Datum
}

CorrelatedColumn stands for a column in a correlated sub query.

func ExtractCorColumns Uses

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

ExtractCorColumns extracts correlated column from given expression.

func (*CorrelatedColumn) Clone Uses

func (col *CorrelatedColumn) Clone() Expression

Clone implements Expression interface.

func (*CorrelatedColumn) ConstItem Uses

func (col *CorrelatedColumn) ConstItem() bool

ConstItem implements Expression interface.

func (*CorrelatedColumn) Decorrelate Uses

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

Decorrelate implements Expression interface.

func (*CorrelatedColumn) Equal Uses

func (col *CorrelatedColumn) Equal(ctx sessionctx.Context, expr Expression) bool

Equal implements Expression interface.

func (*CorrelatedColumn) Eval Uses

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

Eval implements Expression interface.

func (*CorrelatedColumn) EvalDecimal Uses

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

EvalDecimal returns decimal representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalDuration Uses

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

EvalDuration returns Duration representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalInt Uses

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

EvalInt returns int representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalJSON Uses

func (col *CorrelatedColumn) EvalJSON(ctx sessionctx.Context, row chunk.Row) (json.BinaryJSON, bool, error)

EvalJSON returns JSON representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalReal Uses

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

EvalReal returns real representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalString Uses

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

EvalString returns string representation of CorrelatedColumn.

func (*CorrelatedColumn) EvalTime Uses

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

EvalTime returns DATE/DATETIME/TIMESTAMP representation of CorrelatedColumn.

func (*CorrelatedColumn) IsCorrelated Uses

func (col *CorrelatedColumn) IsCorrelated() bool

IsCorrelated implements Expression interface.

func (*CorrelatedColumn) ResolveIndices Uses

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

ResolveIndices implements Expression interface.

func (*CorrelatedColumn) VecEvalDecimal Uses

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

VecEvalDecimal evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalDuration Uses

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

VecEvalDuration evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalInt Uses

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

VecEvalInt evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalJSON Uses

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

VecEvalJSON evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalReal Uses

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

VecEvalReal evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalString Uses

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

VecEvalString evaluates this expression in a vectorized manner.

func (*CorrelatedColumn) VecEvalTime Uses

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

VecEvalTime evaluates this expression in a vectorized manner.

type EvaluatorSuite Uses

type EvaluatorSuite struct {
    // 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 Uses

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) Run Uses

func (e *EvaluatorSuite) Run(ctx sessionctx.Context, input, output *chunk.Chunk) error

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

func (*EvaluatorSuite) Vectorizable Uses

func (e *EvaluatorSuite) Vectorizable() bool

Vectorizable checks whether this EvaluatorSuite can use vectorizd execution mode.

type Expression Uses

type Expression interface {
    fmt.Stringer
    goJSON.Marshaler
    VecExpr

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

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

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

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

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

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

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

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

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

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

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

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

    // ConstItem checks if this expression is constant item, regardless of query evaluation state.
    // A constant item can be eval() when build a plan.
    // An expression is constant item if it:
    // refers no tables.
    // refers no subqueries that refers any tables.
    // refers no non-deterministic functions.
    // refers no statement parameters.
    ConstItem() bool

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

    // ExplainInfo returns operator information to be explained.
    ExplainInfo() 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(sc *stmtctx.StatementContext) []byte
    // contains filtered or unexported methods
}

Expression represents all scalar expression in SQL.

func BuildCastFunction Uses

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

BuildCastFunction builds a CAST ScalarFunction from the Expression.

func BuildCastFunction4Union Uses

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

BuildCastFunction4Union build a implicitly CAST ScalarFunction from the Union Expression.

func BuildNotNullExpr Uses

func BuildNotNullExpr(ctx sessionctx.Context, expr Expression) Expression

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

func CheckExprPushFlash Uses

func CheckExprPushFlash(exprs []Expression) (exprPush, remain []Expression)

CheckExprPushFlash checks a expr list whether each expr can be pushed to flash storage.

func Column2Exprs Uses

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

Column2Exprs will transfer column slice to expression slice.

func ColumnSubstitute Uses

func ColumnSubstitute(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.

func ColumnSubstituteImpl Uses

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

ColumnSubstituteImpl tries to substitute column expr using newExprs, the newFunctionInternal is only called if its child is substituted

func ComposeCNFCondition Uses

func ComposeCNFCondition(ctx sessionctx.Context, conditions ...Expression) Expression

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

func ComposeDNFCondition Uses

func ComposeDNFCondition(ctx sessionctx.Context, conditions ...Expression) Expression

ComposeDNFCondition composes DNF items into a balance deep DNF tree.

func DeriveRelaxedFiltersFromDNF Uses

func DeriveRelaxedFiltersFromDNF(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 EvaluateExprWithNull Uses

func EvaluateExprWithNull(ctx sessionctx.Context, schema *Schema, expr Expression) Expression

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 ExtractFiltersFromDNFs Uses

func ExtractFiltersFromDNFs(ctx sessionctx.Context, 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 orignal slice.

func Filter Uses

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

Filter the input expressions, append the results to result.

func FilterOutInPlace Uses

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 Uses

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 Uses

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 Uses

func FoldConstant(expr Expression) Expression

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

func GetFuncArg Uses

func GetFuncArg(e Expression, idx int) Expression

GetFuncArg gets the argument of the function at idx.

func NewFunction Uses

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

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

func NewFunctionBase Uses

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

NewFunctionBase creates a new scalar function with no constant folding.

func NewFunctionInternal Uses

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

NewFunctionInternal is similar to NewFunction, but do not returns error, should only be used internally.

func PBToExpr Uses

func PBToExpr(expr *tipb.Expr, tps []*types.FieldType, sc *stmtctx.StatementContext) (Expression, error)

PBToExpr converts pb structure to expression.

func ParamMarkerExpression Uses

func ParamMarkerExpression(ctx sessionctx.Context, v *driver.ParamMarkerExpr) (Expression, error)

ParamMarkerExpression generate a getparam function expression.

func ParseSimpleExprCastWithTableInfo Uses

func ParseSimpleExprCastWithTableInfo(ctx sessionctx.Context, exprStr string, tableInfo *model.TableInfo, targetFt *types.FieldType) (Expression, error)

ParseSimpleExprCastWithTableInfo parses simple expression string to Expression. And the expr returns will cast to the target type.

func ParseSimpleExprWithTableInfo Uses

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

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

func ParseSimpleExprsWithNames Uses

func ParseSimpleExprsWithNames(ctx sessionctx.Context, exprStr string, schema *Schema, names types.NameSlice) ([]Expression, error)

ParseSimpleExprsWithNames parses simple expression string to Expression. The expression string must only reference the column in the given NameSlice.

func ParseSimpleExprsWithSchema Uses

func ParseSimpleExprsWithSchema(ctx sessionctx.Context, exprStr string, schema *Schema) ([]Expression, error)

ParseSimpleExprsWithSchema parses simple expression string to Expression. The expression string must only reference the column in the given schema.

func PopRowFirstArg Uses

func PopRowFirstArg(ctx sessionctx.Context, 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 Uses

func PropagateConstant(ctx sessionctx.Context, conditions []Expression) []Expression

PropagateConstant propagate constant values of deterministic predicates in a condition.

func PushDownNot Uses

func PushDownNot(ctx sessionctx.Context, expr Expression) Expression

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

func RemoveDupExprs Uses

func RemoveDupExprs(ctx sessionctx.Context, 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.

func RewriteSimpleExprWithNames Uses

func RewriteSimpleExprWithNames(ctx sessionctx.Context, expr ast.ExprNode, schema *Schema, names []*types.FieldName) (Expression, error)

RewriteSimpleExprWithNames rewrites simple ast.ExprNode to expression.Expression.

func RewriteSimpleExprWithSchema Uses

func RewriteSimpleExprWithSchema(ctx sessionctx.Context, expr ast.ExprNode, schema *Schema) (Expression, error)

RewriteSimpleExprWithSchema rewrites simple ast.ExprNode to expression.Expression.

func RewriteSimpleExprWithTableInfo Uses

func RewriteSimpleExprWithTableInfo(ctx sessionctx.Context, tbl *model.TableInfo, expr ast.ExprNode) (Expression, error)

RewriteSimpleExprWithTableInfo rewrites simple ast.ExprNode to expression.Expression.

func ScalarFuncs2Exprs Uses

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

ScalarFuncs2Exprs converts []*ScalarFunction to []Expression.

func SplitCNFItems Uses

func SplitCNFItems(onExpr Expression) []Expression

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

func SplitDNFItems Uses

func SplitDNFItems(onExpr Expression) []Expression

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

func SubstituteCorCol2Constant Uses

func SubstituteCorCol2Constant(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 WrapWithCastAsDecimal Uses

func WrapWithCastAsDecimal(ctx sessionctx.Context, expr Expression) Expression

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

func WrapWithCastAsDuration Uses

func WrapWithCastAsDuration(ctx sessionctx.Context, expr Expression) Expression

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

func WrapWithCastAsInt Uses

func WrapWithCastAsInt(ctx sessionctx.Context, expr Expression) Expression

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

func WrapWithCastAsJSON Uses

func WrapWithCastAsJSON(ctx sessionctx.Context, expr Expression) Expression

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

func WrapWithCastAsReal Uses

func WrapWithCastAsReal(ctx sessionctx.Context, expr Expression) Expression

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

func WrapWithCastAsString Uses

func WrapWithCastAsString(ctx sessionctx.Context, expr Expression) Expression

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

func WrapWithCastAsTime Uses

func WrapWithCastAsTime(ctx sessionctx.Context, 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.

type KeyInfo Uses

type KeyInfo []*Column

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

func (KeyInfo) Clone Uses

func (ki KeyInfo) Clone() KeyInfo

Clone copies the entire UniqueKey.

type ParamMarker Uses

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

ParamMarker indicates param provided by COM_STMT_EXECUTE.

func (*ParamMarker) GetUserVar Uses

func (d *ParamMarker) GetUserVar() types.Datum

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

type PbConverter Uses

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

PbConverter supplys methods to convert TiDB expressions to TiPB.

func NewPBConverter Uses

func NewPBConverter(client kv.Client, sc *stmtctx.StatementContext) PbConverter

NewPBConverter creates a PbConverter.

func (PbConverter) ExprToPB Uses

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

ExprToPB converts Expression to TiPB.

type PropagateConstantSolver Uses

type PropagateConstantSolver interface {
    PropagateConstant(ctx sessionctx.Context, conditions []Expression) []Expression
}

PropagateConstantSolver is a constant propagate solver.

type ScalarFunction Uses

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
    Function builtinFunc
    // contains filtered or unexported fields
}

ScalarFunction is the function that returns a value.

func NewValuesFunc Uses

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

NewValuesFunc creates a new values function.

func (*ScalarFunction) Clone Uses

func (sf *ScalarFunction) Clone() Expression

Clone implements Expression interface.

func (*ScalarFunction) ConstItem Uses

func (sf *ScalarFunction) ConstItem() bool

ConstItem implements Expression interface.

func (*ScalarFunction) Decorrelate Uses

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

Decorrelate implements Expression interface.

func (*ScalarFunction) Equal Uses

func (sf *ScalarFunction) Equal(ctx sessionctx.Context, e Expression) bool

Equal implements Expression interface.

func (*ScalarFunction) Eval Uses

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

Eval implements Expression interface.

func (*ScalarFunction) EvalDecimal Uses

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

EvalDecimal implements Expression interface.

func (*ScalarFunction) EvalDuration Uses

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

EvalDuration implements Expression interface.

func (*ScalarFunction) EvalInt Uses

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

EvalInt implements Expression interface.

func (*ScalarFunction) EvalJSON Uses

func (sf *ScalarFunction) EvalJSON(ctx sessionctx.Context, row chunk.Row) (json.BinaryJSON, bool, error)

EvalJSON implements Expression interface.

func (*ScalarFunction) EvalReal Uses

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

EvalReal implements Expression interface.

func (*ScalarFunction) EvalString Uses

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

EvalString implements Expression interface.

func (*ScalarFunction) EvalTime Uses

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

EvalTime implements Expression interface.

func (*ScalarFunction) ExplainInfo Uses

func (expr *ScalarFunction) ExplainInfo() string

ExplainInfo implements the Expression interface.

func (*ScalarFunction) GetArgs Uses

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

GetArgs gets arguments of function.

func (*ScalarFunction) GetCtx Uses

func (sf *ScalarFunction) GetCtx() sessionctx.Context

GetCtx gets the context of function.

func (*ScalarFunction) GetType Uses

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

GetType implements Expression interface.

func (*ScalarFunction) HashCode Uses

func (sf *ScalarFunction) HashCode(sc *stmtctx.StatementContext) []byte

HashCode implements Expression interface.

func (*ScalarFunction) IsCorrelated Uses

func (sf *ScalarFunction) IsCorrelated() bool

IsCorrelated implements Expression interface.

func (*ScalarFunction) MarshalJSON Uses

func (sf *ScalarFunction) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*ScalarFunction) ResolveIndices Uses

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

ResolveIndices implements Expression interface.

func (*ScalarFunction) String Uses

func (sf *ScalarFunction) String() string

String implements fmt.Stringer interface.

func (*ScalarFunction) VecEvalDecimal Uses

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

VecEvalDecimal evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalDuration Uses

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

VecEvalDuration evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalInt Uses

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

VecEvalInt evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalJSON Uses

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

VecEvalJSON evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalReal Uses

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

VecEvalReal evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalString Uses

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

VecEvalString evaluates this expression in a vectorized manner.

func (*ScalarFunction) VecEvalTime Uses

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

VecEvalTime evaluates this expression in a vectorized manner.

func (*ScalarFunction) Vectorized Uses

func (sf *ScalarFunction) Vectorized() bool

Vectorized returns if this expression supports vectorized evaluation.

type Schema Uses

type Schema struct {
    Columns []*Column
    Keys    []KeyInfo
}

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

func MergeSchema Uses

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 Uses

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

NewSchema returns a schema made by its parameter.

func TableInfo2SchemaAndNames Uses

func TableInfo2SchemaAndNames(ctx sessionctx.Context, dbName model.CIStr, tbl *model.TableInfo) (*Schema, []*types.FieldName)

TableInfo2SchemaAndNames converts the TableInfo to the schema and name slice.

func (*Schema) Append Uses

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

Append append new column to the columns stored in schema.

func (*Schema) Clone Uses

func (s *Schema) Clone() *Schema

Clone copies the total schema.

func (*Schema) ColumnIndex Uses

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

ColumnIndex finds the index for a column.

func (*Schema) ColumnsByIndices Uses

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 Uses

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 Uses

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

Contains checks if the schema contains the column.

func (*Schema) IsUniqueKey Uses

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

IsUniqueKey checks if this column is a unique key.

func (*Schema) Len Uses

func (s *Schema) Len() int

Len returns the number of columns in schema.

func (*Schema) RetrieveColumn Uses

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

RetrieveColumn retrieves column in expression from the columns in schema.

func (*Schema) SetUniqueKeys Uses

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

SetUniqueKeys will set the value of Schema.Keys.

func (*Schema) String Uses

func (s *Schema) String() string

String implements fmt.Stringer interface.

type VarAssignment Uses

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 Uses

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

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

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

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

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

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

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

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

VecExpr contains all vectorized evaluation methods.

Directories

PathSynopsis
aggregation

Package expression imports 64 packages (graph) and is imported by 458 packages. Updated 2019-11-19. Refresh now. Tools for package owners.