diff --git a/go/vt/vtgate/evalengine/compiler_asm.go b/go/vt/vtgate/evalengine/compiler_asm.go index 9099f8711c0..7dda215353f 100644 --- a/go/vt/vtgate/evalengine/compiler_asm.go +++ b/go/vt/vtgate/evalengine/compiler_asm.go @@ -5141,21 +5141,15 @@ func (asm *assembler) Introduce(offset int, t sqltypes.Type, col collations.Type func (asm *assembler) Fn_LAST_INSERT_ID() { asm.emit(func(env *ExpressionEnv) int { - arg := env.vm.stack[env.vm.sp-1].(*evalUint64) - env.VCursor().SetLastInsertID(arg.u) + arg := env.vm.stack[env.vm.sp-1] + if arg == nil { + env.VCursor().SetLastInsertID(0) + } else { + iarg := evalToInt64(arg) + uarg := env.vm.arena.newEvalUint64(uint64(iarg.i)) + env.vm.stack[env.vm.sp-1] = uarg + env.VCursor().SetLastInsertID(uarg.u) + } 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") -} - -func (asm *assembler) addJump(end *jump) { - asm.emit(func(env *ExpressionEnv) int { - return end.offset() - }, "JUMP") -} diff --git a/go/vt/vtgate/evalengine/fn_misc.go b/go/vt/vtgate/evalengine/fn_misc.go index cb17f8d6560..6f7d27c1101 100644 --- a/go/vt/vtgate/evalengine/fn_misc.go +++ b/go/vt/vtgate/evalengine/fn_misc.go @@ -219,19 +219,8 @@ func (call *builtinLastInsertID) compile(c *compiler) (ctype, error) { if err != nil { return ctype{}, err } - - setZero := c.compileNullCheck1(arg) - c.compileToUint64(arg, 1) c.asm.Fn_LAST_INSERT_ID() - end := c.asm.jumpFrom() - c.asm.addJump(end) - - c.asm.jumpDestination(setZero) - c.asm.Fn_LAST_INSERT_ID_NULL() - - c.asm.jumpDestination(end) - - return ctype{Type: sqltypes.Uint64, Flag: flagNullable, Col: collationNumeric}, nil + return ctype{Type: sqltypes.Uint64, Flag: arg.Flag & flagNullable, Col: collationNumeric}, nil } func printIPv6AsIPv4(addr netip.Addr) (netip.Addr, bool) {