From a63963ad3f8e5692c99cead89f8edbe9de060dcc Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Sat, 23 Jan 2021 15:20:05 +0100 Subject: [PATCH 01/14] fixed want/result order in executor_select_test assertions Signed-off-by: Florent Poinsard --- go/vt/vtgate/executor_select_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/go/vt/vtgate/executor_select_test.go b/go/vt/vtgate/executor_select_test.go index 48945d68c6f..5e999e85420 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -313,7 +313,7 @@ func TestSelectLastInsertId(t *testing.T) { }}, } require.NoError(t, err) - utils.MustMatch(t, result, wantResult, "Mismatch") + utils.MustMatch(t, wantResult, result, "Mismatch") } func TestSelectSystemVariables(t *testing.T) { @@ -364,7 +364,7 @@ func TestSelectSystemVariables(t *testing.T) { }}, } require.NoError(t, err) - utils.MustMatch(t, result, wantResult, "Mismatch") + utils.MustMatch(t, wantResult, result, "Mismatch") } func TestSelectUserDefindVariable(t *testing.T) { @@ -385,7 +385,7 @@ func TestSelectUserDefindVariable(t *testing.T) { sqltypes.NULL, }}, } - utils.MustMatch(t, result, wantResult, "Mismatch") + utils.MustMatch(t, wantResult, result, "Mismatch") masterSession = &vtgatepb.Session{UserDefinedVariables: createMap([]string{"foo"}, []interface{}{"bar"})} result, err = executorExec(executor, sql, map[string]*querypb.BindVariable{}) @@ -399,7 +399,7 @@ func TestSelectUserDefindVariable(t *testing.T) { sqltypes.NewVarBinary("bar"), }}, } - utils.MustMatch(t, result, wantResult, "Mismatch") + utils.MustMatch(t, wantResult, result, "Mismatch") } func TestFoundRows(t *testing.T) { @@ -424,7 +424,7 @@ func TestFoundRows(t *testing.T) { }}, } require.NoError(t, err) - utils.MustMatch(t, result, wantResult, "Mismatch") + utils.MustMatch(t, wantResult, result, "Mismatch") } func TestRowCount(t *testing.T) { @@ -454,7 +454,7 @@ func testRowCount(t *testing.T, executor *Executor, wantRowCount int64) { }}, } require.NoError(t, err) - utils.MustMatch(t, result, wantResult, "Mismatch") + utils.MustMatch(t, wantResult, result, "Mismatch") } func TestSelectLastInsertIdInUnion(t *testing.T) { @@ -558,7 +558,7 @@ func TestSelectDatabase(t *testing.T) { }}, } require.NoError(t, err) - utils.MustMatch(t, result, wantResult, "Mismatch") + utils.MustMatch(t, wantResult, result, "Mismatch") } From 9e2c673e623a73b659df413167b7a329714563c5 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Sat, 23 Jan 2021 15:39:49 +0100 Subject: [PATCH 02/14] addition of the new test case for future fix Signed-off-by: Florent Poinsard --- go/vt/vtgate/executor_select_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/go/vt/vtgate/executor_select_test.go b/go/vt/vtgate/executor_select_test.go index 5e999e85420..080cb087616 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -367,6 +367,29 @@ func TestSelectSystemVariables(t *testing.T) { utils.MustMatch(t, wantResult, result, "Mismatch") } +// Must fail until https://github.com/vitessio/vitess/issues/7301 is not fixed. +func TestSelectSingleVitessAwareVariable(t *testing.T) { + executor, _, _, _ := createLegacyExecutorEnv() + executor.normalize = true + logChan := QueryLogger.Subscribe("Test") + defer QueryLogger.Unsubscribe(logChan) + + sql := "select @@autocommit" + + result, err := executorExec(executor, sql, map[string]*querypb.BindVariable{}) + wantResult := &sqltypes.Result{ + Fields: []*querypb.Field{ + {Name: "@@autocommit", Type: sqltypes.Int32}, + }, + RowsAffected: 1, + Rows: [][]sqltypes.Value{{ + sqltypes.NewInt32(1), + }}, + } + require.NoError(t, err) + utils.MustMatch(t, wantResult, result, "Mismatch") +} + func TestSelectUserDefindVariable(t *testing.T) { executor, _, _, _ := createLegacyExecutorEnv() executor.normalize = true From 34ffa847d0f428ab22834cbe6a56c8f017db6458 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Sat, 23 Jan 2021 17:19:46 +0100 Subject: [PATCH 03/14] support for 32 bits value in evalengine toSQLValue function Signed-off-by: Florent Poinsard --- go/vt/vtgate/evalengine/evalengine.go | 28 +++++++++++++-------------- go/vt/vtgate/executor_select_test.go | 10 +++++----- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/go/vt/vtgate/evalengine/evalengine.go b/go/vt/vtgate/evalengine/evalengine.go index 7e2b3a7226c..f5e123b5aba 100644 --- a/go/vt/vtgate/evalengine/evalengine.go +++ b/go/vt/vtgate/evalengine/evalengine.go @@ -200,34 +200,34 @@ func (v EvalResult) toSQLValue(resultType querypb.Type) sqltypes.Value { switch { case sqltypes.IsSigned(resultType): switch v.typ { - case sqltypes.Int64: - return sqltypes.MakeTrusted(resultType, strconv.AppendInt(nil, v.ival, 10)) - case sqltypes.Uint64: + case sqltypes.Int64, sqltypes.Int32: + return sqltypes.MakeTrusted(resultType, strconv.AppendInt(nil, int64(v.ival), 10)) + case sqltypes.Uint64, sqltypes.Uint32: return sqltypes.MakeTrusted(resultType, strconv.AppendInt(nil, int64(v.uval), 10)) - case sqltypes.Float64: + case sqltypes.Float64, sqltypes.Float32: return sqltypes.MakeTrusted(resultType, strconv.AppendInt(nil, int64(v.fval), 10)) } case sqltypes.IsUnsigned(resultType): switch v.typ { - case sqltypes.Uint64: - return sqltypes.MakeTrusted(resultType, strconv.AppendUint(nil, v.uval, 10)) - case sqltypes.Int64: + case sqltypes.Uint64, sqltypes.Uint32: + return sqltypes.MakeTrusted(resultType, strconv.AppendUint(nil, uint64(v.uval), 10)) + case sqltypes.Int64, sqltypes.Int32: return sqltypes.MakeTrusted(resultType, strconv.AppendUint(nil, uint64(v.ival), 10)) - case sqltypes.Float64: + case sqltypes.Float64, sqltypes.Float32: return sqltypes.MakeTrusted(resultType, strconv.AppendUint(nil, uint64(v.fval), 10)) } case sqltypes.IsFloat(resultType) || resultType == sqltypes.Decimal: switch v.typ { - case sqltypes.Int64: - return sqltypes.MakeTrusted(resultType, strconv.AppendInt(nil, v.ival, 10)) - case sqltypes.Uint64: - return sqltypes.MakeTrusted(resultType, strconv.AppendUint(nil, v.uval, 10)) - case sqltypes.Float64: + case sqltypes.Int64, sqltypes.Int32: + return sqltypes.MakeTrusted(resultType, strconv.AppendInt(nil, int64(v.ival), 10)) + case sqltypes.Uint64, sqltypes.Uint32: + return sqltypes.MakeTrusted(resultType, strconv.AppendUint(nil, uint64(v.uval), 10)) + case sqltypes.Float64, sqltypes.Float32: format := byte('g') if resultType == sqltypes.Decimal { format = 'f' } - return sqltypes.MakeTrusted(resultType, strconv.AppendFloat(nil, v.fval, format, -1, 64)) + return sqltypes.MakeTrusted(resultType, strconv.AppendFloat(nil, float64(v.fval), format, -1, 64)) } default: return sqltypes.MakeTrusted(resultType, v.bytes) diff --git a/go/vt/vtgate/executor_select_test.go b/go/vt/vtgate/executor_select_test.go index 080cb087616..95e2b1cbdff 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -349,10 +349,10 @@ func TestSelectSystemVariables(t *testing.T) { RowsAffected: 1, Rows: [][]sqltypes.Value{{ // the following are the uninitialised session values - sqltypes.NULL, - sqltypes.NULL, - sqltypes.NULL, - sqltypes.NULL, + sqltypes.NewInt32(0), + sqltypes.NewInt32(0), + sqltypes.NewInt32(0), + sqltypes.NewInt32(0), sqltypes.NewInt64(0), sqltypes.NewVarBinary("UNSPECIFIED"), sqltypes.NewVarBinary(""), @@ -383,7 +383,7 @@ func TestSelectSingleVitessAwareVariable(t *testing.T) { }, RowsAffected: 1, Rows: [][]sqltypes.Value{{ - sqltypes.NewInt32(1), + sqltypes.NewInt32(0), // autocommit is by default false in the masterSession, thus 0 }}, } require.NoError(t, err) From c562244809797888980a09ceca9c2ce198f5431f Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Sat, 23 Jan 2021 17:57:19 +0100 Subject: [PATCH 04/14] deleted TDD test and added test for initialized VitessAware vars Signed-off-by: Florent Poinsard --- go/vt/vtgate/executor_select_test.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/go/vt/vtgate/executor_select_test.go b/go/vt/vtgate/executor_select_test.go index 95e2b1cbdff..54c496fe08a 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -367,23 +367,32 @@ func TestSelectSystemVariables(t *testing.T) { utils.MustMatch(t, wantResult, result, "Mismatch") } -// Must fail until https://github.com/vitessio/vitess/issues/7301 is not fixed. -func TestSelectSingleVitessAwareVariable(t *testing.T) { +func TestSelectInitializedVitessAwareVariable(t *testing.T) { executor, _, _, _ := createLegacyExecutorEnv() executor.normalize = true logChan := QueryLogger.Subscribe("Test") defer QueryLogger.Unsubscribe(logChan) - sql := "select @@autocommit" + masterSession.Autocommit = true + masterSession.EnableSystemSettings = true - result, err := executorExec(executor, sql, map[string]*querypb.BindVariable{}) + defer func() { + masterSession.Autocommit = false + masterSession.EnableSystemSettings = false + }() + + sql := "select @@autocommit, @@enable_system_settings" + + result, err := executorExec(executor, sql, nil) wantResult := &sqltypes.Result{ Fields: []*querypb.Field{ {Name: "@@autocommit", Type: sqltypes.Int32}, + {Name: "@@enable_system_settings", Type: sqltypes.Int32}, }, RowsAffected: 1, Rows: [][]sqltypes.Value{{ - sqltypes.NewInt32(0), // autocommit is by default false in the masterSession, thus 0 + sqltypes.NewInt32(1), + sqltypes.NewInt32(1), }}, } require.NoError(t, err) From da7611d87c2ed55b7e9117c9955955cd81b9c1d1 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Sat, 23 Jan 2021 18:03:26 +0100 Subject: [PATCH 05/14] removed temporary fix in TestEnableSystemSettings endtoend test Signed-off-by: Florent Poinsard --- go/test/endtoend/vtgate/reservedconn/sysvar_test.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go index 74a32bd083c..a9cd4339e18 100644 --- a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go +++ b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go @@ -329,16 +329,11 @@ func TestEnableSystemSettings(t *testing.T) { require.NoError(t, err) defer conn.Close() - // Insert a single row to correctly select @@enable_system_settings. - // See: https://github.com/vitessio/vitess/issues/7301 - checkedExec(t, conn, "delete from test") - checkedExec(t, conn, "insert into test (id, val1, val2, val3) values (1, null, 0, 0)") - // test set @@enable_system_settings to false and true checkedExec(t, conn, "set enable_system_settings = false") - assertMatches(t, conn, `select @@enable_system_settings from test`, `[[INT64(0)]]`) + assertMatches(t, conn, `select @@enable_system_settings`, `[[INT32(0)]]`) checkedExec(t, conn, "set enable_system_settings = true") - assertMatches(t, conn, `select @@enable_system_settings from test`, `[[INT64(1)]]`) + assertMatches(t, conn, `select @@enable_system_settings`, `[[INT32(1)]]`) // prepare the @@sql_mode variable checkedExec(t, conn, "set sql_mode = 'NO_ZERO_DATE'") From 1a4b9b0a5c9b84acd1e700e89b514a2ee0b290bb Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Tue, 26 Jan 2021 14:40:51 +0100 Subject: [PATCH 06/14] added system variable type consitency endtoend test Signed-off-by: Florent Poinsard --- .../vtgate/reservedconn/sysvar_test.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go index a9cd4339e18..7a76d290c0e 100644 --- a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go +++ b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go @@ -349,3 +349,27 @@ func TestEnableSystemSettings(t *testing.T) { checkedExec(t, conn, "set sql_mode = ''") // changing @@sql_mode to empty string assertMatches(t, conn, "select @@sql_mode", `[[VARCHAR("")]]`) // @@sql_mode did change } + +// Tests type consitency through multiple queries +func TestSystemVariableType(t *testing.T) { + vtParams := mysql.ConnParams{ + Host: "localhost", + Port: clusterInstance.VtgateMySQLPort, + } + conn, err := mysql.Connect(context.Background(), &vtParams) + require.NoError(t, err) + defer conn.Close() + + checkedExec(t, conn, "delete from test") + checkedExec(t, conn, "insert into test (id, val1, val2, val3) values (1, null, 0, 0)") + + // regardeless of the "from", the select @@autocommit should always return a INT32 type + + checkedExec(t, conn, "set autocommit = false") + assertMatches(t, conn, `select @@autocommit`, `[[INT32(0)]]`) + assertMatches(t, conn, `select @@autocommit test`, `[[INT32(0)]]`) + + checkedExec(t, conn, "set autocommit = true") + assertMatches(t, conn, `select @@autocommit`, `[[INT32(1)]]`) + assertMatches(t, conn, `select @@autocommit from test`, `[[INT32(1)]]`) +} From 72d0f924a86a318b62df800cbaa37af357e2cbbd Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Tue, 26 Jan 2021 14:57:26 +0100 Subject: [PATCH 07/14] fix test typo Signed-off-by: Florent Poinsard --- go/test/endtoend/vtgate/reservedconn/sysvar_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go index 7a76d290c0e..19a00873c8c 100644 --- a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go +++ b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go @@ -367,7 +367,7 @@ func TestSystemVariableType(t *testing.T) { checkedExec(t, conn, "set autocommit = false") assertMatches(t, conn, `select @@autocommit`, `[[INT32(0)]]`) - assertMatches(t, conn, `select @@autocommit test`, `[[INT32(0)]]`) + assertMatches(t, conn, `select @@autocommit from test`, `[[INT32(0)]]`) checkedExec(t, conn, "set autocommit = true") assertMatches(t, conn, `select @@autocommit`, `[[INT32(1)]]`) From a8c1b89d97c617aaf320bdfe12160064c1f09fc5 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Wed, 27 Jan 2021 15:03:41 +0100 Subject: [PATCH 08/14] addition test in vttablet to select system variables Signed-off-by: Florent Poinsard --- go/vt/vttablet/endtoend/misc_test.go | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/go/vt/vttablet/endtoend/misc_test.go b/go/vt/vttablet/endtoend/misc_test.go index 5c0f2c03908..3d5a5e11154 100644 --- a/go/vt/vttablet/endtoend/misc_test.go +++ b/go/vt/vttablet/endtoend/misc_test.go @@ -760,3 +760,37 @@ func TestBeginExecuteWithFailingPreQueriesAndCheckConnectionState(t *testing.T) require.NoError(t, err) require.Empty(t, qr.Rows) } + +func TestSelectBooleanSystemVariables(t *testing.T) { + client := framework.NewClient() + + type testCase struct { + Variable string + Value int + Type querypb.Type + } + + newTestCase := func(varname string, vartype querypb.Type, value int) testCase { + return testCase{Variable: varname, Value: value, Type: vartype} + } + + tcs := []testCase{ + newTestCase("autocommit", querypb.Type_INT32, 1), + newTestCase("autocommit", querypb.Type_INT32, 0), + newTestCase("enable_system_settings", querypb.Type_INT32, 1), + newTestCase("enable_system_settings", querypb.Type_INT32, 0), + } + + for _, tc := range tcs { + qr, err := client.Execute( + fmt.Sprintf("select @@%s", tc.Variable), + map[string]*querypb.BindVariable{tc.Variable: sqltypes.Int32BindVariable(int32(tc.Value))}, + ) + if err != nil { + t.Error(err) + return + } + require.NotEmpty(t, qr.Fields, "fields should not be empty") + require.Equal(t, tc.Type, qr.Fields[0].Type, fmt.Sprintf("invalid type, wants: %+v, but got: %+v\n", tc.Type, qr.Fields[0].Type)) + } +} From e5027d00b1fbd6e064f1890f2c9dcfa0e8281fce Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Wed, 27 Jan 2021 20:38:32 +0100 Subject: [PATCH 09/14] experimental support for 32-bits in sqltypes value Signed-off-by: Florent Poinsard --- go/sqltypes/value.go | 6 +++++- go/vt/vttablet/endtoend/misc_test.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/go/sqltypes/value.go b/go/sqltypes/value.go index 550e8b86eaf..e51729417b6 100644 --- a/go/sqltypes/value.go +++ b/go/sqltypes/value.go @@ -279,7 +279,11 @@ func (v Value) EncodeSQL(b BinWriter) { case v.typ == Bit: encodeBytesSQLBits(v.val, b) default: - b.Write(v.val) + if v.typ == querypb.Type_INT32 { + b.Write([]byte(fmt.Sprintf("CAST(1 as INT) AS autocommit"))) + } else { + b.Write(v.val) + } } } diff --git a/go/vt/vttablet/endtoend/misc_test.go b/go/vt/vttablet/endtoend/misc_test.go index 3d5a5e11154..5fed97b1e13 100644 --- a/go/vt/vttablet/endtoend/misc_test.go +++ b/go/vt/vttablet/endtoend/misc_test.go @@ -783,7 +783,7 @@ func TestSelectBooleanSystemVariables(t *testing.T) { for _, tc := range tcs { qr, err := client.Execute( - fmt.Sprintf("select @@%s", tc.Variable), + fmt.Sprintf("select :%s", tc.Variable), map[string]*querypb.BindVariable{tc.Variable: sqltypes.Int32BindVariable(int32(tc.Value))}, ) if err != nil { From 15527fb10784b674a5ab7268e227c098f7481990 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Wed, 27 Jan 2021 20:39:29 +0100 Subject: [PATCH 10/14] fixed fmt typo Signed-off-by: Florent Poinsard --- go/sqltypes/value.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/sqltypes/value.go b/go/sqltypes/value.go index e51729417b6..5e3ade4c10a 100644 --- a/go/sqltypes/value.go +++ b/go/sqltypes/value.go @@ -280,7 +280,7 @@ func (v Value) EncodeSQL(b BinWriter) { encodeBytesSQLBits(v.val, b) default: if v.typ == querypb.Type_INT32 { - b.Write([]byte(fmt.Sprintf("CAST(1 as INT) AS autocommit"))) + b.Write([]byte("CAST(1 as INT) AS autocommit")) } else { b.Write(v.val) } From 029446583f2a91ffc0477d041b22316662b47081 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Wed, 27 Jan 2021 21:31:27 +0100 Subject: [PATCH 11/14] make boolean values int64 to match mysql Signed-off-by: Andres Taylor --- go/sqltypes/bind_variables.go | 4 ++-- go/sqltypes/value.go | 6 +----- .../vtgate/reservedconn/sysvar_test.go | 18 +++++++++++++----- go/vt/vttablet/endtoend/misc_test.go | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/go/sqltypes/bind_variables.go b/go/sqltypes/bind_variables.go index 3c9bc6bbe9e..83c1802d7b5 100644 --- a/go/sqltypes/bind_variables.go +++ b/go/sqltypes/bind_variables.go @@ -78,9 +78,9 @@ func Int32BindVariable(v int32) *querypb.BindVariable { // BoolBindVariable converts an bool to a int32 bind var. func BoolBindVariable(v bool) *querypb.BindVariable { if v { - return Int32BindVariable(1) + return Int64BindVariable(1) } - return Int32BindVariable(0) + return Int64BindVariable(0) } // Int64BindVariable converts an int64 to a bind var. diff --git a/go/sqltypes/value.go b/go/sqltypes/value.go index 5e3ade4c10a..550e8b86eaf 100644 --- a/go/sqltypes/value.go +++ b/go/sqltypes/value.go @@ -279,11 +279,7 @@ func (v Value) EncodeSQL(b BinWriter) { case v.typ == Bit: encodeBytesSQLBits(v.val, b) default: - if v.typ == querypb.Type_INT32 { - b.Write([]byte("CAST(1 as INT) AS autocommit")) - } else { - b.Write(v.val) - } + b.Write(v.val) } } diff --git a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go index 19a00873c8c..db0a4214645 100644 --- a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go +++ b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go @@ -22,6 +22,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "vitess.io/vitess/go/mysql" @@ -363,13 +365,19 @@ func TestSystemVariableType(t *testing.T) { checkedExec(t, conn, "delete from test") checkedExec(t, conn, "insert into test (id, val1, val2, val3) values (1, null, 0, 0)") - // regardeless of the "from", the select @@autocommit should always return a INT32 type + // regardless of the "from", the select @@autocommit should return the same type checkedExec(t, conn, "set autocommit = false") - assertMatches(t, conn, `select @@autocommit`, `[[INT32(0)]]`) - assertMatches(t, conn, `select @@autocommit from test`, `[[INT32(0)]]`) + qr1 := checkedExec(t, conn, "select @@autocommit") + got1 := fmt.Sprintf("%v", qr1.Rows) + qr2 := checkedExec(t, conn, "select @@autocommit from test") + got2 := fmt.Sprintf("%v", qr2.Rows) + assert.Equal(t, got1, got2) checkedExec(t, conn, "set autocommit = true") - assertMatches(t, conn, `select @@autocommit`, `[[INT32(1)]]`) - assertMatches(t, conn, `select @@autocommit from test`, `[[INT32(1)]]`) + qr1 = checkedExec(t, conn, "select @@autocommit") + got1 = fmt.Sprintf("%v", qr1.Rows) + qr2 = checkedExec(t, conn, "select @@autocommit from test") + got2 = fmt.Sprintf("%v", qr2.Rows) + assert.Equal(t, got1, got2) } diff --git a/go/vt/vttablet/endtoend/misc_test.go b/go/vt/vttablet/endtoend/misc_test.go index 5fed97b1e13..e068c640fb7 100644 --- a/go/vt/vttablet/endtoend/misc_test.go +++ b/go/vt/vttablet/endtoend/misc_test.go @@ -783,7 +783,7 @@ func TestSelectBooleanSystemVariables(t *testing.T) { for _, tc := range tcs { qr, err := client.Execute( - fmt.Sprintf("select :%s", tc.Variable), + "select @@autocommit", map[string]*querypb.BindVariable{tc.Variable: sqltypes.Int32BindVariable(int32(tc.Value))}, ) if err != nil { From 2d91120f6b82882bb7e39b0f3cad8cc4c0cdc4ea Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Wed, 27 Jan 2021 22:10:21 +0100 Subject: [PATCH 12/14] adaptation of the boolean int64 throughout various tests Signed-off-by: Florent Poinsard --- .../endtoend/vtgate/reservedconn/main_test.go | 10 ++++++++ .../vtgate/reservedconn/sysvar_test.go | 16 ++++--------- go/vt/vtgate/executor_select_test.go | 24 +++++++++---------- go/vt/vttablet/endtoend/misc_test.go | 16 ++++++------- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/go/test/endtoend/vtgate/reservedconn/main_test.go b/go/test/endtoend/vtgate/reservedconn/main_test.go index 90d71e71753..e3b5ec78567 100644 --- a/go/test/endtoend/vtgate/reservedconn/main_test.go +++ b/go/test/endtoend/vtgate/reservedconn/main_test.go @@ -169,3 +169,13 @@ func assertIsEmpty(t *testing.T, conn *mysql.Conn, query string) { qr := checkedExec(t, conn, query) assert.Empty(t, qr.Rows) } + +func assertResponseMatch(t *testing.T, conn *mysql.Conn, query1, query2 string) { + qr1 := checkedExec(t, conn, query1) + got1 := fmt.Sprintf("%v", qr1.Rows) + + qr2 := checkedExec(t, conn, query2) + got2 := fmt.Sprintf("%v", qr2.Rows) + + assert.Equal(t, got1, got2) +} diff --git a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go index db0a4214645..651f3635612 100644 --- a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go +++ b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go @@ -22,8 +22,6 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "vitess.io/vitess/go/mysql" @@ -366,18 +364,12 @@ func TestSystemVariableType(t *testing.T) { checkedExec(t, conn, "insert into test (id, val1, val2, val3) values (1, null, 0, 0)") // regardless of the "from", the select @@autocommit should return the same type + query1 := "select @@autocommit" + query2 := "select @@autocommit from test" checkedExec(t, conn, "set autocommit = false") - qr1 := checkedExec(t, conn, "select @@autocommit") - got1 := fmt.Sprintf("%v", qr1.Rows) - qr2 := checkedExec(t, conn, "select @@autocommit from test") - got2 := fmt.Sprintf("%v", qr2.Rows) - assert.Equal(t, got1, got2) + assertResponseMatch(t, conn, query1, query2) checkedExec(t, conn, "set autocommit = true") - qr1 = checkedExec(t, conn, "select @@autocommit") - got1 = fmt.Sprintf("%v", qr1.Rows) - qr2 = checkedExec(t, conn, "select @@autocommit from test") - got2 = fmt.Sprintf("%v", qr2.Rows) - assert.Equal(t, got1, got2) + assertResponseMatch(t, conn, query1, query2) } diff --git a/go/vt/vtgate/executor_select_test.go b/go/vt/vtgate/executor_select_test.go index 54c496fe08a..79d92a4f50a 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -334,10 +334,10 @@ func TestSelectSystemVariables(t *testing.T) { result, err := executorExec(executor, sql, map[string]*querypb.BindVariable{}) wantResult := &sqltypes.Result{ Fields: []*querypb.Field{ - {Name: "@@autocommit", Type: sqltypes.Int32}, - {Name: "@@client_found_rows", Type: sqltypes.Int32}, - {Name: "@@skip_query_plan_cache", Type: sqltypes.Int32}, - {Name: "@@enable_system_settings", Type: sqltypes.Int32}, + {Name: "@@autocommit", Type: sqltypes.Int64}, + {Name: "@@client_found_rows", Type: sqltypes.Int64}, + {Name: "@@skip_query_plan_cache", Type: sqltypes.Int64}, + {Name: "@@enable_system_settings", Type: sqltypes.Int64}, {Name: "@@sql_select_limit", Type: sqltypes.Int64}, {Name: "@@transaction_mode", Type: sqltypes.VarBinary}, {Name: "@@workload", Type: sqltypes.VarBinary}, @@ -349,10 +349,10 @@ func TestSelectSystemVariables(t *testing.T) { RowsAffected: 1, Rows: [][]sqltypes.Value{{ // the following are the uninitialised session values - sqltypes.NewInt32(0), - sqltypes.NewInt32(0), - sqltypes.NewInt32(0), - sqltypes.NewInt32(0), + sqltypes.NewInt64(0), + sqltypes.NewInt64(0), + sqltypes.NewInt64(0), + sqltypes.NewInt64(0), sqltypes.NewInt64(0), sqltypes.NewVarBinary("UNSPECIFIED"), sqltypes.NewVarBinary(""), @@ -386,13 +386,13 @@ func TestSelectInitializedVitessAwareVariable(t *testing.T) { result, err := executorExec(executor, sql, nil) wantResult := &sqltypes.Result{ Fields: []*querypb.Field{ - {Name: "@@autocommit", Type: sqltypes.Int32}, - {Name: "@@enable_system_settings", Type: sqltypes.Int32}, + {Name: "@@autocommit", Type: sqltypes.Int64}, + {Name: "@@enable_system_settings", Type: sqltypes.Int64}, }, RowsAffected: 1, Rows: [][]sqltypes.Value{{ - sqltypes.NewInt32(1), - sqltypes.NewInt32(1), + sqltypes.NewInt64(1), + sqltypes.NewInt64(1), }}, } require.NoError(t, err) diff --git a/go/vt/vttablet/endtoend/misc_test.go b/go/vt/vttablet/endtoend/misc_test.go index e068c640fb7..9f3ec9b6f01 100644 --- a/go/vt/vttablet/endtoend/misc_test.go +++ b/go/vt/vttablet/endtoend/misc_test.go @@ -766,25 +766,25 @@ func TestSelectBooleanSystemVariables(t *testing.T) { type testCase struct { Variable string - Value int + Value bool Type querypb.Type } - newTestCase := func(varname string, vartype querypb.Type, value int) testCase { + newTestCase := func(varname string, vartype querypb.Type, value bool) testCase { return testCase{Variable: varname, Value: value, Type: vartype} } tcs := []testCase{ - newTestCase("autocommit", querypb.Type_INT32, 1), - newTestCase("autocommit", querypb.Type_INT32, 0), - newTestCase("enable_system_settings", querypb.Type_INT32, 1), - newTestCase("enable_system_settings", querypb.Type_INT32, 0), + newTestCase("autocommit", querypb.Type_INT64, true), + newTestCase("autocommit", querypb.Type_INT64, false), + newTestCase("enable_system_settings", querypb.Type_INT64, true), + newTestCase("enable_system_settings", querypb.Type_INT64, false), } for _, tc := range tcs { qr, err := client.Execute( - "select @@autocommit", - map[string]*querypb.BindVariable{tc.Variable: sqltypes.Int32BindVariable(int32(tc.Value))}, + fmt.Sprintf("select :%s", tc.Variable), + map[string]*querypb.BindVariable{tc.Variable: sqltypes.BoolBindVariable(tc.Value)}, ) if err != nil { t.Error(err) From 561c633147d3334d50a1ced1b1013fc16d37c1b9 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Wed, 27 Jan 2021 22:14:22 +0100 Subject: [PATCH 13/14] fixed BoolBindVariable comment Signed-off-by: Florent Poinsard --- go/sqltypes/bind_variables.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/sqltypes/bind_variables.go b/go/sqltypes/bind_variables.go index 83c1802d7b5..9d60c1c8e1a 100644 --- a/go/sqltypes/bind_variables.go +++ b/go/sqltypes/bind_variables.go @@ -75,7 +75,7 @@ func Int32BindVariable(v int32) *querypb.BindVariable { return ValueBindVariable(NewInt32(v)) } -// BoolBindVariable converts an bool to a int32 bind var. +// BoolBindVariable converts an bool to a int64 bind var. func BoolBindVariable(v bool) *querypb.BindVariable { if v { return Int64BindVariable(1) From 22097a9b31e685e201a1109a7c1599faace02b55 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Thu, 28 Jan 2021 16:30:18 +0100 Subject: [PATCH 14/14] modified TestEnableSystemSettings to fit with the 64bit Signed-off-by: Florent Poinsard --- go/test/endtoend/vtgate/reservedconn/sysvar_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go index 651f3635612..3201fdd7521 100644 --- a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go +++ b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go @@ -331,9 +331,9 @@ func TestEnableSystemSettings(t *testing.T) { // test set @@enable_system_settings to false and true checkedExec(t, conn, "set enable_system_settings = false") - assertMatches(t, conn, `select @@enable_system_settings`, `[[INT32(0)]]`) + assertMatches(t, conn, `select @@enable_system_settings`, `[[INT64(0)]]`) checkedExec(t, conn, "set enable_system_settings = true") - assertMatches(t, conn, `select @@enable_system_settings`, `[[INT32(1)]]`) + assertMatches(t, conn, `select @@enable_system_settings`, `[[INT64(1)]]`) // prepare the @@sql_mode variable checkedExec(t, conn, "set sql_mode = 'NO_ZERO_DATE'")