diff --git a/go/vt/vtgate/evalengine/compiler_asm.go b/go/vt/vtgate/evalengine/compiler_asm.go index b717b0750f6..ebde418a3db 100644 --- a/go/vt/vtgate/evalengine/compiler_asm.go +++ b/go/vt/vtgate/evalengine/compiler_asm.go @@ -5146,3 +5146,10 @@ func (asm *assembler) Fn_LAST_INSERT_ID() { return 1 }, "FN LAST_INSERT_ID UINT64(SP-1)") } + +func (asm *assembler) Fn_LAST_INSERT_ID_NULL() { + asm.emit(func(env *ExpressionEnv) int { + env.VCursor().SetLastInsertID(0) + return 1 + }, "FN LAST_INSERT_ID NULL") +} diff --git a/go/vt/vtgate/evalengine/fn_misc.go b/go/vt/vtgate/evalengine/fn_misc.go index 948383f5352..6c017b9195c 100644 --- a/go/vt/vtgate/evalengine/fn_misc.go +++ b/go/vt/vtgate/evalengine/fn_misc.go @@ -222,17 +222,13 @@ func (call *builtinLastInsertID) compile(c *compiler) (ctype, error) { setZero := c.compileNullCheck1(arg) c.compileToUint64(arg, 1) - setLastInsertID := c.asm.jumpFrom() + c.asm.Fn_LAST_INSERT_ID() + end := c.asm.jumpFrom() c.asm.jumpDestination(setZero) - c.asm.emit(func(env *ExpressionEnv) int { - env.vm.stack[env.vm.sp] = env.vm.arena.newEvalUint64(0) - env.vm.sp++ - return 1 - }, "PUSH UINT64(0)") + c.asm.Fn_LAST_INSERT_ID_NULL() - c.asm.jumpDestination(setLastInsertID) - c.asm.Fn_LAST_INSERT_ID() + c.asm.jumpDestination(end) return ctype{Type: sqltypes.Uint64, Flag: flagNullable, Col: collationNumeric}, nil }