Documentation ¶
Index ¶
- Constants
- Variables
- func CheckArgsNotMultiColumnRow(args ...Expression) error
- func Contains(exprs []Expression, e Expression) bool
- func EvalBool(ctx sessionctx.Context, exprList CNFExprs, row types.Row) (bool, error)
- func ExplainColumnList(cols []*Column) []byte
- func ExplainExpressionList(exprs []Expression) []byte
- func ExprFromSchema(expr Expression, schema *Schema) bool
- func ExpressionsToPB(sc *stmtctx.StatementContext, exprs []Expression, client kv.Client) (pbCNF *tipb.Expr, pushed []Expression, remained []Expression)
- func ExpressionsToPBList(sc *stmtctx.StatementContext, exprs []Expression, client kv.Client) (pbExpr []*tipb.Expr)
- func GetAccurateCmpType(lhs, rhs Expression) types.EvalType
- func GetRowLen(e Expression) int
- func GetTimeValue(ctx sessionctx.Context, v interface{}, tp byte, fsp int) (d types.Datum, err error)
- func GroupByItemToPB(sc *stmtctx.StatementContext, client kv.Client, expr Expression) *tipb.ByItem
- func IsBinaryLiteral(expr Expression) bool
- func IsCurrentTimestampExpr(e ast.ExprNode) bool
- func SetBinFlagOrBinStr(argTp *types.FieldType, resTp *types.FieldType)
- func SortByItemToPB(sc *stmtctx.StatementContext, client kv.Client, expr Expression, desc bool) *tipb.ByItem
- func Vectorizable(exprs []Expression) bool
- func VectorizedExecute(ctx sessionctx.Context, exprs []Expression, iterator *chunk.Iterator4Chunk, ...) error
- func VectorizedFilter(ctx sessionctx.Context, filters []Expression, iterator *chunk.Iterator4Chunk, ...) ([]bool, error)
- type Assignment
- type CNFExprs
- type Column
- func ColInfo2Col(cols []*Column, col *model.ColumnInfo) *Column
- func ColumnInfos2ColumnsWithDBName(dbName, tblName model.CIStr, colInfos []*model.ColumnInfo) []*Column
- func ExtractColumns(expr Expression) (cols []*Column)
- func ExtractColumnsFromExpressions(result []*Column, exprs []Expression, filter func(*Column) bool) []*Column
- func IndexInfo2Cols(cols []*Column, index *model.IndexInfo) ([]*Column, []int)
- func (col *Column) Clone() Expression
- func (col *Column) Decorrelate(_ *Schema) Expression
- func (col *Column) Equal(_ sessionctx.Context, expr Expression) bool
- func (col *Column) Eval(row types.Row) (types.Datum, error)
- func (col *Column) EvalDecimal(ctx sessionctx.Context, row types.Row) (*types.MyDecimal, bool, error)
- func (col *Column) EvalDuration(ctx sessionctx.Context, row types.Row) (types.Duration, bool, error)
- func (col *Column) EvalInt(ctx sessionctx.Context, row types.Row) (int64, bool, error)
- func (col *Column) EvalJSON(ctx sessionctx.Context, row types.Row) (json.BinaryJSON, bool, error)
- func (col *Column) EvalReal(ctx sessionctx.Context, row types.Row) (float64, bool, error)
- func (col *Column) EvalString(ctx sessionctx.Context, row types.Row) (string, bool, error)
- func (col *Column) EvalTime(ctx sessionctx.Context, row types.Row) (types.Time, bool, error)
- func (expr *Column) ExplainInfo() string
- func (col *Column) GetType() *types.FieldType
- func (col *Column) HashCode(_ *stmtctx.StatementContext) []byte
- func (col *Column) IsCorrelated() bool
- func (col *Column) MarshalJSON() ([]byte, error)
- func (col *Column) ResolveIndices(schema *Schema)
- func (col *Column) String() string
- type Constant
- func (c *Constant) Clone() Expression
- func (c *Constant) Decorrelate(_ *Schema) Expression
- func (c *Constant) Equal(ctx sessionctx.Context, b Expression) bool
- func (c *Constant) Eval(_ types.Row) (types.Datum, error)
- func (c *Constant) EvalDecimal(ctx sessionctx.Context, _ types.Row) (*types.MyDecimal, bool, error)
- func (c *Constant) EvalDuration(ctx sessionctx.Context, _ types.Row) (val types.Duration, isNull bool, err error)
- func (c *Constant) EvalInt(ctx sessionctx.Context, _ types.Row) (int64, bool, error)
- func (c *Constant) EvalJSON(ctx sessionctx.Context, _ types.Row) (json.BinaryJSON, bool, error)
- func (c *Constant) EvalReal(ctx sessionctx.Context, _ types.Row) (float64, bool, error)
- func (c *Constant) EvalString(ctx sessionctx.Context, _ types.Row) (string, bool, error)
- func (c *Constant) EvalTime(ctx sessionctx.Context, _ types.Row) (val types.Time, isNull bool, err error)
- func (expr *Constant) ExplainInfo() string
- func (c *Constant) GetType() *types.FieldType
- func (c *Constant) HashCode(sc *stmtctx.StatementContext) []byte
- func (c *Constant) IsCorrelated() bool
- func (c *Constant) MarshalJSON() ([]byte, error)
- func (c *Constant) ResolveIndices(_ *Schema)
- func (c *Constant) String() string
- type CorrelatedColumn
- func (col *CorrelatedColumn) Clone() Expression
- func (col *CorrelatedColumn) Decorrelate(schema *Schema) Expression
- func (col *CorrelatedColumn) Equal(ctx sessionctx.Context, expr Expression) bool
- func (col *CorrelatedColumn) Eval(row types.Row) (types.Datum, error)
- func (col *CorrelatedColumn) EvalDecimal(ctx sessionctx.Context, row types.Row) (*types.MyDecimal, bool, error)
- func (col *CorrelatedColumn) EvalDuration(ctx sessionctx.Context, row types.Row) (types.Duration, bool, error)
- func (col *CorrelatedColumn) EvalInt(ctx sessionctx.Context, row types.Row) (int64, bool, error)
- func (col *CorrelatedColumn) EvalJSON(ctx sessionctx.Context, row types.Row) (json.BinaryJSON, bool, error)
- func (col *CorrelatedColumn) EvalReal(ctx sessionctx.Context, row types.Row) (float64, bool, error)
- func (col *CorrelatedColumn) EvalString(ctx sessionctx.Context, row types.Row) (string, bool, error)
- func (col *CorrelatedColumn) EvalTime(ctx sessionctx.Context, row types.Row) (types.Time, bool, error)
- func (col *CorrelatedColumn) IsCorrelated() bool
- func (col *CorrelatedColumn) ResolveIndices(_ *Schema)
- type EvaluatorSuit
- type Expression
- func BuildCastFunction(ctx sessionctx.Context, expr Expression, tp *types.FieldType) (res Expression)
- func Column2Exprs(cols []*Column) []Expression
- func ColumnSubstitute(expr Expression, schema *Schema, newExprs []Expression) Expression
- func ComposeCNFCondition(ctx sessionctx.Context, conditions ...Expression) Expression
- func ComposeDNFCondition(ctx sessionctx.Context, conditions ...Expression) Expression
- func EvaluateExprWithNull(ctx sessionctx.Context, schema *Schema, expr Expression) Expression
- func ExtractFiltersFromDNFs(ctx sessionctx.Context, conditions []Expression) []Expression
- func Filter(result []Expression, input []Expression, filter func(Expression) bool) []Expression
- func FlattenCNFConditions(CNFCondition *ScalarFunction) []Expression
- func FlattenDNFConditions(DNFCondition *ScalarFunction) []Expression
- func FoldConstant(expr Expression) Expression
- func GetFuncArg(e Expression, idx int) Expression
- func NewFunction(ctx sessionctx.Context, funcName string, retType *types.FieldType, ...) (Expression, error)
- func NewFunctionInternal(ctx sessionctx.Context, funcName string, retType *types.FieldType, ...) Expression
- func PBToExpr(expr *tipb.Expr, tps []*types.FieldType, sc *stmtctx.StatementContext) (Expression, error)
- func ParseSimpleExpr(ctx sessionctx.Context, exprStr string, tableInfo *model.TableInfo) (Expression, error)
- func PopRowFirstArg(ctx sessionctx.Context, e Expression) (ret Expression, err error)
- func PropagateConstant(ctx sessionctx.Context, conditions []Expression) []Expression
- func PushDownNot(ctx sessionctx.Context, expr Expression, not bool) Expression
- func ScalarFuncs2Exprs(funcs []*ScalarFunction) []Expression
- func SplitCNFItems(onExpr Expression) []Expression
- func SplitDNFItems(onExpr Expression) []Expression
- func SubstituteCorCol2Constant(expr Expression) (Expression, error)
- func WrapWithCastAsDecimal(ctx sessionctx.Context, expr Expression) Expression
- func WrapWithCastAsDuration(ctx sessionctx.Context, expr Expression) Expression
- func WrapWithCastAsInt(ctx sessionctx.Context, expr Expression) Expression
- func WrapWithCastAsJSON(ctx sessionctx.Context, expr Expression) Expression
- func WrapWithCastAsReal(ctx sessionctx.Context, expr Expression) Expression
- func WrapWithCastAsString(ctx sessionctx.Context, expr Expression) Expression
- func WrapWithCastAsTime(ctx sessionctx.Context, expr Expression, tp *types.FieldType) Expression
- type KeyInfo
- type PbConverter
- type ScalarFunction
- func (sf *ScalarFunction) Clone() Expression
- func (sf *ScalarFunction) Decorrelate(schema *Schema) Expression
- func (sf *ScalarFunction) Equal(ctx sessionctx.Context, e Expression) bool
- func (sf *ScalarFunction) Eval(row types.Row) (d types.Datum, err error)
- func (sf *ScalarFunction) EvalDecimal(ctx sessionctx.Context, row types.Row) (*types.MyDecimal, bool, error)
- func (sf *ScalarFunction) EvalDuration(ctx sessionctx.Context, row types.Row) (types.Duration, bool, error)
- func (sf *ScalarFunction) EvalInt(ctx sessionctx.Context, row types.Row) (int64, bool, error)
- func (sf *ScalarFunction) EvalJSON(ctx sessionctx.Context, row types.Row) (json.BinaryJSON, bool, error)
- func (sf *ScalarFunction) EvalReal(ctx sessionctx.Context, row types.Row) (float64, bool, error)
- func (sf *ScalarFunction) EvalString(ctx sessionctx.Context, row types.Row) (string, bool, error)
- func (sf *ScalarFunction) EvalTime(ctx sessionctx.Context, row types.Row) (types.Time, bool, error)
- func (expr *ScalarFunction) ExplainInfo() string
- func (sf *ScalarFunction) GetArgs() []Expression
- func (sf *ScalarFunction) GetCtx() sessionctx.Context
- func (sf *ScalarFunction) GetType() *types.FieldType
- func (sf *ScalarFunction) HashCode(sc *stmtctx.StatementContext) []byte
- func (sf *ScalarFunction) IsCorrelated() bool
- func (sf *ScalarFunction) MarshalJSON() ([]byte, error)
- func (sf *ScalarFunction) ResolveIndices(schema *Schema)
- func (sf *ScalarFunction) String() string
- type Schema
- func (s *Schema) Append(col ...*Column)
- func (s *Schema) Clone() *Schema
- func (s *Schema) ColumnIndex(col *Column) int
- func (s *Schema) ColumnsByIndices(offsets []int) []*Column
- func (s *Schema) ColumnsIndices(cols []*Column) (ret []int)
- func (s *Schema) Contains(col *Column) bool
- func (s *Schema) FindColumn(astCol *ast.ColumnName) (*Column, error)
- func (s *Schema) FindColumnAndIndex(astCol *ast.ColumnName) (*Column, int, error)
- func (s *Schema) IsUniqueKey(col *Column) bool
- func (s *Schema) Len() int
- func (s *Schema) RetrieveColumn(col *Column) *Column
- func (s *Schema) SetUniqueKeys(keys []KeyInfo)
- func (s *Schema) String() string
- type VarAssignment
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 ( ErrIncorrectParameterCount = terror.ClassExpression.New(mysql.ErrWrongParamcountToNativeFct, mysql.MySQLErrName[mysql.ErrWrongParamcountToNativeFct]) ErrDivisionByZero = terror.ClassExpression.New(mysql.ErrDivisionByZero, mysql.MySQLErrName[mysql.ErrDivisionByZero]) ErrOperandColumns = terror.ClassExpression.New(mysql.ErrOperandColumns, mysql.MySQLErrName[mysql.ErrOperandColumns]) )
Error instances.
var EvalAstExpr func(ctx sessionctx.Context, expr ast.ExprNode) (types.Datum, error)
EvalAstExpr evaluates ast expression directly.
var MaxPropagateColsCnt = 100
MaxPropagateColsCnt means the max number of columns that can participate propagation.
var UnCacheableFunctions = 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.Database: {}, ast.CurrentUser: {}, ast.User: {}, ast.ConnectionID: {}, ast.LastInsertId: {}, ast.Version: {}, }
UnCacheableFunctions stores functions which can not be cached to plan cache.
Functions ¶
func CheckArgsNotMultiColumnRow ¶
func CheckArgsNotMultiColumnRow(args ...Expression) error
CheckArgsNotMultiColumnRow checks the args are not multi-column row.
func Contains ¶
func Contains(exprs []Expression, e Expression) bool
Contains tests if `exprs` contains `e`.
func ExplainColumnList ¶
ExplainColumnList generates explain information for a list of columns.
func ExplainExpressionList ¶
func ExplainExpressionList(exprs []Expression) []byte
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 ExpressionsToPB ¶
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 ¶
func ExpressionsToPBList(sc *stmtctx.StatementContext, exprs []Expression, client kv.Client) (pbExpr []*tipb.Expr)
ExpressionsToPBList converts expressions to tipb.Expr list for new plan.
func GetAccurateCmpType ¶ added in v1.0.2
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 GetRowLen ¶
func GetRowLen(e Expression) int
GetRowLen gets the length if the func is row, returns 1 if not row.
func GetTimeValue ¶
func GetTimeValue(ctx sessionctx.Context, v interface{}, tp byte, fsp int) (d types.Datum, err error)
GetTimeValue gets the time value with type tp.
func GroupByItemToPB ¶
func GroupByItemToPB(sc *stmtctx.StatementContext, client kv.Client, expr Expression) *tipb.ByItem
GroupByItemToPB converts group by items to pb.
func IsBinaryLiteral ¶
func IsBinaryLiteral(expr Expression) bool
IsBinaryLiteral checks whether an expression is a binary literal
func IsCurrentTimestampExpr ¶
IsCurrentTimestampExpr returns whether e is CurrentTimestamp expression.
func SetBinFlagOrBinStr ¶
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 ¶
func SortByItemToPB(sc *stmtctx.StatementContext, client kv.Client, expr Expression, desc bool) *tipb.ByItem
SortByItemToPB converts order by items to pb.
func Vectorizable ¶
func Vectorizable(exprs []Expression) bool
Vectorizable checks whether a list of expressions can employ vectorized execution.
func VectorizedExecute ¶
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 ¶
func VectorizedFilter(ctx sessionctx.Context, filters []Expression, iterator *chunk.Iterator4Chunk, selected []bool) ([]bool, 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.
Types ¶
type Assignment ¶
type Assignment struct { Col *Column Expr Expression }
Assignment represents a set assignment in Update, such as Update t set c1 = hex(12), c2 = c3 where c2 = 1
type Column ¶
type Column struct { FromID int ColName model.CIStr DBName model.CIStr OrigTblName model.CIStr TblName model.CIStr RetType *types.FieldType ID int64 // Position means the position of this column that appears in the select fields. // e.g. SELECT name as id , 1 - id as id , 1 + name as id, name as id from src having id = 1; // There are four ids in the same schema, so you can't identify the column through the FromID and ColName. Position int // IsAggOrSubq means if this column is referenced to a Aggregation column or a Subquery column. // If so, this column's name will be the plain sql text. IsAggOrSubq bool // Index is only used for execution. Index int // 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 ColumnInfos2ColumnsWithDBName ¶
func ColumnInfos2ColumnsWithDBName(dbName, tblName model.CIStr, colInfos []*model.ColumnInfo) []*Column
ColumnInfos2ColumnsWithDBName converts a slice of ColumnInfo to a slice of Column.
func ExtractColumns ¶
func ExtractColumns(expr Expression) (cols []*Column)
ExtractColumns extracts all columns from an expression.
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 IndexInfo2Cols ¶
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 only the 1st corresponding *Column and its length.
func (*Column) Decorrelate ¶
func (col *Column) Decorrelate(_ *Schema) Expression
Decorrelate implements Expression interface.
func (*Column) Equal ¶
func (col *Column) Equal(_ sessionctx.Context, expr Expression) bool
Equal implements Expression interface.
func (*Column) EvalDecimal ¶
func (col *Column) EvalDecimal(ctx sessionctx.Context, row types.Row) (*types.MyDecimal, bool, error)
EvalDecimal returns decimal representation of Column.
func (*Column) EvalDuration ¶
func (col *Column) EvalDuration(ctx sessionctx.Context, row types.Row) (types.Duration, bool, error)
EvalDuration returns Duration representation of Column.
func (*Column) EvalJSON ¶
func (col *Column) EvalJSON(ctx sessionctx.Context, row types.Row) (json.BinaryJSON, bool, error)
EvalJSON returns JSON representation of Column.
func (*Column) EvalString ¶
EvalString returns string representation of Column.
func (*Column) ExplainInfo ¶
ExplainInfo implements the Expression interface.
func (*Column) HashCode ¶
func (col *Column) HashCode(_ *stmtctx.StatementContext) []byte
HashCode implements Expression interface.
func (*Column) IsCorrelated ¶
IsCorrelated implements Expression interface.
func (*Column) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface.
func (*Column) ResolveIndices ¶
ResolveIndices implements Expression interface.
type Constant ¶
type Constant struct { Value types.Datum RetType *types.FieldType DeferredExpr Expression // parameter getter expression // contains filtered or unexported fields }
Constant stands for a constant value.
func RefineConstantArg ¶ added in v1.0.2
RefineConstantArg changes the constant argument to it's ceiling or flooring result by the given op.
func (*Constant) Clone ¶
func (c *Constant) Clone() Expression
Clone implements Expression interface.
func (*Constant) Decorrelate ¶
func (c *Constant) Decorrelate(_ *Schema) Expression
Decorrelate implements Expression interface.
func (*Constant) Equal ¶
func (c *Constant) Equal(ctx sessionctx.Context, b Expression) bool
Equal implements Expression interface.
func (*Constant) EvalDecimal ¶
EvalDecimal returns decimal representation of Constant.
func (*Constant) EvalDuration ¶
func (c *Constant) EvalDuration(ctx sessionctx.Context, _ types.Row) (val types.Duration, isNull bool, err error)
EvalDuration returns Duration representation of Constant.
func (*Constant) EvalJSON ¶
func (c *Constant) EvalJSON(ctx sessionctx.Context, _ types.Row) (json.BinaryJSON, bool, error)
EvalJSON returns JSON representation of Constant.
func (*Constant) EvalString ¶
EvalString returns string representation of Constant.
func (*Constant) EvalTime ¶
func (c *Constant) EvalTime(ctx sessionctx.Context, _ types.Row) (val types.Time, isNull bool, err error)
EvalTime returns DATE/DATETIME/TIMESTAMP representation of Constant.
func (*Constant) ExplainInfo ¶
ExplainInfo implements the Expression interface.
func (*Constant) HashCode ¶
func (c *Constant) HashCode(sc *stmtctx.StatementContext) []byte
HashCode implements Expression interface.
func (*Constant) IsCorrelated ¶
IsCorrelated implements Expression interface.
func (*Constant) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface.
func (*Constant) ResolveIndices ¶
ResolveIndices implements Expression interface.
type CorrelatedColumn ¶
type CorrelatedColumn struct {}
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) Clone ¶
func (col *CorrelatedColumn) Clone() Expression
Clone implements Expression interface.
func (*CorrelatedColumn) Decorrelate ¶
func (col *CorrelatedColumn) Decorrelate(schema *Schema) Expression
Decorrelate implements Expression interface.
func (*CorrelatedColumn) Equal ¶
func (col *CorrelatedColumn) Equal(ctx sessionctx.Context, expr Expression) bool
Equal implements Expression interface.
func (*CorrelatedColumn) EvalDecimal ¶
func (col *CorrelatedColumn) EvalDecimal(ctx sessionctx.Context, row types.Row) (*types.MyDecimal, bool, error)
EvalDecimal returns decimal representation of CorrelatedColumn.
func (*CorrelatedColumn) EvalDuration ¶
func (col *CorrelatedColumn) EvalDuration(ctx sessionctx.Context, row types.Row) (types.Duration, bool, error)
EvalDuration returns Duration representation of CorrelatedColumn.
func (*CorrelatedColumn) EvalInt ¶
func (col *CorrelatedColumn) EvalInt(ctx sessionctx.Context, row types.Row) (int64, bool, error)
EvalInt returns int representation of CorrelatedColumn.
func (*CorrelatedColumn) EvalJSON ¶
func (col *CorrelatedColumn) EvalJSON(ctx sessionctx.Context, row types.Row) (json.BinaryJSON, bool, error)
EvalJSON returns JSON representation of CorrelatedColumn.
func (*CorrelatedColumn) EvalReal ¶
func (col *CorrelatedColumn) EvalReal(ctx sessionctx.Context, row types.Row) (float64, bool, error)
EvalReal returns real representation of CorrelatedColumn.
func (*CorrelatedColumn) EvalString ¶
func (col *CorrelatedColumn) EvalString(ctx sessionctx.Context, row types.Row) (string, bool, error)
EvalString returns string representation of CorrelatedColumn.
func (*CorrelatedColumn) EvalTime ¶
func (col *CorrelatedColumn) EvalTime(ctx sessionctx.Context, row types.Row) (types.Time, bool, error)
EvalTime returns DATE/DATETIME/TIMESTAMP representation of CorrelatedColumn.
func (*CorrelatedColumn) IsCorrelated ¶
func (col *CorrelatedColumn) IsCorrelated() bool
IsCorrelated implements Expression interface.
func (*CorrelatedColumn) ResolveIndices ¶
func (col *CorrelatedColumn) ResolveIndices(_ *Schema)
ResolveIndices implements Expression interface.
type EvaluatorSuit ¶
type EvaluatorSuit struct {
// contains filtered or unexported fields
}
EvaluatorSuit 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 NewEvaluatorSuit ¶
func NewEvaluatorSuit(exprs []Expression) *EvaluatorSuit
NewEvaluatorSuit creates an EvaluatorSuit to evaluate all the exprs.
func (*EvaluatorSuit) Run ¶
func (e *EvaluatorSuit) Run(ctx sessionctx.Context, input, output *chunk.Chunk) error
Run evaluates all the expressions hold by this EvaluatorSuit. NOTE: "defaultEvaluator" must be evaluated before "columnEvaluator".
type Expression ¶
type Expression interface { fmt.Stringer goJSON.Marshaler // Eval evaluates an expression through a row. Eval(row types.Row) (types.Datum, error) // EvalInt returns the int64 representation of expression. EvalInt(ctx sessionctx.Context, row types.Row) (val int64, isNull bool, err error) // EvalReal returns the float64 representation of expression. EvalReal(ctx sessionctx.Context, row types.Row) (val float64, isNull bool, err error) // EvalString returns the string representation of expression. EvalString(ctx sessionctx.Context, row types.Row) (val string, isNull bool, err error) // EvalDecimal returns the decimal representation of expression. EvalDecimal(ctx sessionctx.Context, row types.Row) (val *types.MyDecimal, isNull bool, err error) // EvalTime returns the DATE/DATETIME/TIMESTAMP representation of expression. EvalTime(ctx sessionctx.Context, row types.Row) (val types.Time, isNull bool, err error) // EvalDuration returns the duration representation of expression. EvalDuration(ctx sessionctx.Context, row types.Row) (val types.Duration, isNull bool, err error) // EvalJSON returns the JSON representation of expression. EvalJSON(ctx sessionctx.Context, row types.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() bool // Decorrelate try to decorrelate the expression by schema. Decorrelate(schema *Schema) Expression // ResolveIndices resolves indices by the given schema. ResolveIndices(schema *Schema) // 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 }
Expression represents all scalar expression in SQL.
func BuildCastFunction ¶
func BuildCastFunction(ctx sessionctx.Context, expr Expression, tp *types.FieldType) (res Expression)
BuildCastFunction builds a CAST ScalarFunction from the Expression.
func Column2Exprs ¶
func Column2Exprs(cols []*Column) []Expression
Column2Exprs will transfer column slice to expression slice.
func ColumnSubstitute ¶
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 ComposeCNFCondition ¶
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 ¶
func ComposeDNFCondition(ctx sessionctx.Context, conditions ...Expression) Expression
ComposeDNFCondition composes DNF items into a balance deep DNF tree.
func EvaluateExprWithNull ¶
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 ¶
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 ¶
func Filter(result []Expression, input []Expression, filter func(Expression) bool) []Expression
Filter the input expressions, append the results to result.
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(expr Expression) Expression
FoldConstant does constant folding optimization on an expression excluding deferred ones.
func GetFuncArg ¶
func GetFuncArg(e Expression, idx int) Expression
GetFuncArg gets the argument of the function at idx.
func NewFunction ¶
func NewFunction(ctx sessionctx.Context, funcName string, retType *types.FieldType, args ...Expression) (Expression, error)
NewFunction creates a new scalar function or constant.
func NewFunctionInternal ¶
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 ¶
func PBToExpr(expr *tipb.Expr, tps []*types.FieldType, sc *stmtctx.StatementContext) (Expression, error)
PBToExpr converts pb structure to expression.
func ParseSimpleExpr ¶
func ParseSimpleExpr(ctx sessionctx.Context, exprStr string, tableInfo *model.TableInfo) (Expression, error)
ParseSimpleExpr parses simple expression string to Expression. The expression string must only reference the column in table Info.
func PopRowFirstArg ¶
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 ¶
func PropagateConstant(ctx sessionctx.Context, conditions []Expression) []Expression
PropagateConstant propagate constant values of equality predicates and inequality predicates in a condition.
func PushDownNot ¶
func PushDownNot(ctx sessionctx.Context, expr Expression, not bool) Expression
PushDownNot pushes the `not` function down to the expression's arguments.
func ScalarFuncs2Exprs ¶
func ScalarFuncs2Exprs(funcs []*ScalarFunction) []Expression
ScalarFuncs2Exprs converts []*ScalarFunction to []Expression.
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(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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 PbConverter ¶
type PbConverter struct {
// contains filtered or unexported fields
}
PbConverter supplys methods to convert TiDB expressions to TiPB.
func NewPBConverter ¶
func NewPBConverter(client kv.Client, sc *stmtctx.StatementContext) PbConverter
NewPBConverter creates a PbConverter.
func (PbConverter) ExprToPB ¶
func (pc PbConverter) ExprToPB(expr Expression) *tipb.Expr
ExprToPB converts Expression to TiPB.
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 Function builtinFunc // contains filtered or unexported fields }
ScalarFunction is the function that returns a value.
func NewValuesFunc ¶
func NewValuesFunc(ctx sessionctx.Context, offset int, retTp *types.FieldType) *ScalarFunction
NewValuesFunc creates a new values function.
func (*ScalarFunction) Clone ¶
func (sf *ScalarFunction) Clone() Expression
Clone implements Expression interface.
func (*ScalarFunction) Decorrelate ¶
func (sf *ScalarFunction) Decorrelate(schema *Schema) Expression
Decorrelate implements Expression interface.
func (*ScalarFunction) Equal ¶
func (sf *ScalarFunction) Equal(ctx sessionctx.Context, e Expression) bool
Equal implements Expression interface.
func (*ScalarFunction) EvalDecimal ¶
func (sf *ScalarFunction) EvalDecimal(ctx sessionctx.Context, row types.Row) (*types.MyDecimal, bool, error)
EvalDecimal implements Expression interface.
func (*ScalarFunction) EvalDuration ¶
func (sf *ScalarFunction) EvalDuration(ctx sessionctx.Context, row types.Row) (types.Duration, bool, error)
EvalDuration implements Expression interface.
func (*ScalarFunction) EvalInt ¶
func (sf *ScalarFunction) EvalInt(ctx sessionctx.Context, row types.Row) (int64, bool, error)
EvalInt implements Expression interface.
func (*ScalarFunction) EvalJSON ¶
func (sf *ScalarFunction) EvalJSON(ctx sessionctx.Context, row types.Row) (json.BinaryJSON, bool, error)
EvalJSON implements Expression interface.
func (*ScalarFunction) EvalReal ¶
func (sf *ScalarFunction) EvalReal(ctx sessionctx.Context, row types.Row) (float64, bool, error)
EvalReal implements Expression interface.
func (*ScalarFunction) EvalString ¶
func (sf *ScalarFunction) EvalString(ctx sessionctx.Context, row types.Row) (string, bool, error)
EvalString implements Expression interface.
func (*ScalarFunction) EvalTime ¶
func (sf *ScalarFunction) EvalTime(ctx sessionctx.Context, row types.Row) (types.Time, bool, error)
EvalTime implements Expression interface.
func (*ScalarFunction) ExplainInfo ¶
func (expr *ScalarFunction) ExplainInfo() string
ExplainInfo implements the Expression interface.
func (*ScalarFunction) GetArgs ¶
func (sf *ScalarFunction) GetArgs() []Expression
GetArgs gets arguments of function.
func (*ScalarFunction) GetCtx ¶
func (sf *ScalarFunction) GetCtx() sessionctx.Context
GetCtx gets the context of function.
func (*ScalarFunction) GetType ¶
func (sf *ScalarFunction) GetType() *types.FieldType
GetType implements Expression interface.
func (*ScalarFunction) HashCode ¶
func (sf *ScalarFunction) HashCode(sc *stmtctx.StatementContext) []byte
HashCode implements Expression interface.
func (*ScalarFunction) IsCorrelated ¶
func (sf *ScalarFunction) IsCorrelated() bool
IsCorrelated implements Expression interface.
func (*ScalarFunction) MarshalJSON ¶
func (sf *ScalarFunction) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler interface.
func (*ScalarFunction) ResolveIndices ¶
func (sf *ScalarFunction) ResolveIndices(schema *Schema)
ResolveIndices implements Expression interface.
func (*ScalarFunction) String ¶
func (sf *ScalarFunction) String() string
String implements fmt.Stringer interface.
type Schema ¶
type Schema struct { Columns []*Column Keys []KeyInfo // TblID2Handle stores the tables' handle column information if we need handle in execution phase. TblID2Handle map[int64][]*Column }
Schema stands for the row schema and unique key information get from input.
func MergeSchema ¶
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 TableInfo2Schema ¶
TableInfo2Schema converts table info to schema with empty DBName.
func TableInfo2SchemaWithDBName ¶
TableInfo2SchemaWithDBName converts table info to schema.
func (*Schema) ColumnIndex ¶
ColumnIndex finds the index for a column.
func (*Schema) ColumnsByIndices ¶
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 ¶
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) FindColumn ¶
func (s *Schema) FindColumn(astCol *ast.ColumnName) (*Column, error)
FindColumn finds an Column from schema for a ast.ColumnName. It compares the db/table/column names. If there are more than one result, it will raise ambiguous error.
func (*Schema) FindColumnAndIndex ¶
FindColumnAndIndex finds an Column and its index from schema for a ast.ColumnName. It compares the db/table/column names. If there are more than one result, raise ambiguous error.
func (*Schema) IsUniqueKey ¶
IsUniqueKey checks if this column is a unique key.
func (*Schema) RetrieveColumn ¶
RetrieveColumn retrieves column in expression from the columns in schema.
func (*Schema) SetUniqueKeys ¶
SetUniqueKeys will set the value of Schema.Keys.
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.
Source Files ¶
- builtin.go
- builtin_arithmetic.go
- builtin_cast.go
- builtin_compare.go
- builtin_control.go
- builtin_encryption.go
- builtin_info.go
- builtin_json.go
- builtin_like.go
- builtin_math.go
- builtin_miscellaneous.go
- builtin_op.go
- builtin_other.go
- builtin_string.go
- builtin_time.go
- chunk_executor.go
- column.go
- constant.go
- constant_fold.go
- constant_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