Skip to content

Commit

Permalink
enable vectorized expression evaluation by default
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 committed Sep 1, 2019
1 parent bbb70be commit 9513127
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
3 changes: 3 additions & 0 deletions executor/projection.go
Expand Up @@ -172,6 +172,9 @@ func (e *ProjectionExec) unParallelExecute(ctx context.Context, chk *chunk.Chunk
if err != nil {
return err
}
if e.childResult.NumRows() == 0 {
return nil
}
err = e.evaluatorSuit.Run(e.ctx, e.childResult, chk)
return err
}
Expand Down
6 changes: 4 additions & 2 deletions expression/chunk_executor.go
Expand Up @@ -95,8 +95,10 @@ func evalOneVec(ctx sessionctx.Context, expr Expression, input *chunk.Chunk, out
}
if ft.Tp == mysql.TypeFloat {
f64s := result.Float64s()
buf := chunk.NewColumn(ft, input.NumRows())
buf.ResizeFloat32(input.NumRows())
n := input.NumRows()
buf := chunk.NewColumn(ft, n)
buf.ResizeFloat32(n)
buf.SetNulls(0, n, false)
f32s := buf.Float32s()
for i := range f64s {
if result.IsNull(i) {
Expand Down
5 changes: 4 additions & 1 deletion expression/constant.go
Expand Up @@ -162,7 +162,7 @@ func (c *Constant) VecEvalTime(ctx sessionctx.Context, input *chunk.Chunk, resul
// VecEvalDuration evaluates this expression in a vectorized manner.
func (c *Constant) VecEvalDuration(ctx sessionctx.Context, input *chunk.Chunk, result *chunk.Column) error {
if c.DeferredExpr == nil {
return genVecFromConstExpr(ctx, c, types.ETDecimal, input, result)
return genVecFromConstExpr(ctx, c, types.ETDuration, input, result)
}
return c.DeferredExpr.VecEvalDuration(ctx, input, result)
}
Expand Down Expand Up @@ -443,5 +443,8 @@ func (c *Constant) resolveIndices(_ *Schema) error {

// Vectorized returns if this expression supports vectorized evaluation.
func (c *Constant) Vectorized() bool {
if c.DeferredExpr != nil {
return c.DeferredExpr.Vectorized()
}
return true
}
18 changes: 11 additions & 7 deletions expression/vectorized.go
Expand Up @@ -25,6 +25,10 @@ func genVecFromConstExpr(ctx sessionctx.Context, expr Expression, targetType typ
if input != nil {
n = input.NumRows()
}
if n == 0 {
result.Reset()
return nil
}
switch targetType {
case types.ETInt:
result.ResizeInt64(n)
Expand Down Expand Up @@ -93,13 +97,13 @@ func genVecFromConstExpr(ctx sessionctx.Context, expr Expression, targetType typ
return err
}
if isNull {
for i := 0; i < n; i++ {
result.AppendNull()
}
} else {
for i := 0; i < n; i++ {
result.AppendDuration(v)
}
result.SetNulls(0, n, true)
return nil
}
result.SetNulls(0, n, false)
ds := result.GoDurations()
for i := range ds {
ds[i] = v.Duration
}
case types.ETJson:
result.ReserveJSON(n)
Expand Down
2 changes: 1 addition & 1 deletion sessionctx/variable/tidb_vars.go
Expand Up @@ -347,7 +347,7 @@ const (
DefTiDBForcePriority = mysql.NoPriority
DefTiDBUseRadixJoin = false
DefEnableWindowFunction = true
DefEnableVectorizedExpression = false
DefEnableVectorizedExpression = true
DefTiDBOptJoinReorderThreshold = 0
DefTiDBDDLSlowOprThreshold = 300
DefTiDBUseFastAnalyze = false
Expand Down

0 comments on commit 9513127

Please sign in to comment.