Skip to content

Commit

Permalink
optionally disable verify-after-insert behavior of lookup vindexes (v…
Browse files Browse the repository at this point in the history
…itessio#11313)

Add a VIndex option to skip verify-after-insert behavior when using INSERT...IGNORE or INSERT...ON DUPLICATE KEY UPDATE.

Co-authored-by: Harshit Gangal <[email protected]>
Co-authored-by: Jacques Grove <[email protected]>

Signed-off-by: Max Englander <[email protected]>

Signed-off-by: Max Englander <[email protected]>
  • Loading branch information
maxenglander authored and arthurschreiber committed Oct 10, 2023
1 parent ff422b1 commit 66015fd
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 90 deletions.
121 changes: 75 additions & 46 deletions go/test/endtoend/vtgate/vindex_bindvars/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
id BIGINT NOT NULL,
field BIGINT NOT NULL,
field2 BIGINT,
field3 BIGINT,
PRIMARY KEY (id)
) ENGINE=Innodb;
Expand All @@ -56,6 +57,12 @@ CREATE TABLE lookup2 (
UNIQUE KEY (field2)
) ENGINE=Innodb;
CREATE TABLE lookup3 (
field3 BIGINT NOT NULL,
keyspace_id binary(8),
UNIQUE KEY (field3)
) ENGINE=Innodb;
CREATE TABLE thex (
id VARBINARY(64) NOT NULL,
field BIGINT NOT NULL,
Expand Down Expand Up @@ -88,7 +95,7 @@ CREATE TABLE thex (
"table": "lookup1",
"from": "field",
"to": "keyspace_id",
"ignore_nulls": "true"
"ignore_nulls": "true"
},
"owner": "t1"
},
Expand All @@ -98,7 +105,17 @@ CREATE TABLE thex (
"table": "lookup2",
"from": "field2",
"to": "keyspace_id",
"ignore_nulls": "true"
"ignore_nulls": "true"
},
"owner": "t1"
},
"lookup3": {
"type": "lookup",
"params": {
"from": "field3",
"no_verify": "true",
"table": "lookup3",
"to": "keyspace_id"
},
"owner": "t1"
}
Expand All @@ -117,6 +134,10 @@ CREATE TABLE thex (
{
"column": "field2",
"name": "lookup2"
},
{
"column": "field3",
"name": "lookup3"
}
]
},
Expand All @@ -136,6 +157,14 @@ CREATE TABLE thex (
}
]
},
"lookup3": {
"column_vindexes": [
{
"column": "field3",
"name": "binary_md5_vdx"
}
]
},
"thex": {
"column_vindexes": [
{
Expand Down Expand Up @@ -216,51 +245,51 @@ func TestVindexBindVarOverlap(t *testing.T) {
require.Nil(t, err)
defer conn.Close()

utils.Exec(t, conn, "INSERT INTO t1 (id, field, field2) VALUES "+
"(0,1,2), "+
"(1,2,3), "+
"(2,3,4), "+
"(3,4,5), "+
"(4,5,6), "+
"(5,6,7), "+
"(6,7,8), "+
"(7,8,9), "+
"(8,9,10), "+
"(9,10,11), "+
"(10,11,12), "+
"(11,12,13), "+
"(12,13,14), "+
"(13,14,15), "+
"(14,15,16), "+
"(15,16,17), "+
"(16,17,18), "+
"(17,18,19), "+
"(18,19,20), "+
"(19,20,21), "+
"(20,21,22)")
result := utils.Exec(t, conn, "select id, field, field2 from t1 order by id")
utils.Exec(t, conn, "INSERT INTO t1 (id, field, field2, field3) VALUES "+
"(0,1,2,3), "+
"(1,2,3,4), "+
"(2,3,4,5), "+
"(3,4,5,6), "+
"(4,5,6,7), "+
"(5,6,7,8), "+
"(6,7,8,9), "+
"(7,8,9,10), "+
"(8,9,10,11), "+
"(9,10,11,12), "+
"(10,11,12,13), "+
"(11,12,13,14), "+
"(12,13,14,15), "+
"(13,14,15,16), "+
"(14,15,16,17), "+
"(15,16,17,18), "+
"(16,17,18,19), "+
"(17,18,19,20), "+
"(18,19,20,21), "+
"(19,20,21,22), "+
"(20,21,22,23)")
result := utils.Exec(t, conn, "select id, field, field2, field3 from t1 order by id")

expected :=
"[[INT64(0) INT64(1) INT64(2)] " +
"[INT64(1) INT64(2) INT64(3)] " +
"[INT64(2) INT64(3) INT64(4)] " +
"[INT64(3) INT64(4) INT64(5)] " +
"[INT64(4) INT64(5) INT64(6)] " +
"[INT64(5) INT64(6) INT64(7)] " +
"[INT64(6) INT64(7) INT64(8)] " +
"[INT64(7) INT64(8) INT64(9)] " +
"[INT64(8) INT64(9) INT64(10)] " +
"[INT64(9) INT64(10) INT64(11)] " +
"[INT64(10) INT64(11) INT64(12)] " +
"[INT64(11) INT64(12) INT64(13)] " +
"[INT64(12) INT64(13) INT64(14)] " +
"[INT64(13) INT64(14) INT64(15)] " +
"[INT64(14) INT64(15) INT64(16)] " +
"[INT64(15) INT64(16) INT64(17)] " +
"[INT64(16) INT64(17) INT64(18)] " +
"[INT64(17) INT64(18) INT64(19)] " +
"[INT64(18) INT64(19) INT64(20)] " +
"[INT64(19) INT64(20) INT64(21)] " +
"[INT64(20) INT64(21) INT64(22)]]"
"[[INT64(0) INT64(1) INT64(2) INT64(3)] " +
"[INT64(1) INT64(2) INT64(3) INT64(4)] " +
"[INT64(2) INT64(3) INT64(4) INT64(5)] " +
"[INT64(3) INT64(4) INT64(5) INT64(6)] " +
"[INT64(4) INT64(5) INT64(6) INT64(7)] " +
"[INT64(5) INT64(6) INT64(7) INT64(8)] " +
"[INT64(6) INT64(7) INT64(8) INT64(9)] " +
"[INT64(7) INT64(8) INT64(9) INT64(10)] " +
"[INT64(8) INT64(9) INT64(10) INT64(11)] " +
"[INT64(9) INT64(10) INT64(11) INT64(12)] " +
"[INT64(10) INT64(11) INT64(12) INT64(13)] " +
"[INT64(11) INT64(12) INT64(13) INT64(14)] " +
"[INT64(12) INT64(13) INT64(14) INT64(15)] " +
"[INT64(13) INT64(14) INT64(15) INT64(16)] " +
"[INT64(14) INT64(15) INT64(16) INT64(17)] " +
"[INT64(15) INT64(16) INT64(17) INT64(18)] " +
"[INT64(16) INT64(17) INT64(18) INT64(19)] " +
"[INT64(17) INT64(18) INT64(19) INT64(20)] " +
"[INT64(18) INT64(19) INT64(20) INT64(21)] " +
"[INT64(19) INT64(20) INT64(21) INT64(22)] " +
"[INT64(20) INT64(21) INT64(22) INT64(23)]]"
assert.Equal(t, expected, fmt.Sprintf("%v", result.Rows))
}
6 changes: 6 additions & 0 deletions go/vt/vtexplain/testdata/test-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,9 @@ CREATE TABLE orders_id_lookup (
keyspace_id varbinary(128),
primary key(id)
);

CREATE TABLE orders_id_lookup_no_verify (
id int NOT NULL,
keyspace_id varbinary(128),
primary key(id)
);
18 changes: 18 additions & 0 deletions go/vt/vtexplain/testdata/test-vschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
},
"owner": "orders"
},
"orders_id_vdx_no_verify": {
"type": "lookup_unique",
"params": {
"table": "orders_id_lookup_no_verify",
"from": "id",
"to": "keyspace_id",
"no_verify": "true"
},
"owner": "orders"
},
"music_user_map": {
"type": "lookup_hash_unique",
"owner": "music",
Expand Down Expand Up @@ -165,6 +175,14 @@
}
]
},
"orders_id_lookup_no_verify": {
"column_vindexes": [
{
"column": "id",
"name": "hash"
}
]
},
"email_customer_map": {
"column_vindexes": [
{
Expand Down
Loading

0 comments on commit 66015fd

Please sign in to comment.