diff --git a/go/test/endtoend/vtgate/queries/collations/collations_test.go b/go/test/endtoend/vtgate/queries/collations/collations_test.go new file mode 100644 index 00000000000..ce408c9bce6 --- /dev/null +++ b/go/test/endtoend/vtgate/queries/collations/collations_test.go @@ -0,0 +1,66 @@ +/* +Copyright 2021 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package collations + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "vitess.io/vitess/go/test/endtoend/cluster" + "vitess.io/vitess/go/test/endtoend/utils" +) + +func start(t *testing.T) (utils.MySQLCompare, func()) { + // ensure that the vschema and the tables have been created before running any tests + _ = utils.WaitForAuthoritative(t, keyspaceName, "t1", clusterInstance.VtgateProcess.ReadVSchema) + _ = utils.WaitForAuthoritative(t, keyspaceName, "t2", clusterInstance.VtgateProcess.ReadVSchema) + + mcmp, err := utils.NewMySQLCompare(t, vtParams, mysqlParams) + require.NoError(t, err) + + deleteAll := func() { + _, _ = utils.ExecAllowError(t, mcmp.VtConn, "set workload = oltp") + + tables := []string{"t1", "t2"} + for _, table := range tables { + _, _ = mcmp.ExecAndIgnore("delete from " + table) + } + } + + deleteAll() + + return mcmp, func() { + deleteAll() + mcmp.Close() + cluster.PanicHandler(t) + } +} + +func TestCollationTyping(t *testing.T) { + utils.SkipIfBinaryIsBelowVersion(t, 19, "vtgate") + + mcmp, closer := start(t) + defer closer() + mcmp.Exec("insert into t1(id, name) values(1,'ß'), (2,'s'), (3,'ss')") + mcmp.Exec("insert into t2(id, name) values(1,'ß'), (2,'s'), (3,'ss')") + + res := utils.Exec(t, mcmp.VtConn, `vexplain plan SELECT name from t1 union select name from t2`) + fmt.Printf("%v", res.Rows) + mcmp.Exec(`SELECT name from t1 union select name from t2`) +} diff --git a/go/test/endtoend/vtgate/queries/collations/main_test.go b/go/test/endtoend/vtgate/queries/collations/main_test.go new file mode 100644 index 00000000000..3f4c99e6ed7 --- /dev/null +++ b/go/test/endtoend/vtgate/queries/collations/main_test.go @@ -0,0 +1,94 @@ +/* +Copyright 2021 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package collations + +import ( + _ "embed" + "flag" + "fmt" + "os" + "testing" + + "vitess.io/vitess/go/test/endtoend/utils" + + "vitess.io/vitess/go/mysql" + "vitess.io/vitess/go/test/endtoend/cluster" +) + +var ( + clusterInstance *cluster.LocalProcessCluster + vtParams mysql.ConnParams + mysqlParams mysql.ConnParams + keyspaceName = "ks_aggr" + cell = "test_aggr" + + //go:embed schema.sql + schemaSQL string + + //go:embed vschema.json + vschema string +) + +func TestMain(m *testing.M) { + defer cluster.PanicHandler(nil) + flag.Parse() + + exitCode := func() int { + clusterInstance = cluster.NewCluster(cell, "localhost") + defer clusterInstance.Teardown() + + // Start topo server + err := clusterInstance.StartTopo() + if err != nil { + return 1 + } + + // Start keyspace + keyspace := &cluster.Keyspace{ + Name: keyspaceName, + SchemaSQL: schemaSQL, + VSchema: vschema, + } + clusterInstance.VtGateExtraArgs = []string{"--schema_change_signal"} + clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-schema-change-signal"} + err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 0, false) + if err != nil { + return 1 + } + + clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--enable_system_settings=true") + // Start vtgate + err = clusterInstance.StartVtgate() + if err != nil { + return 1 + } + + vtParams = clusterInstance.GetVTParams(keyspaceName) + + // create mysql instance and connection parameters + conn, closer, err := utils.NewMySQL(clusterInstance, keyspaceName, schemaSQL) + if err != nil { + fmt.Println(err) + return 1 + } + defer closer() + mysqlParams = conn + + return m.Run() + }() + os.Exit(exitCode) +} diff --git a/go/test/endtoend/vtgate/queries/collations/schema.sql b/go/test/endtoend/vtgate/queries/collations/schema.sql new file mode 100644 index 00000000000..9270999b534 --- /dev/null +++ b/go/test/endtoend/vtgate/queries/collations/schema.sql @@ -0,0 +1,13 @@ +create table t1 +( + id bigint, + name varchar(255) collate utf8_general_mysql500_ci, + primary key (id) +) Engine = InnoDB; + +create table t2 +( + id bigint, + name varchar(255) collate utf8_general_mysql500_ci, + primary key (id) +) ENGINE = InnoDB; \ No newline at end of file diff --git a/go/test/endtoend/vtgate/queries/collations/vschema.json b/go/test/endtoend/vtgate/queries/collations/vschema.json new file mode 100644 index 00000000000..2721da21692 --- /dev/null +++ b/go/test/endtoend/vtgate/queries/collations/vschema.json @@ -0,0 +1,29 @@ +{ + "sharded": true, + "vindexes": { + "hash": { + "type": "hash" + }, + "unicode_loose_xxhash": { + "type": "unicode_loose_xxhash" + } + }, + "tables": { + "t1": { + "column_vindexes": [ + { + "column": "id", + "name": "hash" + } + ] + }, + "t2": { + "column_vindexes": [ + { + "column": "id", + "name": "hash" + } + ] + } + } +} \ No newline at end of file diff --git a/test/config.json b/test/config.json index 14c05cb8df6..6bc0ae1c4a0 100644 --- a/test/config.json +++ b/test/config.json @@ -518,6 +518,15 @@ "RetryMax": 2, "Tags": ["upgrade_downgrade_query_serving_queries"] }, + "vtgate_queries_collations": { + "File": "unused.go", + "Args": ["vitess.io/vitess/go/test/endtoend/vtgate/queries/collations"], + "Command": [], + "Manual": false, + "Shard": "vtgate_queries", + "RetryMax": 2, + "Tags": ["upgrade_downgrade_query_serving_queries"] + }, "vtgate_queries_foundrows": { "File": "unused.go", "Args": ["vitess.io/vitess/go/test/endtoend/vtgate/queries/foundrows"],