From 5f48f05169bd7e880ed19f545c5b6b0a62ce1032 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Wed, 18 Dec 2024 14:27:43 +0100 Subject: [PATCH] refactor: clean up compiler code Signed-off-by: Andres Taylor --- go/vt/vtgate/evalengine/compiler_asm.go | 7 +++++++ go/vt/vtgate/evalengine/fn_misc.go | 12 ++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) 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 }