diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 74b0c742ecbd9..491ddf213988c 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1070,6 +1070,20 @@ func (s *testEvaluatorSuite) TestSysDate(c *C) { c.Assert(times[i].String(), GreaterEqual, last.Format(types.TimeFormat)) } + baseFunc, _, input, output = genVecBuiltinFuncBenchCase(ctx, ast.Sysdate, + vecExprBenchCase{ + retEvalType: types.ETDatetime, + childrenTypes: []types.EvalType{types.ETInt}, + geners: []dataGenerator{&rangeInt64Gener{begin: 0, end: 7}}, + }) + resetStmtContext(s.ctx) + loc := ctx.GetSessionVars().Location() + startTm := time.Now().In(loc) + err = baseFunc.vecEvalTime(input, output) + c.Assert(err, IsNil) + for i := 0; i < 1024; i++ { + c.Assert(times[i].String(), GreaterEqual, startTm.Format(types.TimeFormat)) + } } last := time.Now() diff --git a/expression/builtin_time_vec.go b/expression/builtin_time_vec.go index bb89095ef50a5..16e90cb3de2e6 100644 --- a/expression/builtin_time_vec.go +++ b/expression/builtin_time_vec.go @@ -745,11 +745,39 @@ func (b *builtinAddDateStringIntSig) vecEvalTime(input *chunk.Chunk, result *chu } func (b *builtinSysDateWithFspSig) vectorized() bool { - return false + return true } func (b *builtinSysDateWithFspSig) vecEvalTime(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + n := input.NumRows() + buf, err := b.bufAllocator.get(types.ETInt, n) + if err != nil { + return err + } + defer b.bufAllocator.put(buf) + if err = b.args[0].VecEvalInt(b.ctx, input, buf); err != nil { + return err + } + + loc := b.ctx.GetSessionVars().Location() + now := time.Now().In(loc) + + result.ResizeTime(n, false) + result.MergeNulls(buf) + times := result.Times() + ds := buf.Int64s() + + for i := 0; i < n; i++ { + if result.IsNull(i) { + continue + } + t, err := convertTimeToMysqlTime(now, int8(ds[i]), types.ModeHalfEven) + if err != nil { + return err + } + times[i] = t + } + return nil } func (b *builtinAddDateDurationIntSig) vectorized() bool { diff --git a/expression/builtin_time_vec_test.go b/expression/builtin_time_vec_test.go index dd742b73a243f..3b6bb3f799212 100644 --- a/expression/builtin_time_vec_test.go +++ b/expression/builtin_time_vec_test.go @@ -223,6 +223,8 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{ // we cannot use the vectorized test framework to test builtinSysDateWithoutFspSig. // We test the builtinSysDateWithoutFspSig in TestSysDate function. // {retEvalType: types.ETDatetime}, + // {retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETInt}, + // geners: []dataGenerator{&rangeInt64Gener{begin: 0, end: 7}}}, }, }