Skip to content

Commit

Permalink
Merge pull request pingcap#838 from pingcap/qiuyesuifeng/cleanup
Browse files Browse the repository at this point in the history
Tiny clean up.
  • Loading branch information
coocood committed Jan 12, 2016
2 parents 2134e23 + eb5dbcf commit 61a4ce5
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 64 deletions.
2 changes: 1 addition & 1 deletion ast/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func IsPreEvaluable(expr ExprNode) bool {
return expr.GetFlag()|preEvaluable == preEvaluable
}

// IsConstant check if the expression is constant.
// IsConstant checks if the expression is constant.
// A constant expression is safe to be rewritten to value expression.
func IsConstant(expr ExprNode) bool {
return expr.GetFlag() == FlagConstant
Expand Down
43 changes: 25 additions & 18 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,32 @@ func (b *executorBuilder) build(p plan.Plan) Executor {
switch v := p.(type) {
case nil:
return nil
case *plan.TableScan:
return b.buildTableScan(v)
case *plan.ShowDDL:
return b.buildShowDDL(v)
case *plan.Aggregate:
return b.buildAggregate(v)
case *plan.CheckTable:
return b.buildCheckTable(v)
case *plan.IndexScan:
return b.buildIndexScan(v)
case *plan.Deallocate:
return b.buildDeallocate(v)
case *plan.Execute:
return b.buildExecute(v)
case *plan.Filter:
return b.buildFilter(v)
case *plan.SelectLock:
return b.buildSelectLock(v)
case *plan.SelectFields:
return b.buildSelectFields(v)
case *plan.Sort:
return b.buildSort(v)
case *plan.IndexScan:
return b.buildIndexScan(v)
case *plan.Limit:
return b.buildLimit(v)
case *plan.Prepare:
return b.buildPrepare(v)
case *plan.Execute:
return b.buildExecute(v)
case *plan.Deallocate:
return &DeallocateExec{ctx: b.ctx, Name: v.Name}
case *plan.Aggregate:
return b.buildAggregate(v)
case *plan.SelectFields:
return b.buildSelectFields(v)
case *plan.SelectLock:
return b.buildSelectLock(v)
case *plan.ShowDDL:
return b.buildShowDDL(v)
case *plan.Sort:
return b.buildSort(v)
case *plan.TableScan:
return b.buildTableScan(v)
default:
b.err = ErrUnknownPlan.Gen("Unknown Plan %T", p)
return nil
Expand Down Expand Up @@ -102,6 +102,13 @@ func (b *executorBuilder) buildCheckTable(v *plan.CheckTable) Executor {
}
}

func (b *executorBuilder) buildDeallocate(v *plan.Deallocate) Executor {
return &DeallocateExec{
ctx: b.ctx,
Name: v.Name,
}
}

func (b *executorBuilder) buildIndexScan(v *plan.IndexScan) Executor {
tbl, _ := b.is.TableByID(v.Table.ID)
var idx *column.IndexedCol
Expand Down
2 changes: 1 addition & 1 deletion executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var (

// Error codes.
const (
CodeUnknownPlan terror.ErrCode = iota + 1
CodeUnknownPlan terror.ErrCode = iota
CodePrepareMulti
CodeStmtNotFound
CodeSchemaChanged
Expand Down
2 changes: 1 addition & 1 deletion optimizer/evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (

// Error codes.
const (
CodeInvalidOperation terror.ErrCode = iota + 1
CodeInvalidOperation terror.ErrCode = iota
)

// Eval evaluates an expression to a value.
Expand Down
32 changes: 16 additions & 16 deletions optimizer/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,32 @@ func (nr *nameResolver) popJoin() {
// Enter implements ast.Visitor interface.
func (nr *nameResolver) Enter(inNode ast.Node) (outNode ast.Node, skipChildren bool) {
switch v := inNode.(type) {
case *ast.SelectStmt:
case *ast.ByItem:
if _, ok := v.Expr.(*ast.ColumnNameExpr); !ok {
// If ByItem is not a single column name expression,
// the resolving rule is different from order by clause.
nr.currentContext().inByItemExpression = true
}
case *ast.DeleteStmt:
nr.pushContext()
case *ast.TableRefsClause:
nr.currentContext().inTableRefs = true
case *ast.Join:
nr.pushJoin(v)
case *ast.OnCondition:
nr.currentContext().inOnCondition = true
case *ast.FieldList:
nr.currentContext().inFieldList = true
case *ast.GroupByClause:
nr.currentContext().inGroupBy = true
case *ast.HavingClause:
nr.currentContext().inHaving = true
case *ast.OrderByClause:
nr.currentContext().inOrderBy = true
case *ast.ByItem:
if _, ok := v.Expr.(*ast.ColumnNameExpr); !ok {
// If ByItem is not a single column name expression,
// the resolving rule is different from order by clause.
nr.currentContext().inByItemExpression = true
}
case *ast.InsertStmt:
nr.pushContext()
case *ast.DeleteStmt:
case *ast.Join:
nr.pushJoin(v)
case *ast.OnCondition:
nr.currentContext().inOnCondition = true
case *ast.OrderByClause:
nr.currentContext().inOrderBy = true
case *ast.SelectStmt:
nr.pushContext()
case *ast.TableRefsClause:
nr.currentContext().inTableRefs = true
case *ast.UpdateStmt:
nr.pushContext()
}
Expand Down
40 changes: 20 additions & 20 deletions optimizer/typeinferer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,38 @@ func (v *typeInferrer) Enter(in ast.Node) (out ast.Node, skipChildren bool) {

func (v *typeInferrer) Leave(in ast.Node) (out ast.Node, ok bool) {
switch x := in.(type) {
case *ast.ColumnNameExpr:
x.SetType(&x.Refer.Column.FieldType)
case *ast.FuncCastExpr:
x.SetType(x.Tp)
case *ast.SelectStmt:
v.selectStmt(x)
case *ast.ParamMarkerExpr:
x.SetType(types.DefaultTypeForValue(x.GetValue()))
case *ast.BinaryOperationExpr:
v.binaryOperation(x)
case *ast.UnaryOperationExpr:
v.unaryOperation(x)
case *ast.AggregateFuncExpr:
v.aggregateFunc(x)
case *ast.BetweenExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.BinaryOperationExpr:
v.binaryOperation(x)
case *ast.ColumnNameExpr:
x.SetType(&x.Refer.Column.FieldType)
case *ast.CompareSubqueryExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.ExistsSubqueryExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.PatternInExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.PatternLikeExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.PatternRegexpExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.FuncCastExpr:
x.SetType(x.Tp)
case *ast.IsNullExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.IsTruthExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.ParamMarkerExpr:
x.SetType(types.DefaultTypeForValue(x.GetValue()))
case *ast.ParenthesesExpr:
x.SetType(x.Expr.GetType())
case *ast.AggregateFuncExpr:
v.aggregateFunc(x)
case *ast.PatternInExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.PatternLikeExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.PatternRegexpExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.SelectStmt:
v.selectStmt(x)
case *ast.UnaryOperationExpr:
v.unaryOperation(x)
// TODO: handle all expression types.
}
return in, true
Expand Down
15 changes: 8 additions & 7 deletions optimizer/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,26 @@ func (v *validator) Enter(in ast.Node) (out ast.Node, skipChildren bool) {

func (v *validator) Leave(in ast.Node) (out ast.Node, ok bool) {
switch x := in.(type) {
case *ast.IsNullExpr:
v.checkAllOneColumn(x.Expr)
case *ast.IsTruthExpr:
v.checkAllOneColumn(x.Expr)
case *ast.BetweenExpr:
v.checkAllOneColumn(x.Expr, x.Left, x.Right)
case *ast.BinaryOperationExpr:
v.checkBinaryOperation(x)
case *ast.PatternInExpr:
v.checkSameColumns(append(x.List, x.Expr)...)
case *ast.ByItem:
v.checkAllOneColumn(x.Expr)
case *ast.FieldList:
v.checkFieldList(x)
case *ast.ByItem:
case *ast.IsNullExpr:
v.checkAllOneColumn(x.Expr)
case *ast.IsTruthExpr:
v.checkAllOneColumn(x.Expr)
case *ast.ParamMarkerExpr:
if !v.inPrepare {
v.err = parser.ErrSyntax.Gen("syntax error, unexpected '?'")
}
case *ast.PatternInExpr:
v.checkSameColumns(append(x.List, x.Expr)...)
}

return in, v.err == nil
}

Expand Down

0 comments on commit 61a4ce5

Please sign in to comment.