From 6d88acd2fcf7c65660bbf483a60013cdb7211f50 Mon Sep 17 00:00:00 2001 From: Manan Gupta <35839558+GuptaManan100@users.noreply.github.com> Date: Fri, 29 Mar 2024 10:37:53 +0530 Subject: [PATCH] Add testing for shard scoped foreign keys (#15571) Signed-off-by: Manan Gupta --- .../vtgate/foreignkey/fk_fuzz_test.go | 33 +- go/test/endtoend/vtgate/foreignkey/fk_test.go | 141 +++--- .../endtoend/vtgate/foreignkey/main_test.go | 49 ++- .../foreignkey/shard_scoped_vschema.json | 411 ++++++++++++++++++ .../endtoend/vtgate/foreignkey/utils_test.go | 9 +- 5 files changed, 542 insertions(+), 101 deletions(-) create mode 100644 go/test/endtoend/vtgate/foreignkey/shard_scoped_vschema.json diff --git a/go/test/endtoend/vtgate/foreignkey/fk_fuzz_test.go b/go/test/endtoend/vtgate/foreignkey/fk_fuzz_test.go index d884fee1468..9d2f267a288 100644 --- a/go/test/endtoend/vtgate/foreignkey/fk_fuzz_test.go +++ b/go/test/endtoend/vtgate/foreignkey/fk_fuzz_test.go @@ -257,20 +257,20 @@ func (fz *fuzzer) generateDeleteDMLQuery() string { } // start starts running the fuzzer. -func (fz *fuzzer) start(t *testing.T, sharded bool) { +func (fz *fuzzer) start(t *testing.T, keyspace string) { // We mark the fuzzer thread to be running now. fz.shouldStop.Store(false) fz.wg.Add(fz.concurrency) for i := 0; i < fz.concurrency; i++ { fuzzerThreadId := i go func() { - fz.runFuzzerThread(t, sharded, fuzzerThreadId) + fz.runFuzzerThread(t, keyspace, fuzzerThreadId) }() } } // runFuzzerThread is used to run a thread of the fuzzer. -func (fz *fuzzer) runFuzzerThread(t *testing.T, sharded bool, fuzzerThreadId int) { +func (fz *fuzzer) runFuzzerThread(t *testing.T, keyspace string, fuzzerThreadId int) { // Whenever we finish running this thread, we should mark the thread has stopped. defer func() { fz.wg.Done() @@ -293,16 +293,9 @@ func (fz *fuzzer) runFuzzerThread(t *testing.T, sharded bool, fuzzerThreadId int defer mysqlDb.Close() } // Set the correct keyspace to use from VtGates. - if sharded { - _ = utils.Exec(t, mcmp.VtConn, "use `ks`") - if vitessDb != nil { - _, _ = vitessDb.Exec("use `ks`") - } - } else { - _ = utils.Exec(t, mcmp.VtConn, "use `uks`") - if vitessDb != nil { - _, _ = vitessDb.Exec("use `uks`") - } + _ = utils.Exec(t, mcmp.VtConn, fmt.Sprintf("use `%v`", keyspace)) + if vitessDb != nil { + _, _ = vitessDb.Exec(fmt.Sprintf("use `%v`", keyspace)) } if fz.queryFormat == OlapSQLQueries { _ = utils.Exec(t, mcmp.VtConn, "set workload = olap") @@ -715,21 +708,19 @@ func TestFkFuzzTest(t *testing.T) { valFalse := false for _, fkState := range []*bool{nil, &valTrue, &valFalse} { for _, tt := range testcases { - for _, testSharded := range []bool{false, true} { + for _, keyspace := range []string{unshardedKs, shardedKs} { for _, queryFormat := range []QueryFormat{OlapSQLQueries, SQLQueries, PreparedStatmentQueries, PreparedStatementPacket} { if fkState != nil && (queryFormat != SQLQueries || tt.concurrency != 1) { continue } - t.Run(getTestName(tt.name, testSharded)+fmt.Sprintf(" FkState - %v QueryFormat - %v", sqlparser.FkChecksStateString(fkState), queryFormat), func(t *testing.T) { + t.Run(getTestName(tt.name, keyspace)+fmt.Sprintf(" FkState - %v QueryFormat - %v", sqlparser.FkChecksStateString(fkState), queryFormat), func(t *testing.T) { mcmp, closer := start(t) defer closer() - // Set the correct keyspace to use from VtGates. - if testSharded { + if keyspace == shardedKs { t.Skip("Skip test since we don't have sharded foreign key support yet") - _ = utils.Exec(t, mcmp.VtConn, "use `ks`") - } else { - _ = utils.Exec(t, mcmp.VtConn, "use `uks`") } + // Set the correct keyspace to use from VtGates. + _ = utils.Exec(t, mcmp.VtConn, fmt.Sprintf("use `%v`", keyspace)) // Ensure that the Vitess database is originally empty ensureDatabaseState(t, mcmp.VtConn, true) @@ -739,7 +730,7 @@ func TestFkFuzzTest(t *testing.T) { fz := newFuzzer(tt.concurrency, tt.maxValForId, tt.maxValForCol, tt.insertShare, tt.deleteShare, tt.updateShare, queryFormat, fkState) // Start the fuzzer. - fz.start(t, testSharded) + fz.start(t, keyspace) // Wait for the timeForTesting so that the threads continue to run. totalTime := time.After(tt.timeForTesting) diff --git a/go/test/endtoend/vtgate/foreignkey/fk_test.go b/go/test/endtoend/vtgate/foreignkey/fk_test.go index a0678e6dba1..5a34a2b49c0 100644 --- a/go/test/endtoend/vtgate/foreignkey/fk_test.go +++ b/go/test/endtoend/vtgate/foreignkey/fk_test.go @@ -380,6 +380,7 @@ func TestFkScenarios(t *testing.T) { dataQueries []string dmlQuery string dmlShouldErr bool + skipShardScoped bool assertionQueries []string }{ { @@ -421,7 +422,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_t1(id, col) values (1, 7), (2, 9)", "insert into fk_t2(id, col) values (1, 7)", }, - dmlQuery: "update fk_t1 set col = 5 where id = 2", + dmlQuery: "update fk_t1 set col = 5 where id = 2", + skipShardScoped: true, assertionQueries: []string{ "select * from fk_t1 order by id", "select * from fk_t2 order by id", @@ -457,7 +459,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_t3(id, col) values (1, 7)", "insert into fk_t6(id, col) values (1, 7)", }, - dmlQuery: "update fk_t3 set col = 9 where id = 1", + dmlQuery: "update fk_t3 set col = 9 where id = 1", + skipShardScoped: true, assertionQueries: []string{ "select * from fk_t1 order by id", "select * from fk_t2 order by id", @@ -491,7 +494,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_t4(id, col) values (1, 7), (2, 9)", "insert into fk_t6(id, col) values (1, 7), (2, 9)", }, - dmlQuery: "update fk_t2 set col = 9 where id = 1", + dmlQuery: "update fk_t2 set col = 9 where id = 1", + skipShardScoped: true, assertionQueries: []string{ "select * from fk_t1 order by id", "select * from fk_t2 order by id", @@ -507,7 +511,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_t3(id, col) values (1, 7), (2, 9)", "insert into fk_t6(id, col) values (1, 7)", }, - dmlQuery: "delete from fk_t3 where id = 1", + dmlQuery: "delete from fk_t3 where id = 1", + skipShardScoped: true, assertionQueries: []string{ "select * from fk_t1 order by id", "select * from fk_t2 order by id", @@ -541,7 +546,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_t4(id, col) values (1, 7), (2, 9)", "insert into fk_t6(id, col) values (1, 7), (2, 9)", }, - dmlQuery: "delete from fk_t2 where id = 1", + dmlQuery: "delete from fk_t2 where id = 1", + skipShardScoped: true, assertionQueries: []string{ "select * from fk_t1 order by id", "select * from fk_t2 order by id", @@ -555,7 +561,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_t10(id, col) values (1, 7), (2, 9)", "insert into fk_t11(id, col) values (1, 7)", }, - dmlQuery: "update fk_t10 set col = 5 where id = 1", + dmlQuery: "update fk_t10 set col = 5 where id = 1", + skipShardScoped: true, assertionQueries: []string{ "select * from fk_t10 order by id", "select * from fk_t11 order by id", @@ -581,7 +588,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_t11(id, col) values (1, 7)", "insert into fk_t12(id, col) values (1, 7)", }, - dmlQuery: "update fk_t10 set col = 5 where id = 1", + dmlQuery: "update fk_t10 set col = 5 where id = 1", + skipShardScoped: true, assertionQueries: []string{ "select * from fk_t10 order by id", "select * from fk_t11 order by id", @@ -633,7 +641,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_multicol_t17(id, cola, colb) values (1, 7, 1)", "insert into fk_multicol_t18(id, cola, colb) values (1, 7, 1)", }, - dmlQuery: "delete from fk_multicol_t16 where id = 1", + dmlQuery: "delete from fk_multicol_t16 where id = 1", + skipShardScoped: true, assertionQueries: []string{ "select * from fk_multicol_t15 order by id", "select * from fk_multicol_t16 order by id", @@ -648,7 +657,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_multicol_t17(id, cola, colb) values (1, 7, 1)", "insert into fk_multicol_t18(id, cola, colb) values (1, 7, 1)", }, - dmlQuery: "delete from fk_multicol_t15 where id = 1", + dmlQuery: "delete from fk_multicol_t15 where id = 1", + skipShardScoped: true, assertionQueries: []string{ "select * from fk_multicol_t15 order by id", "select * from fk_multicol_t16 order by id", @@ -663,7 +673,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_multicol_t17(id, cola, colb) values (1, 7, 1)", "insert into fk_multicol_t18(id, cola, colb) values (1, 7, 1)", }, - dmlQuery: "update fk_multicol_t15 set cola = 3 where id = 1", + dmlQuery: "update fk_multicol_t15 set cola = 3 where id = 1", + skipShardScoped: true, assertionQueries: []string{ "select * from fk_multicol_t15 order by id", "select * from fk_multicol_t16 order by id", @@ -675,7 +686,8 @@ func TestFkScenarios(t *testing.T) { dataQueries: []string{ "insert into fk_t20(id, col, col2) values (1, 7, NULL)", }, - dmlQuery: "insert into fk_t20(id, col, col2) values (2, 9, 7), (3, 10, 9)", + skipShardScoped: true, + dmlQuery: "insert into fk_t20(id, col, col2) values (2, 9, 7), (3, 10, 9)", assertionQueries: []string{ "select * from fk_t20 order by id", }, @@ -684,8 +696,9 @@ func TestFkScenarios(t *testing.T) { dataQueries: []string{ "insert into fk_t20(id, col, col2) values (5, 7, NULL)", }, - dmlQuery: "insert into fk_t20(id, col, col2) values (6, 9, 6)", - dmlShouldErr: true, + skipShardScoped: true, + dmlQuery: "insert into fk_t20(id, col, col2) values (6, 9, 6)", + dmlShouldErr: true, assertionQueries: []string{ "select * from fk_t20 order by id", }, @@ -697,7 +710,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_multicol_t17(id, cola, colb) values (1, 7, 1)", "insert into fk_multicol_t19(id, cola, colb) values (1, 7, 1)", }, - dmlQuery: "delete fk_multicol_t15 from fk_multicol_t15 join fk_multicol_t17 where fk_multicol_t15.id = fk_multicol_t17.id", + skipShardScoped: true, + dmlQuery: "delete fk_multicol_t15 from fk_multicol_t15 join fk_multicol_t17 where fk_multicol_t15.id = fk_multicol_t17.id", assertionQueries: []string{ "select * from fk_multicol_t15 order by id", "select * from fk_multicol_t16 order by id", @@ -713,7 +727,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_multicol_t18(id, cola, colb) values (1, 7, 1), (3, 11, 1)", "insert into fk_multicol_t19(id, cola, colb) values (1, 7, 1), (2, 9, 1)", }, - dmlQuery: "delete fk_multicol_t15, fk_multicol_t17 from fk_multicol_t15 join fk_multicol_t17 where fk_multicol_t15.id = fk_multicol_t17.id", + skipShardScoped: true, + dmlQuery: "delete fk_multicol_t15, fk_multicol_t17 from fk_multicol_t15 join fk_multicol_t17 where fk_multicol_t15.id = fk_multicol_t17.id", assertionQueries: []string{ "select * from fk_multicol_t15 order by id", "select * from fk_multicol_t16 order by id", @@ -728,7 +743,8 @@ func TestFkScenarios(t *testing.T) { "insert into fk_multicol_t17(id, cola, colb) values (1, 7, 1)", "insert into fk_multicol_t19(id, cola, colb) values (1, 7, 1)", }, - dmlQuery: "delete from fk_multicol_t15 order by id limit 1", + skipShardScoped: true, + dmlQuery: "delete from fk_multicol_t15 order by id limit 1", assertionQueries: []string{ "select * from fk_multicol_t15 order by id", "select * from fk_multicol_t16 order by id", @@ -736,7 +752,8 @@ func TestFkScenarios(t *testing.T) { "select * from fk_multicol_t19 order by id", }, }, { - name: "Delete with limit 0 success", + name: "Delete with limit 0 success", + skipShardScoped: true, dataQueries: []string{ "insert into fk_multicol_t15(id, cola, colb) values (1, 7, 1), (2, 9, 1)", "insert into fk_multicol_t16(id, cola, colb) values (1, 7, 1), (2, 9, 1)", @@ -751,7 +768,8 @@ func TestFkScenarios(t *testing.T) { "select * from fk_multicol_t19 order by id", }, }, { - name: "Update with limit success", + name: "Update with limit success", + skipShardScoped: true, dataQueries: []string{ "insert into fk_multicol_t15(id, cola, colb) values (1, 7, 1), (2, 9, 1)", "insert into fk_multicol_t16(id, cola, colb) values (1, 7, 1), (2, 9, 1)", @@ -766,7 +784,8 @@ func TestFkScenarios(t *testing.T) { "select * from fk_multicol_t19 order by id", }, }, { - name: "Update with limit 0 success", + name: "Update with limit 0 success", + skipShardScoped: true, dataQueries: []string{ "insert into fk_multicol_t15(id, cola, colb) values (1, 7, 1), (2, 9, 1)", "insert into fk_multicol_t16(id, cola, colb) values (1, 7, 1), (2, 9, 1)", @@ -781,7 +800,8 @@ func TestFkScenarios(t *testing.T) { "select * from fk_multicol_t19 order by id", }, }, { - name: "Update with non-literal update and limit success", + name: "Update with non-literal update and limit success", + skipShardScoped: true, dataQueries: []string{ "insert into fk_multicol_t15(id, cola, colb) values (1, 7, 1), (2, 9, 1)", "insert into fk_multicol_t16(id, cola, colb) values (1, 7, 1), (2, 9, 1)", @@ -796,7 +816,8 @@ func TestFkScenarios(t *testing.T) { "select * from fk_multicol_t19 order by id", }, }, { - name: "Update with non-literal update order by and limit - multiple update", + name: "Update with non-literal update order by and limit - multiple update", + skipShardScoped: true, dataQueries: []string{ "insert into fk_multicol_t15(id, cola, colb) values (1, 7, 1), (2, 9, 1), (3, 12, 1)", "insert into fk_multicol_t16(id, cola, colb) values (1, 7, 1), (2, 9, 1), (3, 12, 1)", @@ -811,7 +832,8 @@ func TestFkScenarios(t *testing.T) { "select * from fk_multicol_t19 order by id", }, }, { - name: "Update with non-literal update order by and limit - single update", + name: "Update with non-literal update order by and limit - single update", + skipShardScoped: true, dataQueries: []string{ "insert into fk_multicol_t15(id, cola, colb) values (1, 7, 1), (2, 9, 1), (3, 12, 1)", "insert into fk_multicol_t16(id, cola, colb) values (1, 7, 1), (2, 9, 1), (3, 12, 1)", @@ -826,7 +848,8 @@ func TestFkScenarios(t *testing.T) { "select * from fk_multicol_t19 order by id", }, }, { - name: "Multi Table Update with non-literal update", + name: "Multi Table Update with non-literal update", + skipShardScoped: true, dataQueries: []string{ "insert into fk_multicol_t15(id, cola, colb) values (1, 7, 1), (2, 9, 1), (3, 12, 1)", "insert into fk_multicol_t16(id, cola, colb) values (1, 7, 1), (2, 9, 1), (3, 12, 1)", @@ -841,7 +864,8 @@ func TestFkScenarios(t *testing.T) { "select * from fk_multicol_t19 order by id", }, }, { - name: "Multi Target Update with non-literal update", + name: "Multi Target Update with non-literal update", + skipShardScoped: true, dataQueries: []string{ "insert into fk_multicol_t15(id, cola, colb) values (1, 7, 1), (2, 9, 1), (3, 12, 1)", "insert into fk_multicol_t16(id, cola, colb) values (1, 7, 1), (2, 9, 1), (3, 12, 1)", @@ -859,17 +883,18 @@ func TestFkScenarios(t *testing.T) { } for _, tt := range testcases { - for _, testSharded := range []bool{false, true} { - t.Run(getTestName(tt.name, testSharded), func(t *testing.T) { + for _, keyspace := range []string{unshardedKs, shardedKs, shardScopedKs} { + t.Run(getTestName(tt.name, keyspace), func(t *testing.T) { mcmp, closer := start(t) defer closer() - // Set the correct keyspace to use from VtGates. - if testSharded { + if keyspace == shardedKs { t.Skip("Skip test since we don't have sharded foreign key support yet") - _ = utils.Exec(t, mcmp.VtConn, "use `ks`") - } else { - _ = utils.Exec(t, mcmp.VtConn, "use `uks`") } + if keyspace == shardScopedKs && tt.skipShardScoped { + t.Skip("Skip test since we don't support updates in primary vindex columns") + } + // Set the correct keyspace to use from VtGates. + _ = utils.Exec(t, mcmp.VtConn, fmt.Sprintf("use `%v`", keyspace)) // Insert all the data required for running the test. for _, query := range tt.dataQueries { @@ -892,17 +917,15 @@ func TestFkScenarios(t *testing.T) { } } - for _, testSharded := range []bool{false, true} { - t.Run(getTestName("Transactions with intermediate failure", testSharded), func(t *testing.T) { + for _, keyspace := range []string{unshardedKs, shardedKs} { + t.Run(getTestName("Transactions with intermediate failure", keyspace), func(t *testing.T) { mcmp, closer := start(t) defer closer() - // Set the correct keyspace to use from VtGates. - if testSharded { + if keyspace == shardedKs { t.Skip("Skip test since we don't have sharded foreign key support yet") - _ = utils.Exec(t, mcmp.VtConn, "use `ks`") - } else { - _ = utils.Exec(t, mcmp.VtConn, "use `uks`") } + // Set the correct keyspace to use from VtGates. + _ = utils.Exec(t, mcmp.VtConn, fmt.Sprintf("use `%v`", keyspace)) // Insert some rows mcmp.Exec("INSERT INTO fk_t10(id, col) VALUES (1, 7), (2, 9), (3, 5)") @@ -1114,28 +1137,34 @@ func TestFkQueries(t *testing.T) { }, } - for _, testcase := range testcases { - t.Run(testcase.name, func(t *testing.T) { - mcmp, closer := start(t) - defer closer() - _ = utils.Exec(t, mcmp.VtConn, "use `uks`") + for _, tt := range testcases { + for _, keyspace := range []string{unshardedKs, shardedKs} { + t.Run(getTestName(tt.name, keyspace), func(t *testing.T) { + mcmp, closer := start(t) + defer closer() + if keyspace == shardedKs { + t.Skip("Skip test since we don't have sharded foreign key support yet") + } + // Set the correct keyspace to use from VtGates. + _ = utils.Exec(t, mcmp.VtConn, fmt.Sprintf("use `%v`", keyspace)) - // Ensure that the Vitess database is originally empty - ensureDatabaseState(t, mcmp.VtConn, true) - ensureDatabaseState(t, mcmp.MySQLConn, true) + // Ensure that the Vitess database is originally empty + ensureDatabaseState(t, mcmp.VtConn, true) + ensureDatabaseState(t, mcmp.MySQLConn, true) - for _, query := range testcase.queries { - _, _ = mcmp.ExecAllowAndCompareError(query) - if t.Failed() { - break + for _, query := range tt.queries { + _, _ = mcmp.ExecAllowAndCompareError(query) + if t.Failed() { + break + } } - } - // ensure Vitess database has some data. This ensures not all the commands failed. - ensureDatabaseState(t, mcmp.VtConn, false) - // Verify the consistency of the data. - verifyDataIsCorrect(t, mcmp, 1) - }) + // ensure Vitess database has some data. This ensures not all the commands failed. + ensureDatabaseState(t, mcmp.VtConn, false) + // Verify the consistency of the data. + verifyDataIsCorrect(t, mcmp, 1) + }) + } } } diff --git a/go/test/endtoend/vtgate/foreignkey/main_test.go b/go/test/endtoend/vtgate/foreignkey/main_test.go index 63590df9247..b4d610785b5 100644 --- a/go/test/endtoend/vtgate/foreignkey/main_test.go +++ b/go/test/endtoend/vtgate/foreignkey/main_test.go @@ -37,6 +37,7 @@ var ( mysqlParams mysql.ConnParams vtgateGrpcAddress string shardedKs = "ks" + shardScopedKs = "sks" unshardedKs = "uks" unshardedUnmanagedKs = "unmanaged_uks" Cell = "test" @@ -47,6 +48,9 @@ var ( //go:embed sharded_vschema.json shardedVSchema string + //go:embed shard_scoped_vschema.json + shardScopedVSchema string + //go:embed unsharded_vschema.json unshardedVSchema string @@ -119,6 +123,18 @@ func TestMain(m *testing.M) { return 1 } + // Start shard-scoped keyspace + ssKs := &cluster.Keyspace{ + Name: shardScopedKs, + SchemaSQL: schemaSQL, + VSchema: shardScopedVSchema, + } + + err = clusterInstance.StartKeyspace(*ssKs, []string{"-80", "80-"}, 1, false) + if err != nil { + return 1 + } + uKs := &cluster.Keyspace{ Name: unshardedKs, SchemaSQL: schemaSQL, @@ -196,28 +212,25 @@ func startBenchmark(b *testing.B) { } func clearOutAllData(t testing.TB, vtConn *mysql.Conn, mysqlConn *mysql.Conn) { - _ = utils.Exec(t, vtConn, "use `ks/-80`") tables := []string{"t4", "t3", "t2", "t1", "multicol_tbl2", "multicol_tbl1"} tables = append(tables, fkTables...) - for _, table := range tables { - _, _ = utils.ExecAllowError(t, vtConn, "delete /*+ SET_VAR(foreign_key_checks=OFF) */ from "+table) - _, _ = utils.ExecAllowError(t, mysqlConn, "delete /*+ SET_VAR(foreign_key_checks=OFF) */ from "+table) - } - _ = utils.Exec(t, vtConn, "use `ks/80-`") - for _, table := range tables { - _, _ = utils.ExecAllowError(t, vtConn, "delete /*+ SET_VAR(foreign_key_checks=OFF) */ from "+table) - _, _ = utils.ExecAllowError(t, mysqlConn, "delete /*+ SET_VAR(foreign_key_checks=OFF) */ from "+table) + keyspaces := []string{`ks/-80`, `ks/80-`, `sks/-80`, `sks/80-`} + for _, keyspace := range keyspaces { + _ = utils.Exec(t, vtConn, fmt.Sprintf("use `%v`", keyspace)) + for _, table := range tables { + _, _ = utils.ExecAllowError(t, vtConn, "delete /*+ SET_VAR(foreign_key_checks=OFF) */ from "+table) + _, _ = utils.ExecAllowError(t, mysqlConn, "delete /*+ SET_VAR(foreign_key_checks=OFF) */ from "+table) + } } - _ = utils.Exec(t, vtConn, "use `uks`") + tables = []string{"u_t1", "u_t2", "u_t3"} tables = append(tables, fkTables...) - for _, table := range tables { - _, _ = utils.ExecAllowError(t, vtConn, "delete /*+ SET_VAR(foreign_key_checks=OFF) */ from "+table) - _, _ = utils.ExecAllowError(t, mysqlConn, "delete /*+ SET_VAR(foreign_key_checks=OFF) */ from "+table) - } - _ = utils.Exec(t, vtConn, "use `unmanaged_uks`") - for _, table := range tables { - _, _ = utils.ExecAllowError(t, vtConn, "delete /*+ SET_VAR(foreign_key_checks=OFF) */ from "+table) - _, _ = utils.ExecAllowError(t, mysqlConn, "delete /*+ SET_VAR(foreign_key_checks=OFF) */ from "+table) + keyspaces = []string{`uks`, `unmanaged_uks`} + for _, keyspace := range keyspaces { + _ = utils.Exec(t, vtConn, fmt.Sprintf("use `%v`", keyspace)) + for _, table := range tables { + _, _ = utils.ExecAllowError(t, vtConn, "delete /*+ SET_VAR(foreign_key_checks=OFF) */ from "+table) + _, _ = utils.ExecAllowError(t, mysqlConn, "delete /*+ SET_VAR(foreign_key_checks=OFF) */ from "+table) + } } } diff --git a/go/test/endtoend/vtgate/foreignkey/shard_scoped_vschema.json b/go/test/endtoend/vtgate/foreignkey/shard_scoped_vschema.json new file mode 100644 index 00000000000..ed25d3becb0 --- /dev/null +++ b/go/test/endtoend/vtgate/foreignkey/shard_scoped_vschema.json @@ -0,0 +1,411 @@ +{ + "sharded": true, + "foreignKeyMode": "managed", + "vindexes": { + "xxhash": { + "type": "xxhash" + }, + "multicol_vdx": { + "type": "multicol", + "params": { + "column_count": "3", + "column_bytes": "1,3,4", + "column_vindex": "hash,binary,unicode_loose_xxhash" + } + }, + "multicol_fk_vdx": { + "type": "multicol", + "params": { + "column_count": "2", + "column_bytes": "4,4", + "column_vindex": "hash,binary" + } + } + }, + "tables": { + "t1": { + "column_vindexes": [ + { + "column": "id", + "name": "xxhash" + } + ] + }, + "t2": { + "column_vindexes": [ + { + "column": "id", + "name": "xxhash" + } + ] + }, + "t3": { + "column_vindexes": [ + { + "column": "id", + "name": "xxhash" + } + ] + }, + "t4": { + "column_vindexes": [ + { + "column": "id", + "name": "xxhash" + } + ] + }, + "t5": { + "column_vindexes": [ + { + "column": "sk", + "name": "xxhash" + } + ] + }, + "t6": { + "column_vindexes": [ + { + "column": "sk", + "name": "xxhash" + } + ] + }, + "multicol_tbl1": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb", + "colc" + ], + "name": "multicol_vdx" + } + ] + }, + "multicol_tbl2": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb", + "colc" + ], + "name": "multicol_vdx" + } + ] + }, + "fk_t1": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t2": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t3": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t4": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t5": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t6": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t7": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t10": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t11": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t12": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t13": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t15": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t16": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t17": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t18": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t19": { + "column_vindexes": [ + { + "column": "col", + "name": "xxhash" + } + ] + }, + "fk_t20": { + "column_vindexes": [ + { + "column": "col2", + "name": "xxhash" + } + ] + }, + "fk_multicol_t1": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t2": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t3": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t4": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t5": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t6": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t7": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t10": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t11": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t12": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t13": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t15": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t16": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t17": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t18": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + }, + "fk_multicol_t19": { + "column_vindexes": [ + { + "columns": [ + "cola", + "colb" + ], + "name": "multicol_fk_vdx" + } + ] + } + } +} \ No newline at end of file diff --git a/go/test/endtoend/vtgate/foreignkey/utils_test.go b/go/test/endtoend/vtgate/foreignkey/utils_test.go index 39267e9234a..7866db03389 100644 --- a/go/test/endtoend/vtgate/foreignkey/utils_test.go +++ b/go/test/endtoend/vtgate/foreignkey/utils_test.go @@ -36,12 +36,9 @@ import ( var supportedOpps = []string{"*", "+", "-"} -// getTestName prepends whether the test is for a sharded keyspace or not to the test name. -func getTestName(testName string, testSharded bool) string { - if testSharded { - return "Sharded - " + testName - } - return "Unsharded - " + testName +// getTestName prepends the test with keyspace name. +func getTestName(testName string, keyspace string) string { + return keyspace + " - " + testName } // isMultiColFkTable tells if the table is a multicol table or not.