Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GuptaManan100 committed Dec 18, 2024
1 parent 5f48f05 commit 02821a8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions go/test/endtoend/vtgate/queries/misc/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/vt/log"

_ "github.com/go-sql-driver/mysql"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -142,6 +143,7 @@ func TestSetAndGetLastInsertID(t *testing.T) {
name = "tx - " + name
}
mcmp.Run(name, func(mcmp *utils.MySQLCompare) {
log.Errorf("Test start time - %v", time.Now())
mcmp.Exec(query)
mcmp.Exec("select last_insert_id()")
if mcmp.AsT().Failed() {
Expand Down
9 changes: 9 additions & 0 deletions go/vt/vtgate/evalengine/compiler_asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ import (
"math"
"math/bits"
"net/netip"
"runtime/debug"
"strconv"
"time"

"github.com/google/uuid"

"vitess.io/vitess/go/mysql/collations/charset/types"
"vitess.io/vitess/go/mysql/collations/colldata"
"vitess.io/vitess/go/vt/log"

"vitess.io/vitess/go/hack"
"vitess.io/vitess/go/mysql/collations"
Expand Down Expand Up @@ -5149,7 +5151,14 @@ func (asm *assembler) Fn_LAST_INSERT_ID() {

func (asm *assembler) Fn_LAST_INSERT_ID_NULL() {
asm.emit(func(env *ExpressionEnv) int {
log.Errorf("Triggering new code - %v", string(debug.Stack()))
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")
}
2 changes: 1 addition & 1 deletion go/vt/vtgate/evalengine/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ func runTest(t *testing.T, expr sqlparser.Expr, cfg *evalengine.Config, tc struc
vc := &testVcursor{env: vtenv.NewTestEnv()}
env := evalengine.NewExpressionEnv(context.Background(), nil, vc)

_, err = env.EvaluateAST(converted)
_, err = env.Evaluate(converted)
require.NoError(t, err)
if tc.missing {
require.Nil(t, vc.lastInsertID)
Expand Down
1 change: 1 addition & 0 deletions go/vt/vtgate/evalengine/fn_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func (call *builtinLastInsertID) compile(c *compiler) (ctype, error) {
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()
Expand Down

0 comments on commit 02821a8

Please sign in to comment.