From 5a38b9e370ae205fec6145c2cb67a4864a65720b Mon Sep 17 00:00:00 2001 From: "vitess-bot[bot]" <108069721+vitess-bot[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 10:45:20 +0100 Subject: [PATCH 1/2] [release-20.0] [release-21.0] DML test fix for duplicate column value (#17980) (#17987) Signed-off-by: Harshit Gangal Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com> --- .../endtoend/vtgate/queries/dml/dml_test.go | 14 +++++------ .../endtoend/vtgate/queries/dml/main_test.go | 2 +- .../vtgate/queries/dml/sharded_schema.sql | 10 ++++++++ .../endtoend/vtgate/queries/dml/vschema.json | 25 ++++++++++++++++++- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/go/test/endtoend/vtgate/queries/dml/dml_test.go b/go/test/endtoend/vtgate/queries/dml/dml_test.go index c3d1acdec4d..71e60ce6587 100644 --- a/go/test/endtoend/vtgate/queries/dml/dml_test.go +++ b/go/test/endtoend/vtgate/queries/dml/dml_test.go @@ -82,7 +82,7 @@ func TestDeleteWithLimit(t *testing.T) { defer closer() // initial rows - mcmp.Exec("insert into s_tbl(id, num) values (1,10), (2,10), (3,10), (4,20), (5,5), (6,15), (7,17), (8,80)") + mcmp.Exec("insert into s_tbl(id, col) values (1,10), (2,10), (3,10), (4,20), (5,5), (6,15), (7,17), (8,80)") mcmp.Exec("insert into order_tbl(region_id, oid, cust_no) values (1,1,4), (1,2,2), (2,3,5), (2,4,55)") // check rows @@ -92,14 +92,14 @@ func TestDeleteWithLimit(t *testing.T) { `[[INT64(1) INT64(1) INT64(4)] [INT64(1) INT64(2) INT64(2)] [INT64(2) INT64(3) INT64(5)] [INT64(2) INT64(4) INT64(55)]]`) // delete with limit - qr := mcmp.Exec(`delete from s_tbl order by num, id limit 3`) + qr := mcmp.Exec(`delete from s_tbl order by col, id limit 3`) require.EqualValues(t, 3, qr.RowsAffected) qr = mcmp.Exec(`delete from order_tbl where region_id = 1 limit 1`) require.EqualValues(t, 1, qr.RowsAffected) // check rows - mcmp.AssertMatches(`select id, num from s_tbl order by id`, + mcmp.AssertMatches(`select id, col from s_tbl order by id`, `[[INT64(3) INT64(10)] [INT64(4) INT64(20)] [INT64(6) INT64(15)] [INT64(7) INT64(17)] [INT64(8) INT64(80)]]`) // 2 rows matches but limit is 1, so any one of the row can remain in table. mcmp.AssertMatchesAnyNoCompare(`select region_id, oid, cust_no from order_tbl order by oid`, @@ -107,15 +107,15 @@ func TestDeleteWithLimit(t *testing.T) { `[[INT64(1) INT64(1) INT64(4)] [INT64(2) INT64(3) INT64(5)] [INT64(2) INT64(4) INT64(55)]]`) // delete with limit - qr = mcmp.Exec(`delete from s_tbl where num < 20 limit 2`) + qr = mcmp.Exec(`delete from s_tbl where col < 20 limit 2`) require.EqualValues(t, 2, qr.RowsAffected) qr = mcmp.Exec(`delete from order_tbl limit 5`) require.EqualValues(t, 3, qr.RowsAffected) // check rows - // 3 rows matches `num < 20` but limit is 2 so any one of them can remain in the table. - mcmp.AssertMatchesAnyNoCompare(`select id, num from s_tbl order by id`, + // 3 rows matches `col < 20` but limit is 2 so any one of them can remain in the table. + mcmp.AssertMatchesAnyNoCompare(`select id, col from s_tbl order by id`, `[[INT64(4) INT64(20)] [INT64(7) INT64(17)] [INT64(8) INT64(80)]]`, `[[INT64(3) INT64(10)] [INT64(4) INT64(20)] [INT64(8) INT64(80)]]`, `[[INT64(4) INT64(20)] [INT64(6) INT64(15)] [INT64(8) INT64(80)]]`) @@ -127,7 +127,7 @@ func TestDeleteWithLimit(t *testing.T) { mcmp.Exec(`delete from order_tbl limit 5`) // try with limit again on empty table. - qr = mcmp.Exec(`delete from s_tbl where num < 20 limit 2`) + qr = mcmp.Exec(`delete from s_tbl where col < 20 limit 2`) require.EqualValues(t, 0, qr.RowsAffected) qr = mcmp.Exec(`delete from order_tbl limit 5`) diff --git a/go/test/endtoend/vtgate/queries/dml/main_test.go b/go/test/endtoend/vtgate/queries/dml/main_test.go index bc72acc1159..3c8aa6f30a8 100644 --- a/go/test/endtoend/vtgate/queries/dml/main_test.go +++ b/go/test/endtoend/vtgate/queries/dml/main_test.go @@ -131,7 +131,7 @@ func start(t *testing.T) (utils.MySQLCompare, func()) { _, _ = utils.ExecAllowError(t, mcmp.VtConn, "set workload = oltp") tables := []string{ - "s_tbl", "num_vdx_tbl", "user_tbl", "order_tbl", "oevent_tbl", "oextra_tbl", + "s_tbl", "num_vdx_tbl", "col_vdx_tbl", "user_tbl", "order_tbl", "oevent_tbl", "oextra_tbl", "auto_tbl", "oid_vdx_tbl", "unq_idx", "nonunq_idx", "u_tbl", "mixed_tbl", "lkp_map_idx", "j_tbl", "j_utbl", } for _, table := range tables { diff --git a/go/test/endtoend/vtgate/queries/dml/sharded_schema.sql b/go/test/endtoend/vtgate/queries/dml/sharded_schema.sql index cc24737a0fa..703e11e705b 100644 --- a/go/test/endtoend/vtgate/queries/dml/sharded_schema.sql +++ b/go/test/endtoend/vtgate/queries/dml/sharded_schema.sql @@ -2,6 +2,8 @@ create table s_tbl ( id bigint, num bigint, + col bigint, + unique key (num), primary key (id) ) Engine = InnoDB; @@ -12,6 +14,14 @@ create table num_vdx_tbl primary key (num) ) Engine = InnoDB; +create table col_vdx_tbl +( + col bigint, + id bigint, + keyspace_id varbinary(20), + primary key (col, id) +) Engine = InnoDB; + create table user_tbl ( id bigint, diff --git a/go/test/endtoend/vtgate/queries/dml/vschema.json b/go/test/endtoend/vtgate/queries/dml/vschema.json index 72a949a49e4..9ba4ce9ebfb 100644 --- a/go/test/endtoend/vtgate/queries/dml/vschema.json +++ b/go/test/endtoend/vtgate/queries/dml/vschema.json @@ -9,7 +9,18 @@ "params": { "table": "num_vdx_tbl", "from": "num", - "to": "keyspace_id" + "to": "keyspace_id", + "ignore_nulls": "true" + }, + "owner": "s_tbl" + }, + "col_vdx": { + "type": "consistent_lookup", + "params": { + "table": "col_vdx_tbl", + "from": "col,id", + "to": "keyspace_id", + "ignore_nulls": "true" }, "owner": "s_tbl" }, @@ -63,6 +74,10 @@ { "column": "num", "name": "num_vdx" + }, + { + "columns": ["col", "id"], + "name": "col_vdx" } ] }, @@ -74,6 +89,14 @@ } ] }, + "col_vdx_tbl": { + "column_vindexes": [ + { + "column": "col", + "name": "hash" + } + ] + }, "user_tbl": { "auto_increment": { "column": "id", From 8beb893ef60f22ac1dc47d9a7307c65875f64665 Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Tue, 8 Apr 2025 12:51:16 +0530 Subject: [PATCH 2/2] test: fix Signed-off-by: Harshit Gangal --- go/test/endtoend/vtgate/queries/dml/dml_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/test/endtoend/vtgate/queries/dml/dml_test.go b/go/test/endtoend/vtgate/queries/dml/dml_test.go index 71e60ce6587..abcc82a2a9d 100644 --- a/go/test/endtoend/vtgate/queries/dml/dml_test.go +++ b/go/test/endtoend/vtgate/queries/dml/dml_test.go @@ -86,7 +86,7 @@ func TestDeleteWithLimit(t *testing.T) { mcmp.Exec("insert into order_tbl(region_id, oid, cust_no) values (1,1,4), (1,2,2), (2,3,5), (2,4,55)") // check rows - mcmp.AssertMatches(`select id, num from s_tbl order by id`, + mcmp.AssertMatches(`select id, col from s_tbl order by id`, `[[INT64(1) INT64(10)] [INT64(2) INT64(10)] [INT64(3) INT64(10)] [INT64(4) INT64(20)] [INT64(5) INT64(5)] [INT64(6) INT64(15)] [INT64(7) INT64(17)] [INT64(8) INT64(80)]]`) mcmp.AssertMatches(`select region_id, oid, cust_no from order_tbl order by oid`, `[[INT64(1) INT64(1) INT64(4)] [INT64(1) INT64(2) INT64(2)] [INT64(2) INT64(3) INT64(5)] [INT64(2) INT64(4) INT64(55)]]`)