Skip to content

Commit

Permalink
evalengine: jump inside instruction
Browse files Browse the repository at this point in the history
Signed-off-by: Vicent Marti <[email protected]>
  • Loading branch information
vmg committed Dec 19, 2024
1 parent e133d2f commit c270b66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
24 changes: 9 additions & 15 deletions go/vt/vtgate/evalengine/compiler_asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
13 changes: 1 addition & 12 deletions go/vt/vtgate/evalengine/fn_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c270b66

Please sign in to comment.