diff --git a/expression/builtin_time.go b/expression/builtin_time.go index ee23687ccc5e0..26f60cd70dc80 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -6532,8 +6532,8 @@ func (b *builtinLastDaySig) evalTime(row chunk.Row) (types.Time, bool, error) { return types.Time{}, true, handleInvalidTimeError(b.ctx, err) } tm := arg.Time - year, month, day := tm.Year(), tm.Month(), tm.Day() - if month == 0 || day == 0 { + year, month := tm.Year(), tm.Month() + if arg.InvalidZero() { return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())) } lastDay := types.GetLastDay(year, month) diff --git a/expression/builtin_time_vec.go b/expression/builtin_time_vec.go index 587ba54e32b98..54515ef39f2ff 100644 --- a/expression/builtin_time_vec.go +++ b/expression/builtin_time_vec.go @@ -750,11 +750,36 @@ func (b *builtinGetFormatSig) getFormat(format, location string) string { } func (b *builtinLastDaySig) vectorized() bool { - return false + return true } func (b *builtinLastDaySig) vecEvalTime(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + n := input.NumRows() + if err := b.args[0].VecEvalTime(b.ctx, input, result); err != nil { + return err + } + times := result.Times() + for i := 0; i < n; i++ { + if result.IsNull(i) { + continue + } + if times[i].InvalidZero() { + if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(times[i].String())); err != nil { + return err + } + result.SetNull(i, true) + continue + } + tm := times[i].Time + year, month := tm.Year(), tm.Month() + lastDay := types.GetLastDay(year, month) + times[i] = types.Time{ + Time: types.FromDate(year, month, lastDay, 0, 0, 0, 0), + Type: mysql.TypeDate, + Fsp: types.DefaultFsp, + } + } + return nil } func (b *builtinAddDateStringDecimalSig) vectorized() bool { diff --git a/expression/builtin_time_vec_test.go b/expression/builtin_time_vec_test.go index 64b41db60e2eb..05e34bc2da66e 100644 --- a/expression/builtin_time_vec_test.go +++ b/expression/builtin_time_vec_test.go @@ -282,6 +282,9 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{ // {retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETInt}, // geners: []dataGenerator{&rangeInt64Gener{begin: 0, end: 7}}}, }, + ast.LastDay: { + {retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETDatetime}}, + }, ast.Extract: { {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDatetime}, geners: []dataGenerator{&dateTimeUnitStrGener{}, nil}}, },