From c24efc8a4575679edbcfaf7bf8be6442c2678211 Mon Sep 17 00:00:00 2001 From: Noble Mittal Date: Fri, 26 Jan 2024 17:02:08 +0530 Subject: [PATCH] Add check for IsZero datetime in Fn_LAST_DAY Signed-off-by: Noble Mittal --- go/vt/vtgate/evalengine/compiler_asm.go | 5 +++-- go/vt/vtgate/evalengine/fn_time.go | 4 ---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/go/vt/vtgate/evalengine/compiler_asm.go b/go/vt/vtgate/evalengine/compiler_asm.go index 161e3525b5d..1a750ed7d0e 100644 --- a/go/vt/vtgate/evalengine/compiler_asm.go +++ b/go/vt/vtgate/evalengine/compiler_asm.go @@ -3784,11 +3784,12 @@ func (asm *assembler) Fn_LAST_DAY() { return 1 } arg := env.vm.stack[env.vm.sp-1].(*evalTemporal) - d := lastDay(env.currentTimezone(), arg.dt) - if d.IsZero() { + if arg.dt.IsZero() { env.vm.stack[env.vm.sp-1] = nil return 1 } + + d := lastDay(env.currentTimezone(), arg.dt) env.vm.stack[env.vm.sp-1] = env.vm.arena.newEvalDate(d) return 1 }, "FN LAST_DAY DATETIME(SP-1)") diff --git a/go/vt/vtgate/evalengine/fn_time.go b/go/vt/vtgate/evalengine/fn_time.go index 45fa5ad447e..de1b7259aff 100644 --- a/go/vt/vtgate/evalengine/fn_time.go +++ b/go/vt/vtgate/evalengine/fn_time.go @@ -1228,10 +1228,6 @@ func (b *builtinLastDay) eval(env *ExpressionEnv) (eval, error) { } d := lastDay(env.currentTimezone(), dt.dt) - if d.IsZero() { - return nil, nil - } - return newEvalDate(d, env.sqlmode.AllowZeroDate()), nil }