diff --git a/expression/builtin_time_vec.go b/expression/builtin_time_vec.go index 264b6a70d697f..4e6daf60168fc 100644 --- a/expression/builtin_time_vec.go +++ b/expression/builtin_time_vec.go @@ -676,14 +676,6 @@ func (b *builtinTimeToSecSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colum return errors.Errorf("not implemented") } -func (b *builtinDayOfMonthSig) vectorized() bool { - return false -} - -func (b *builtinDayOfMonthSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") -} - func (b *builtinStrToDateDatetimeSig) vectorized() bool { return false } @@ -1243,3 +1235,41 @@ func (b *builtinTimestamp2ArgsSig) vecEvalTime(input *chunk.Chunk, result *chunk func (b *builtinTimestamp2ArgsSig) vectorized() bool { return true } + +func (b *builtinDayOfMonthSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error { + 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 + } + if ds[i].IsZero() { + if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { + if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil { + return err + } + result.SetNull(i, true) + continue + } + i64s[i] = 0 + continue + } + i64s[i] = int64(ds[i].Time.Day()) + } + return nil +} + +func (b *builtinDayOfMonthSig) vectorized() bool { + return true +} diff --git a/expression/builtin_time_vec_test.go b/expression/builtin_time_vec_test.go index cfe774cc637a2..ddf09ea4df361 100644 --- a/expression/builtin_time_vec_test.go +++ b/expression/builtin_time_vec_test.go @@ -34,7 +34,6 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{ ast.Second: {}, ast.MicroSecond: {}, ast.Now: {}, - ast.DayOfMonth: {}, ast.DayOfWeek: {}, ast.DayOfYear: {}, ast.Day: {}, @@ -78,6 +77,9 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{ ast.MonthName: { {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDatetime}}, }, + ast.DayOfMonth: { + {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDatetime}}, + }, } func (s *testEvaluatorSuite) TestVectorizedBuiltinTimeEvalOneVec(c *C) {