diff --git a/go/vt/vtgate/evalengine/expr_bvar.go b/go/vt/vtgate/evalengine/expr_bvar.go index 23b40949e83..f48ec037ac8 100644 --- a/go/vt/vtgate/evalengine/expr_bvar.go +++ b/go/vt/vtgate/evalengine/expr_bvar.go @@ -125,10 +125,13 @@ func (bvar *BindVariable) compile(c *compiler) (ctype, error) { switch tt := typ.Type; { case sqltypes.IsSigned(tt): + typ.Type = sqltypes.Int64 c.asm.PushBVar_i(bvar.Key) case sqltypes.IsUnsigned(tt): + typ.Type = sqltypes.Uint64 c.asm.PushBVar_u(bvar.Key) case sqltypes.IsFloat(tt): + typ.Type = sqltypes.Float64 c.asm.PushBVar_f(bvar.Key) case sqltypes.IsDecimal(tt): c.asm.PushBVar_d(bvar.Key) @@ -146,9 +149,11 @@ func (bvar *BindVariable) compile(c *compiler) (ctype, error) { typ.Type = sqltypes.VarBinary typ.Flag |= flagBit } else { + typ.Type = sqltypes.VarChar c.asm.PushBVar_text(bvar.Key, typ.Col) } case sqltypes.IsBinary(tt): + typ.Type = sqltypes.VarBinary c.asm.PushBVar_bin(bvar.Key) case sqltypes.IsNull(tt): c.asm.PushNull() diff --git a/go/vt/vtgate/evalengine/translate_test.go b/go/vt/vtgate/evalengine/translate_test.go index 3702230e22e..d475a9cac8e 100644 --- a/go/vt/vtgate/evalengine/translate_test.go +++ b/go/vt/vtgate/evalengine/translate_test.go @@ -452,3 +452,19 @@ func TestCardinalityWithBindVariables(t *testing.T) { }) } } + +func TestBindVarType(t *testing.T) { + lhs := sqlparser.NewTypedArgument("lhs", sqltypes.Int32) + rhs := sqlparser.NewTypedArgument("rhs", sqltypes.Int64) + venv := vtenv.NewTestEnv() + cmp := &sqlparser.ComparisonExpr{ + Operator: sqlparser.EqualOp, + Left: lhs, + Right: rhs, + } + _, err := Translate(cmp, &Config{ + Collation: venv.CollationEnv().DefaultConnectionCharset(), + Environment: venv, + }) + require.NoError(t, err) +}