You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Duplicate entry '10' for key 'num_vdx_tbl.PRIMARY'")
43
+
utils.AssertMatches(t, mcmp.VtConn, "select id, num from s_tbl order by id", `[[INT64(1) INT64(10)]]`)
44
+
utils.AssertMatches(t, mcmp.VtConn, "select num, hex(keyspace_id) from num_vdx_tbl order by num", `[[INT64(10) VARCHAR("166B40B44ABA4BD6")]]`)
45
+
46
+
// insert duplicate row in multi-row insert multi shard
47
+
utils.AssertContainsError(t, mcmp.VtConn, "insert into s_tbl(id, num) values (3,20), (4,20),(5,30)",
48
+
"transaction rolled back to reverse changes of partial DML execution: target: sks.80-.primary: vttablet: "+
49
+
"Duplicate entry '20' for key 'num_vdx_tbl.PRIMARY'")
50
+
utils.AssertMatches(t, mcmp.VtConn, "select id, num from s_tbl order by id", `[[INT64(1) INT64(10)]]`)
51
+
utils.AssertMatches(t, mcmp.VtConn, "select num, hex(keyspace_id) from num_vdx_tbl order by num", `[[INT64(10) VARCHAR("166B40B44ABA4BD6")]]`)
52
+
53
+
// insert duplicate row in multi-row insert - lookup single shard
54
+
utils.AssertContainsError(t, mcmp.VtConn, "insert into s_tbl(id, num) values (3,20), (4,20)",
55
+
"transaction rolled back to reverse changes of partial DML execution: lookup.Create: target: sks.80-.primary: vttablet: "+
56
+
"Duplicate entry '20' for key 'num_vdx_tbl.PRIMARY'")
57
+
utils.AssertMatches(t, mcmp.VtConn, "select id, num from s_tbl order by id", `[[INT64(1) INT64(10)]]`)
58
+
utils.AssertMatches(t, mcmp.VtConn, "select num, hex(keyspace_id) from num_vdx_tbl order by num", `[[INT64(10) VARCHAR("166B40B44ABA4BD6")]]`)
59
+
60
+
// insert second row to test with limit update.
61
+
utils.Exec(t, mcmp.VtConn, "insert into s_tbl(id, num) values (10,100)")
62
+
utils.AssertMatches(t, mcmp.VtConn, "select id, num from s_tbl order by id", `[[INT64(1) INT64(10)] [INT64(10) INT64(100)]]`)
63
+
utils.AssertMatches(t, mcmp.VtConn, "select num, hex(keyspace_id) from num_vdx_tbl order by num", `[[INT64(10) VARCHAR("166B40B44ABA4BD6")] [INT64(100) VARCHAR("594764E1A2B2D98E")]]`)
64
+
65
+
// update with limit 1 succeed.
66
+
utils.Exec(t, mcmp.VtConn, "update s_tbl set num = 30 order by id limit 1")
67
+
utils.AssertMatches(t, mcmp.VtConn, "select id, num from s_tbl order by id", `[[INT64(1) INT64(30)] [INT64(10) INT64(100)]]`)
68
+
utils.AssertMatches(t, mcmp.VtConn, "select num, hex(keyspace_id) from num_vdx_tbl order by num", `[[INT64(30) VARCHAR("166B40B44ABA4BD6")] [INT64(100) VARCHAR("594764E1A2B2D98E")]]`)
69
+
70
+
// update to same value on multiple row should fail.
71
+
utils.AssertContainsError(t, mcmp.VtConn, "update s_tbl set num = 40 limit 2",
72
+
"lookup.Create: transaction rolled back to reverse changes of partial DML execution: target: sks.80-.primary: vttablet: "+
utils.AssertMatches(t, mcmp.VtConn, "select id, num from s_tbl order by id", `[[INT64(1) INT64(30)] [INT64(10) INT64(100)]]`)
75
+
utils.AssertMatches(t, mcmp.VtConn, "select num, hex(keyspace_id) from num_vdx_tbl order by num", `[[INT64(30) VARCHAR("166B40B44ABA4BD6")] [INT64(100) VARCHAR("594764E1A2B2D98E")]]`)
76
+
}
77
+
78
+
// TestUniqueLookupDuplicateIgnore tests the insert ignore on lookup table.
utils.Exec(t, mcmp.VtConn, "insert into s_tbl(id, num) values (1,10)")
85
+
utils.AssertMatches(t, mcmp.VtConn, "select id, num from s_tbl order by id", `[[INT64(1) INT64(10)]]`)
86
+
utils.AssertMatches(t, mcmp.VtConn, "select num, hex(keyspace_id) from num_vdx_tbl order by num", `[[INT64(10) VARCHAR("166B40B44ABA4BD6")]]`)
87
+
88
+
// insert ignore duplicate row
89
+
qr:=utils.Exec(t, mcmp.VtConn, "insert ignore into s_tbl(id, num) values (2,10)")
90
+
assert.EqualValues(t, 0, qr.RowsAffected)
91
+
utils.AssertMatches(t, mcmp.VtConn, "select id, num from s_tbl order by id", `[[INT64(1) INT64(10)]]`)
92
+
utils.AssertMatches(t, mcmp.VtConn, "select num, hex(keyspace_id) from num_vdx_tbl order by num", `[[INT64(10) VARCHAR("166B40B44ABA4BD6")]]`)
93
+
94
+
// insert duplicate row in multi-row insert - lookup single shard
95
+
// Current behavior does not work as expected—one of the rows should be inserted.
96
+
// The lookup table is updated, but the main table is not. This is a bug in Vitess.
97
+
// The issue occurs because the table has two vindex columns (`num` and `col`), both of which ignore nulls during vindex insertion.
98
+
// In the `INSERT IGNORE` case, after the vindex create API call, a verify call checks if the row exists in the lookup table.
99
+
// - If the row exists, it is inserted into the main table.
100
+
// - If the row does not exist, the main table insertion is skipped.
101
+
// Since the `col` column is null, the row is not inserted into the lookup table, causing the main table insertion to be ignored.
102
+
qr=utils.Exec(t, mcmp.VtConn, "insert ignore into s_tbl(id, num) values (3,20), (4,20)")
103
+
assert.EqualValues(t, 0, qr.RowsAffected)
104
+
utils.AssertMatches(t, mcmp.VtConn, "select id, num from s_tbl order by id", `[[INT64(1) INT64(10)]]`)
105
+
utils.AssertMatches(t, mcmp.VtConn, "select num, hex(keyspace_id) from num_vdx_tbl order by num", `[[INT64(10) VARCHAR("166B40B44ABA4BD6")] [INT64(20) VARCHAR("4EB190C9A2FA169C")]]`)
106
+
107
+
// insert duplicate row in multi-row insert - vindex values are not null
utils.AssertMatches(t, mcmp.VtConn, "select id, num, col from s_tbl order by id", `[[INT64(1) INT64(10) NULL] [INT64(3) INT64(20) INT64(30)]]`)
111
+
utils.AssertMatches(t, mcmp.VtConn, "select num, hex(keyspace_id) from num_vdx_tbl order by num", `[[INT64(10) VARCHAR("166B40B44ABA4BD6")] [INT64(20) VARCHAR("4EB190C9A2FA169C")]]`)
112
+
utils.AssertMatches(t, mcmp.VtConn, "select col, hex(keyspace_id) from col_vdx_tbl order by col", `[[INT64(30) VARCHAR("4EB190C9A2FA169C")]]`)
113
+
114
+
}
115
+
30
116
funcTestMultiEqual(t*testing.T) {
31
117
ifclusterInstance.HasPartialKeyspaces {
32
118
t.Skip("test uses multiple keyspaces, test framework only supports partial keyspace testing for a single keyspace")
// delete from `user` where (`user`.id) in ::dml_vals - 1 shard
3141
3143
testQueryLog(t, executor, logChan, "TestExecute", "DELETE", "delete `user` from `user` join music on `user`.col = music.col where music.user_id = 1", 18)
0 commit comments