expression: implement vectorized evaluation for builtinWeekWithoutModeSig (#13535)

This commit is contained in:
Lanearth
2019-11-19 10:13:23 +08:00
committed by pingcap-github-bot
parent 9a7e382bc5
commit 14e7ff10a0
2 changed files with 44 additions and 2 deletions

View File

@ -15,10 +15,12 @@ package expression
import (
"math"
"strconv"
"time"
"github.com/pingcap/errors"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
)
@ -1416,11 +1418,50 @@ func (b *builtinUTCDateSig) vecEvalTime(input *chunk.Chunk, result *chunk.Column
}
func (b *builtinWeekWithoutModeSig) vectorized() bool {
return false
return true
}
func (b *builtinWeekWithoutModeSig) 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
}
if err := b.args[0].VecEvalTime(b.ctx, input, buf); err != nil {
return err
}
defer b.bufAllocator.put(buf)
result.ResizeInt64(n, false)
result.MergeNulls(buf)
i64s := result.Int64s()
ds := buf.Times()
mode := 0
modeStr, ok := b.ctx.GetSessionVars().GetSystemVar(variable.DefaultWeekFormat)
if ok && modeStr != "" {
mode, err = strconv.Atoi(modeStr)
if err != nil {
return handleInvalidTimeError(b.ctx, types.ErrInvalidWeekModeFormat.GenWithStackByArgs(modeStr))
}
}
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
date := ds[i]
if date.IsZero() {
if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())); err != nil {
return err
}
result.SetNull(i, true)
continue
}
week := date.Time.Week(mode)
i64s[i] = int64(week)
}
return nil
}
func (b *builtinUnixTimestampDecSig) vectorized() bool {

View File

@ -147,6 +147,7 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
},
},
ast.Week: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDatetime}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDatetime, types.ETInt}},
},
ast.Month: {