expression: implement vectorized evaluation for builtinToSecondsSig (#13067)

This commit is contained in:
shihongzhi
2019-11-02 12:26:03 +08:00
committed by pingcap-github-bot
parent 035fe071a2
commit 5b161df353
2 changed files with 36 additions and 2 deletions

View File

@ -581,11 +581,42 @@ func (b *builtinSubTimeDateTimeNullSig) vecEvalTime(input *chunk.Chunk, result *
}
func (b *builtinToSecondsSig) vectorized() bool {
return false
return true
}
// evalInt evals a builtinToSecondsSig.
// See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_to-seconds
func (b *builtinToSecondsSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETDatetime, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalTime(b.ctx, input, buf); err != nil {
return err
}
result.ResizeInt64(n, false)
result.MergeNulls(buf)
i64s := result.Int64s()
ds := buf.Times()
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
arg := ds[i]
ret := types.TimestampDiff("SECOND", types.ZeroDate, arg)
if ret == 0 {
if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())); err != nil {
return err
}
result.SetNull(i, true)
continue
}
i64s[i] = ret
}
return nil
}
func (b *builtinSubDurationAndStringSig) vectorized() bool {

View File

@ -38,6 +38,9 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
ast.Second: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDuration}, geners: []dataGenerator{&rangeDurationGener{0.2}}},
},
ast.ToSeconds: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDatetime}},
},
ast.MicroSecond: {},
ast.Now: {},
ast.DayOfWeek: {