Documentation ¶
Index ¶
- Constants
- Variables
- func AggFuncToPBExpr(sc *variable.StatementContext, client kv.Client, aggFunc AggregationFunction) *tipb.Expr
- func EvalBool(exprList CNFExprs, row []types.Datum, ctx context.Context) (bool, error)
- func ExplainAggFunc(agg AggregationFunction) string
- func ExplainColumnList(cols []*Column) []byte
- func ExplainExpressionList(exprs []Expression) []byte
- func ExprFromSchema(expr Expression, schema *Schema) bool
- func ExpressionsToPB(sc *variable.StatementContext, exprs []Expression, client kv.Client) (pbExpr *tipb.Expr, pushed []Expression, remained []Expression)
- func ExpressionsToPBList(sc *variable.StatementContext, exprs []Expression, client kv.Client) (pbExpr []*tipb.Expr)
- func GetTimeValue(ctx context.Context, v interface{}, tp byte, fsp int) (types.Datum, error)
- func GroupByItemToPB(sc *variable.StatementContext, client kv.Client, expr Expression) *tipb.ByItem
- func InferType(sc *variable.StatementContext, node ast.Node) error
- func IsCurrentTimeExpr(e ast.ExprNode) bool
- func IsHybridType(expr Expression) bool
- func SetBinFlagOrBinStr(argTp *types.FieldType, resTp *types.FieldType)
- func SortByItemToPB(sc *variable.StatementContext, client kv.Client, expr Expression, desc bool) *tipb.ByItem
- type AggFunctionMode
- type AggregationFunction
- type Assignment
- type CNFExprs
- type Column
- func (col *Column) Clone() Expression
- func (col *Column) Decorrelate(_ *Schema) Expression
- func (col *Column) Equal(expr Expression, _ context.Context) bool
- func (col *Column) Eval(row []types.Datum) (types.Datum, error)
- func (col *Column) EvalDecimal(row []types.Datum, sc *variable.StatementContext) (*types.MyDecimal, bool, error)
- func (col *Column) EvalDuration(row []types.Datum, sc *variable.StatementContext) (types.Duration, bool, error)
- func (col *Column) EvalInt(row []types.Datum, sc *variable.StatementContext) (int64, bool, error)
- func (col *Column) EvalJSON(row []types.Datum, sc *variable.StatementContext) (json.JSON, bool, error)
- func (col *Column) EvalReal(row []types.Datum, sc *variable.StatementContext) (float64, bool, error)
- func (col *Column) EvalString(row []types.Datum, sc *variable.StatementContext) (string, bool, error)
- func (col *Column) EvalTime(row []types.Datum, sc *variable.StatementContext) (types.Time, bool, error)
- func (expr *Column) ExplainInfo() string
- func (col *Column) GetType() *types.FieldType
- func (col *Column) GetTypeClass() types.TypeClass
- func (col *Column) HashCode() []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(b Expression, ctx context.Context) bool
- func (c *Constant) Eval(_ []types.Datum) (types.Datum, error)
- func (c *Constant) EvalDecimal(_ []types.Datum, sc *variable.StatementContext) (*types.MyDecimal, bool, error)
- func (c *Constant) EvalDuration(_ []types.Datum, sc *variable.StatementContext) (val types.Duration, isNull bool, err error)
- func (c *Constant) EvalInt(_ []types.Datum, sc *variable.StatementContext) (int64, bool, error)
- func (c *Constant) EvalJSON(_ []types.Datum, sc *variable.StatementContext) (json.JSON, bool, error)
- func (c *Constant) EvalReal(_ []types.Datum, sc *variable.StatementContext) (float64, bool, error)
- func (c *Constant) EvalString(_ []types.Datum, sc *variable.StatementContext) (string, bool, error)
- func (c *Constant) EvalTime(_ []types.Datum, sc *variable.StatementContext) (val types.Time, isNull bool, err error)
- func (expr *Constant) ExplainInfo() string
- func (c *Constant) GetType() *types.FieldType
- func (c *Constant) GetTypeClass() types.TypeClass
- func (c *Constant) HashCode() []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(expr Expression, ctx context.Context) bool
- func (col *CorrelatedColumn) Eval(row []types.Datum) (types.Datum, error)
- func (col *CorrelatedColumn) EvalDecimal(row []types.Datum, sc *variable.StatementContext) (*types.MyDecimal, bool, error)
- func (col *CorrelatedColumn) EvalDuration(row []types.Datum, sc *variable.StatementContext) (types.Duration, bool, error)
- func (col *CorrelatedColumn) EvalInt(row []types.Datum, sc *variable.StatementContext) (int64, bool, error)
- func (col *CorrelatedColumn) EvalJSON(row []types.Datum, sc *variable.StatementContext) (json.JSON, bool, error)
- func (col *CorrelatedColumn) EvalReal(row []types.Datum, sc *variable.StatementContext) (float64, bool, error)
- func (col *CorrelatedColumn) EvalString(row []types.Datum, sc *variable.StatementContext) (string, bool, error)
- func (col *CorrelatedColumn) EvalTime(row []types.Datum, sc *variable.StatementContext) (types.Time, bool, error)
- func (col *CorrelatedColumn) IsCorrelated() bool
- func (col *CorrelatedColumn) ResolveIndices(_ *Schema)
- type Expression
- func Column2Exprs(cols []*Column) []Expression
- func ColumnSubstitute(expr Expression, schema *Schema, newExprs []Expression) Expression
- func ComposeCNFCondition(ctx context.Context, conditions ...Expression) Expression
- func ComposeDNFCondition(ctx context.Context, conditions ...Expression) Expression
- func ConvertCol2CorCol(cond Expression, corCols []*CorrelatedColumn, outerSchema *Schema) Expression
- func EvaluateExprWithNull(ctx context.Context, schema *Schema, expr Expression) (Expression, error)
- func FoldConstant(expr Expression) Expression
- func NewCastFunc(tp *types.FieldType, arg Expression, ctx context.Context) Expression
- func NewFunction(ctx context.Context, funcName string, retType *types.FieldType, ...) (Expression, error)
- func PBToExpr(expr *tipb.Expr, tps []*types.FieldType, sc *variable.StatementContext) (Expression, error)
- func PropagateConstant(ctx context.Context, conditions []Expression) []Expression
- func PushDownNot(expr Expression, not bool, ctx context.Context) Expression
- func ScalarFuncs2Exprs(funcs []*ScalarFunction) []Expression
- func SplitCNFItems(onExpr Expression) []Expression
- func SplitDNFItems(onExpr Expression) []Expression
- func SubstituteCorCol2Constant(expr Expression) (Expression, error)
- func WrapWithCastAsDecimal(expr Expression, ctx context.Context) Expression
- func WrapWithCastAsDuration(expr Expression, ctx context.Context) Expression
- func WrapWithCastAsInt(expr Expression, ctx context.Context) Expression
- func WrapWithCastAsJSON(expr Expression, ctx context.Context) Expression
- func WrapWithCastAsReal(expr Expression, ctx context.Context) Expression
- func WrapWithCastAsString(expr Expression, ctx context.Context) Expression
- func WrapWithCastAsTime(expr Expression, tp *types.FieldType, ctx context.Context) Expression
- type KeyInfo
- type ScalarFunction
- func (sf *ScalarFunction) Clone() Expression
- func (sf *ScalarFunction) Decorrelate(schema *Schema) Expression
- func (sf *ScalarFunction) Equal(e Expression, ctx context.Context) bool
- func (sf *ScalarFunction) Eval(row []types.Datum) (d types.Datum, err error)
- func (sf *ScalarFunction) EvalDecimal(row []types.Datum, sc *variable.StatementContext) (*types.MyDecimal, bool, error)
- func (sf *ScalarFunction) EvalDuration(row []types.Datum, sc *variable.StatementContext) (types.Duration, bool, error)
- func (sf *ScalarFunction) EvalInt(row []types.Datum, sc *variable.StatementContext) (int64, bool, error)
- func (sf *ScalarFunction) EvalJSON(row []types.Datum, sc *variable.StatementContext) (json.JSON, bool, error)
- func (sf *ScalarFunction) EvalReal(row []types.Datum, sc *variable.StatementContext) (float64, bool, error)
- func (sf *ScalarFunction) EvalString(row []types.Datum, sc *variable.StatementContext) (string, bool, error)
- func (sf *ScalarFunction) EvalTime(row []types.Datum, sc *variable.StatementContext) (types.Time, bool, error)
- func (expr *ScalarFunction) ExplainInfo() string
- func (sf *ScalarFunction) GetArgs() []Expression
- func (sf *ScalarFunction) GetCtx() context.Context
- func (sf *ScalarFunction) GetType() *types.FieldType
- func (sf *ScalarFunction) GetTypeClass() types.TypeClass
- func (sf *ScalarFunction) HashCode() []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 int = 0 SHA224 int = 224 SHA256 int = 256 SHA384 int = 384 SHA512 int = 512 )
Supported hash length of SHA-2 family
Variables ¶
var ( // CurrentTimestamp is the keyword getting default value for datetime and timestamp type. CurrentTimestamp = "CURRENT_TIMESTAMP" // ZeroTimestamp shows the zero datetime and timestamp. ZeroTimestamp = "0000-00-00 00:00:00" )
var (
ErrIncorrectParameterCount = terror.ClassExpression.New(codeIncorrectParameterCount, "Incorrect parameter count in the call to native function '%s'")
)
Error instances.
EvalAstExpr evaluates ast expression directly.
var MaxPropagateColsCnt = 100
MaxPropagateColsCnt means the max number of columns that can participate propagation.
var Null = &Constant{ Value: types.NewDatum(nil), RetType: types.NewFieldType(mysql.TypeTiny), }
Null stands for null constant.
var One = &Constant{ Value: types.NewDatum(1), RetType: types.NewFieldType(mysql.TypeTiny), }
One stands for a number 1.
var TurnOnNewExprEval int32
TurnOnNewExprEval indicates whether turn on the new expression evaluation architecture.
var Zero = &Constant{ Value: types.NewDatum(0), RetType: types.NewFieldType(mysql.TypeTiny), }
Zero stands for a number 0.
Functions ¶
func AggFuncToPBExpr ¶
func AggFuncToPBExpr(sc *variable.StatementContext, client kv.Client, aggFunc AggregationFunction) *tipb.Expr
AggFuncToPBExpr converts aggregate function to pb.
func ExplainAggFunc ¶
func ExplainAggFunc(agg AggregationFunction) string
ExplainAggFunc generates explain information for a aggregation function.
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 *variable.StatementContext, exprs []Expression, client kv.Client) (pbExpr *tipb.Expr, pushed []Expression, remained []Expression)
ExpressionsToPB converts expression to tipb.Expr.
func ExpressionsToPBList ¶
func ExpressionsToPBList(sc *variable.StatementContext, exprs []Expression, client kv.Client) (pbExpr []*tipb.Expr)
ExpressionsToPBList converts expressions to tipb.Expr list for new plan.
func GetTimeValue ¶
GetTimeValue gets the time value with type tp.
func GroupByItemToPB ¶
func GroupByItemToPB(sc *variable.StatementContext, client kv.Client, expr Expression) *tipb.ByItem
GroupByItemToPB converts group by items to pb.
func InferType ¶
func InferType(sc *variable.StatementContext, node ast.Node) error
InferType infers result type for ast.ExprNode.
func IsCurrentTimeExpr ¶
IsCurrentTimeExpr returns whether e is CurrentTimeExpr.
func IsHybridType ¶
func IsHybridType(expr Expression) bool
IsHybridType checks whether a ClassString expression is a hybrid type value which will return different types of value in different context.
For ENUM/SET which is consist of a string attribute `Name` and an int attribute `Value`, it will cause an error if we convert ENUM/SET to int as a string value.
For BinaryLiteral/MysqlBit, we will get a wrong result if we convert it to int as a string value. For example, when convert `0b101` to int, the result should be 5, but we will get 101 if we regard it as a string.
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 *variable.StatementContext, client kv.Client, expr Expression, desc bool) *tipb.ByItem
SortByItemToPB converts order by items to pb.
Types ¶
type AggFunctionMode ¶
type AggFunctionMode int
AggFunctionMode stands for the aggregation function's mode.
const ( // CompleteMode function accepts origin data. CompleteMode AggFunctionMode = iota // FinalMode function accepts partial data. FinalMode )
type AggregationFunction ¶
type AggregationFunction interface { fmt.Stringer json.Marshaler // Update during executing. Update(row []types.Datum, groupKey []byte, sc *variable.StatementContext) error // GetPartialResult will called by coprocessor to get partial results. For avg function, partial results will return // sum and count values at the same time. GetPartialResult(groupKey []byte) []types.Datum // StreamUpdate updates data using streaming algo. StreamUpdate(row []types.Datum, sc *variable.StatementContext) error // SetMode sets aggFunctionMode for aggregate function. SetMode(mode AggFunctionMode) // GetMode gets aggFunctionMode from aggregate function. GetMode() AggFunctionMode // GetGroupResult will be called when all data have been processed. GetGroupResult(groupKey []byte) types.Datum // GetStreamResult gets a result using streaming agg. GetStreamResult() types.Datum // GetArgs stands for getting all arguments. GetArgs() []Expression // GetName gets the aggregation function name. GetName() string // SetArgs sets argument by index. SetArgs(args []Expression) // Reset resets this aggregate function. Reset() // IsDistinct indicates if the aggregate function contains distinct attribute. IsDistinct() bool // SetContext sets the aggregate evaluation context. SetContext(ctx map[string](*aggEvaluateContext)) // Equal checks whether two aggregation functions are equal. Equal(agg AggregationFunction, ctx context.Context) bool // Clone copies an aggregate function totally. Clone() AggregationFunction // GetType gets field type of aggregate function. GetType() *types.FieldType // CalculateDefaultValue gets the default value when the aggregate function's input is null. // The input stands for the schema of Aggregation's child. If the function can't produce a default value, the second // return value will be false. CalculateDefaultValue(schema *Schema, ctx context.Context) (types.Datum, bool) }
AggregationFunction stands for aggregate functions.
func NewAggFunction ¶
func NewAggFunction(funcType string, funcArgs []Expression, distinct bool) AggregationFunction
NewAggFunction creates a new AggregationFunction.
func NewDistAggFunc ¶
func NewDistAggFunc(expr *tipb.Expr, fieldTps []*types.FieldType, sc *variable.StatementContext) (AggregationFunction, error)
NewDistAggFunc creates new Aggregate function for mock tikv.
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 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 ColumnInfos2Columns ¶
func ColumnInfos2Columns(tblName model.CIStr, colInfos []*model.ColumnInfo) []*Column
ColumnInfos2Columns 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 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(expr Expression, _ context.Context) bool
Equal implements Expression interface.
func (*Column) EvalDecimal ¶
func (col *Column) EvalDecimal(row []types.Datum, sc *variable.StatementContext) (*types.MyDecimal, bool, error)
EvalDecimal returns decimal representation of Column.
func (*Column) EvalDuration ¶
func (col *Column) EvalDuration(row []types.Datum, sc *variable.StatementContext) (types.Duration, bool, error)
EvalDuration returns Duration representation of Column.
func (*Column) EvalJSON ¶
func (col *Column) EvalJSON(row []types.Datum, sc *variable.StatementContext) (json.JSON, bool, error)
EvalJSON returns JSON representation of Column.
func (*Column) EvalReal ¶
func (col *Column) EvalReal(row []types.Datum, sc *variable.StatementContext) (float64, bool, error)
EvalReal returns real representation of Column.
func (*Column) EvalString ¶
func (col *Column) EvalString(row []types.Datum, sc *variable.StatementContext) (string, bool, error)
EvalString returns string representation of Column.
func (*Column) EvalTime ¶
func (col *Column) EvalTime(row []types.Datum, sc *variable.StatementContext) (types.Time, bool, error)
EvalTime returns DATE/DATETIME/TIMESTAMP representation of Column.
func (*Column) ExplainInfo ¶
ExplainInfo implements the Expression interface.
func (*Column) GetTypeClass ¶
GetTypeClass 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 ¶
Constant stands for a constant value.
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(b Expression, ctx context.Context) bool
Equal implements Expression interface.
func (*Constant) EvalDecimal ¶
func (c *Constant) EvalDecimal(_ []types.Datum, sc *variable.StatementContext) (*types.MyDecimal, bool, error)
EvalDecimal returns decimal representation of Constant.
func (*Constant) EvalDuration ¶
func (c *Constant) EvalDuration(_ []types.Datum, sc *variable.StatementContext) (val types.Duration, isNull bool, err error)
EvalDuration returns Duration representation of Constant.
func (*Constant) EvalJSON ¶
func (c *Constant) EvalJSON(_ []types.Datum, sc *variable.StatementContext) (json.JSON, bool, error)
EvalJSON returns JSON representation of Constant.
func (*Constant) EvalString ¶
EvalString returns string representation of Constant.
func (*Constant) EvalTime ¶
func (c *Constant) EvalTime(_ []types.Datum, sc *variable.StatementContext) (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) GetTypeClass ¶
GetTypeClass 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 (*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(expr Expression, ctx context.Context) bool
Equal implements Expression interface.
func (*CorrelatedColumn) EvalDecimal ¶
func (col *CorrelatedColumn) EvalDecimal(row []types.Datum, sc *variable.StatementContext) (*types.MyDecimal, bool, error)
EvalDecimal returns decimal representation of CorrelatedColumn.
func (*CorrelatedColumn) EvalDuration ¶
func (col *CorrelatedColumn) EvalDuration(row []types.Datum, sc *variable.StatementContext) (types.Duration, bool, error)
EvalDuration returns Duration representation of CorrelatedColumn.
func (*CorrelatedColumn) EvalInt ¶
func (col *CorrelatedColumn) EvalInt(row []types.Datum, sc *variable.StatementContext) (int64, bool, error)
EvalInt returns int representation of CorrelatedColumn.
func (*CorrelatedColumn) EvalJSON ¶
func (col *CorrelatedColumn) EvalJSON(row []types.Datum, sc *variable.StatementContext) (json.JSON, bool, error)
EvalJSON returns JSON representation of CorrelatedColumn.
func (*CorrelatedColumn) EvalReal ¶
func (col *CorrelatedColumn) EvalReal(row []types.Datum, sc *variable.StatementContext) (float64, bool, error)
EvalReal returns real representation of CorrelatedColumn.
func (*CorrelatedColumn) EvalString ¶
func (col *CorrelatedColumn) EvalString(row []types.Datum, sc *variable.StatementContext) (string, bool, error)
EvalString returns string representation of CorrelatedColumn.
func (*CorrelatedColumn) EvalTime ¶
func (col *CorrelatedColumn) EvalTime(row []types.Datum, sc *variable.StatementContext) (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 Expression ¶
type Expression interface { fmt.Stringer goJSON.Marshaler // Eval evaluates an expression through a row. Eval(row []types.Datum) (types.Datum, error) // EvalInt returns the int64 representation of expression. EvalInt(row []types.Datum, sc *variable.StatementContext) (val int64, isNull bool, err error) // EvalReal returns the float64 representation of expression. EvalReal(row []types.Datum, sc *variable.StatementContext) (val float64, isNull bool, err error) // EvalString returns the string representation of expression. EvalString(row []types.Datum, sc *variable.StatementContext) (val string, isNull bool, err error) // EvalDecimal returns the decimal representation of expression. EvalDecimal(row []types.Datum, sc *variable.StatementContext) (val *types.MyDecimal, isNull bool, err error) // EvalTime returns the DATE/DATETIME/TIMESTAMP representation of expression. EvalTime(row []types.Datum, sc *variable.StatementContext) (val types.Time, isNull bool, err error) // EvalDuration returns the duration representation of expression. EvalDuration(row []types.Datum, sc *variable.StatementContext) (val types.Duration, isNull bool, err error) // EvalJSON returns the JSON representation of expression. EvalJSON(row []types.Datum, sc *variable.StatementContext) (val json.JSON, isNull bool, err error) // GetType gets the type that the expression returns. GetType() *types.FieldType // GetTypeClass gets the TypeClass that the expression returns. GetTypeClass() types.TypeClass // Clone copies an expression totally. Clone() Expression // HashCode create the hashcode for expression HashCode() []byte // Equal checks whether two expressions are equal. Equal(e Expression, ctx context.Context) 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 }
Expression represents all scalar expression in SQL.
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 context.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 context.Context, conditions ...Expression) Expression
ComposeDNFCondition composes DNF items into a balance deep DNF tree.
func ConvertCol2CorCol ¶
func ConvertCol2CorCol(cond Expression, corCols []*CorrelatedColumn, outerSchema *Schema) Expression
ConvertCol2CorCol will convert the column in the condition which can be found in outerSchema to a correlated column whose Column is this column. And please make sure the outerSchema.Columns[i].Equal(corCols[i].Column)) holds when you call this.
func EvaluateExprWithNull ¶
func EvaluateExprWithNull(ctx context.Context, schema *Schema, expr Expression) (Expression, error)
EvaluateExprWithNull sets columns in schema as null and calculate the final result of the scalar function. If the Expression is a non-constant value, it means the result is unknown.
func FoldConstant ¶
func FoldConstant(expr Expression) Expression
FoldConstant does constant folding optimization on an expression.
func NewCastFunc ¶
func NewCastFunc(tp *types.FieldType, arg Expression, ctx context.Context) Expression
NewCastFunc creates a new cast function.
func NewFunction ¶
func NewFunction(ctx context.Context, funcName string, retType *types.FieldType, args ...Expression) (Expression, error)
NewFunction creates a new scalar function or constant.
func PBToExpr ¶
func PBToExpr(expr *tipb.Expr, tps []*types.FieldType, sc *variable.StatementContext) (Expression, error)
PBToExpr converts pb structure to expression.
func PropagateConstant ¶
func PropagateConstant(ctx context.Context, conditions []Expression) []Expression
PropagateConstant propagate constant values of equality predicates and inequality predicates in a condition.
func PushDownNot ¶
func PushDownNot(expr Expression, not bool, ctx context.Context) 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(expr Expression, ctx context.Context) Expression
WrapWithCastAsDecimal wraps `expr` with `cast` if the return type of expr is not type decimal, otherwise, returns `expr` directly.
func WrapWithCastAsDuration ¶
func WrapWithCastAsDuration(expr Expression, ctx context.Context) Expression
WrapWithCastAsDuration wraps `expr` with `cast` if the return type of expr is not type duration, otherwise, returns `expr` directly.
func WrapWithCastAsInt ¶
func WrapWithCastAsInt(expr Expression, ctx context.Context) Expression
WrapWithCastAsInt wraps `expr` with `cast` if the return type of expr is not type int, otherwise, returns `expr` directly.
func WrapWithCastAsJSON ¶
func WrapWithCastAsJSON(expr Expression, ctx context.Context) Expression
WrapWithCastAsJSON wraps `expr` with `cast` if the return type of expr is not type json, otherwise, returns `expr` directly.
func WrapWithCastAsReal ¶
func WrapWithCastAsReal(expr Expression, ctx context.Context) Expression
WrapWithCastAsReal wraps `expr` with `cast` if the return type of expr is not type real, otherwise, returns `expr` directly.
func WrapWithCastAsString ¶
func WrapWithCastAsString(expr Expression, ctx context.Context) Expression
WrapWithCastAsString wraps `expr` with `cast` if the return type of expr is not type string, otherwise, returns `expr` directly.
func WrapWithCastAsTime ¶
func WrapWithCastAsTime(expr Expression, tp *types.FieldType, ctx context.Context) 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 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 }
ScalarFunction is the function that returns a value.
func NewValuesFunc ¶
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(e Expression, ctx context.Context) bool
Equal implements Expression interface.
func (*ScalarFunction) EvalDecimal ¶
func (sf *ScalarFunction) EvalDecimal(row []types.Datum, sc *variable.StatementContext) (*types.MyDecimal, bool, error)
EvalDecimal implements Expression interface.
func (*ScalarFunction) EvalDuration ¶
func (sf *ScalarFunction) EvalDuration(row []types.Datum, sc *variable.StatementContext) (types.Duration, bool, error)
EvalDuration implements Expression interface.
func (*ScalarFunction) EvalInt ¶
func (sf *ScalarFunction) EvalInt(row []types.Datum, sc *variable.StatementContext) (int64, bool, error)
EvalInt implements Expression interface.
func (*ScalarFunction) EvalJSON ¶
func (sf *ScalarFunction) EvalJSON(row []types.Datum, sc *variable.StatementContext) (json.JSON, bool, error)
EvalJSON implements Expression interface.
func (*ScalarFunction) EvalReal ¶
func (sf *ScalarFunction) EvalReal(row []types.Datum, sc *variable.StatementContext) (float64, bool, error)
EvalReal implements Expression interface.
func (*ScalarFunction) EvalString ¶
func (sf *ScalarFunction) EvalString(row []types.Datum, sc *variable.StatementContext) (string, bool, error)
EvalString implements Expression interface.
func (*ScalarFunction) EvalTime ¶
func (sf *ScalarFunction) EvalTime(row []types.Datum, sc *variable.StatementContext) (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() context.Context
GetCtx gets the context of function.
func (*ScalarFunction) GetType ¶
func (sf *ScalarFunction) GetType() *types.FieldType
GetType implements Expression interface.
func (*ScalarFunction) GetTypeClass ¶
func (sf *ScalarFunction) GetTypeClass() types.TypeClass
GetTypeClass implements Expression interface.
func (*ScalarFunction) HashCode ¶
func (sf *ScalarFunction) HashCode() []byte
HashCode implements Expression interface.
func (*ScalarFunction) IsCorrelated ¶
func (sf *ScalarFunction) IsCorrelated() bool
IsCorrelated implements Expression interface.
func (*ScalarFunction) 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 MaxOneRow bool }
Schema stands for the row schema and unique key information get from input.
func MergeSchema ¶
MergeSchema will merge two schema into one schema.
func TableInfo2Schema ¶
TableInfo2Schema 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 ¶
- aggregation.go
- 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
- column.go
- constant_fold.go
- constant_propagation.go
- distsql_builtin.go
- explain.go
- expr_to_pb.go
- expression.go
- helper.go
- scalar_function.go
- schema.go
- typeinferer.go
- util.go