Skip to content

Commit 8603fda

Browse files
maxenglanderarthurschreiber
authored andcommitted
add option to disable lookup read lock (vitessio#11538)
DML to lookup VIndexes unconditionally takes a row lock on rows in the lookup VIndex backing table. Add an option to optionally elide this lock for cases where we know via business logic that the row will not be deleted, nor the lookup column changed. Signed-off-by: Max Englander <[email protected]> Signed-off-by: Max Englander <[email protected]>
1 parent 66015fd commit 8603fda

File tree

8 files changed

+676
-88
lines changed

8 files changed

+676
-88
lines changed

go/test/endtoend/vtgate/vindex_bindvars/main_test.go

Lines changed: 131 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ var (
4242
field BIGINT NOT NULL,
4343
field2 BIGINT,
4444
field3 BIGINT,
45+
field4 BIGINT,
46+
field5 BIGINT,
47+
field6 BIGINT,
4548
PRIMARY KEY (id)
4649
) ENGINE=Innodb;
4750
@@ -63,6 +66,24 @@ CREATE TABLE lookup3 (
6366
UNIQUE KEY (field3)
6467
) ENGINE=Innodb;
6568
69+
CREATE TABLE lookup4 (
70+
field4 BIGINT NOT NULL,
71+
keyspace_id binary(8),
72+
UNIQUE KEY (field4)
73+
) ENGINE=Innodb;
74+
75+
CREATE TABLE lookup5 (
76+
field5 BIGINT NOT NULL,
77+
keyspace_id binary(8),
78+
UNIQUE KEY (field5)
79+
) ENGINE=Innodb;
80+
81+
CREATE TABLE lookup6 (
82+
field6 BIGINT NOT NULL,
83+
keyspace_id binary(8),
84+
UNIQUE KEY (field6)
85+
) ENGINE=Innodb;
86+
6687
CREATE TABLE thex (
6788
id VARBINARY(64) NOT NULL,
6889
field BIGINT NOT NULL,
@@ -118,6 +139,36 @@ CREATE TABLE thex (
118139
"to": "keyspace_id"
119140
},
120141
"owner": "t1"
142+
},
143+
"lookup4": {
144+
"type": "lookup",
145+
"params": {
146+
"from": "field4",
147+
"read_lock": "exclusive",
148+
"table": "lookup4",
149+
"to": "keyspace_id"
150+
},
151+
"owner": "t1"
152+
},
153+
"lookup5": {
154+
"type": "lookup",
155+
"params": {
156+
"from": "field5",
157+
"read_lock": "shared",
158+
"table": "lookup5",
159+
"to": "keyspace_id"
160+
},
161+
"owner": "t1"
162+
},
163+
"lookup6": {
164+
"type": "lookup",
165+
"params": {
166+
"from": "field6",
167+
"read_lock": "none",
168+
"table": "lookup6",
169+
"to": "keyspace_id"
170+
},
171+
"owner": "t1"
121172
}
122173
},
123174
"tables": {
@@ -138,6 +189,18 @@ CREATE TABLE thex (
138189
{
139190
"column": "field3",
140191
"name": "lookup3"
192+
},
193+
{
194+
"column": "field4",
195+
"name": "lookup4"
196+
},
197+
{
198+
"column": "field5",
199+
"name": "lookup5"
200+
},
201+
{
202+
"column": "field6",
203+
"name": "lookup6"
141204
}
142205
]
143206
},
@@ -165,6 +228,30 @@ CREATE TABLE thex (
165228
}
166229
]
167230
},
231+
"lookup4": {
232+
"column_vindexes": [
233+
{
234+
"column": "field4",
235+
"name": "binary_md5_vdx"
236+
}
237+
]
238+
},
239+
"lookup5": {
240+
"column_vindexes": [
241+
{
242+
"column": "field5",
243+
"name": "binary_md5_vdx"
244+
}
245+
]
246+
},
247+
"lookup6": {
248+
"column_vindexes": [
249+
{
250+
"column": "field6",
251+
"name": "binary_md5_vdx"
252+
}
253+
]
254+
},
168255
"thex": {
169256
"column_vindexes": [
170257
{
@@ -245,51 +332,51 @@ func TestVindexBindVarOverlap(t *testing.T) {
245332
require.Nil(t, err)
246333
defer conn.Close()
247334

248-
utils.Exec(t, conn, "INSERT INTO t1 (id, field, field2, field3) VALUES "+
249-
"(0,1,2,3), "+
250-
"(1,2,3,4), "+
251-
"(2,3,4,5), "+
252-
"(3,4,5,6), "+
253-
"(4,5,6,7), "+
254-
"(5,6,7,8), "+
255-
"(6,7,8,9), "+
256-
"(7,8,9,10), "+
257-
"(8,9,10,11), "+
258-
"(9,10,11,12), "+
259-
"(10,11,12,13), "+
260-
"(11,12,13,14), "+
261-
"(12,13,14,15), "+
262-
"(13,14,15,16), "+
263-
"(14,15,16,17), "+
264-
"(15,16,17,18), "+
265-
"(16,17,18,19), "+
266-
"(17,18,19,20), "+
267-
"(18,19,20,21), "+
268-
"(19,20,21,22), "+
269-
"(20,21,22,23)")
270-
result := utils.Exec(t, conn, "select id, field, field2, field3 from t1 order by id")
335+
utils.Exec(t, conn, "INSERT INTO t1 (id, field, field2, field3, field4, field5, field6) VALUES "+
336+
"(0,1,2,3,4,5,6), "+
337+
"(1,2,3,4,5,6,7), "+
338+
"(2,3,4,5,6,7,8), "+
339+
"(3,4,5,6,7,8,9), "+
340+
"(4,5,6,7,8,9,10), "+
341+
"(5,6,7,8,9,10,11), "+
342+
"(6,7,8,9,10,11,12), "+
343+
"(7,8,9,10,11,12,13), "+
344+
"(8,9,10,11,12,13,14), "+
345+
"(9,10,11,12,13,14,15), "+
346+
"(10,11,12,13,14,15,16), "+
347+
"(11,12,13,14,15,16,17), "+
348+
"(12,13,14,15,16,17,18), "+
349+
"(13,14,15,16,17,18,19), "+
350+
"(14,15,16,17,18,19,20), "+
351+
"(15,16,17,18,19,20,21), "+
352+
"(16,17,18,19,20,21,22), "+
353+
"(17,18,19,20,21,22,23), "+
354+
"(18,19,20,21,22,23,24), "+
355+
"(19,20,21,22,23,24,25), "+
356+
"(20,21,22,23,24,25,26)")
357+
result := utils.Exec(t, conn, "select id, field, field2, field3, field4, field5, field6 from t1 order by id")
271358

272359
expected :=
273-
"[[INT64(0) INT64(1) INT64(2) INT64(3)] " +
274-
"[INT64(1) INT64(2) INT64(3) INT64(4)] " +
275-
"[INT64(2) INT64(3) INT64(4) INT64(5)] " +
276-
"[INT64(3) INT64(4) INT64(5) INT64(6)] " +
277-
"[INT64(4) INT64(5) INT64(6) INT64(7)] " +
278-
"[INT64(5) INT64(6) INT64(7) INT64(8)] " +
279-
"[INT64(6) INT64(7) INT64(8) INT64(9)] " +
280-
"[INT64(7) INT64(8) INT64(9) INT64(10)] " +
281-
"[INT64(8) INT64(9) INT64(10) INT64(11)] " +
282-
"[INT64(9) INT64(10) INT64(11) INT64(12)] " +
283-
"[INT64(10) INT64(11) INT64(12) INT64(13)] " +
284-
"[INT64(11) INT64(12) INT64(13) INT64(14)] " +
285-
"[INT64(12) INT64(13) INT64(14) INT64(15)] " +
286-
"[INT64(13) INT64(14) INT64(15) INT64(16)] " +
287-
"[INT64(14) INT64(15) INT64(16) INT64(17)] " +
288-
"[INT64(15) INT64(16) INT64(17) INT64(18)] " +
289-
"[INT64(16) INT64(17) INT64(18) INT64(19)] " +
290-
"[INT64(17) INT64(18) INT64(19) INT64(20)] " +
291-
"[INT64(18) INT64(19) INT64(20) INT64(21)] " +
292-
"[INT64(19) INT64(20) INT64(21) INT64(22)] " +
293-
"[INT64(20) INT64(21) INT64(22) INT64(23)]]"
360+
"[[INT64(0) INT64(1) INT64(2) INT64(3) INT64(4) INT64(5) INT64(6)] " +
361+
"[INT64(1) INT64(2) INT64(3) INT64(4) INT64(5) INT64(6) INT64(7)] " +
362+
"[INT64(2) INT64(3) INT64(4) INT64(5) INT64(6) INT64(7) INT64(8)] " +
363+
"[INT64(3) INT64(4) INT64(5) INT64(6) INT64(7) INT64(8) INT64(9)] " +
364+
"[INT64(4) INT64(5) INT64(6) INT64(7) INT64(8) INT64(9) INT64(10)] " +
365+
"[INT64(5) INT64(6) INT64(7) INT64(8) INT64(9) INT64(10) INT64(11)] " +
366+
"[INT64(6) INT64(7) INT64(8) INT64(9) INT64(10) INT64(11) INT64(12)] " +
367+
"[INT64(7) INT64(8) INT64(9) INT64(10) INT64(11) INT64(12) INT64(13)] " +
368+
"[INT64(8) INT64(9) INT64(10) INT64(11) INT64(12) INT64(13) INT64(14)] " +
369+
"[INT64(9) INT64(10) INT64(11) INT64(12) INT64(13) INT64(14) INT64(15)] " +
370+
"[INT64(10) INT64(11) INT64(12) INT64(13) INT64(14) INT64(15) INT64(16)] " +
371+
"[INT64(11) INT64(12) INT64(13) INT64(14) INT64(15) INT64(16) INT64(17)] " +
372+
"[INT64(12) INT64(13) INT64(14) INT64(15) INT64(16) INT64(17) INT64(18)] " +
373+
"[INT64(13) INT64(14) INT64(15) INT64(16) INT64(17) INT64(18) INT64(19)] " +
374+
"[INT64(14) INT64(15) INT64(16) INT64(17) INT64(18) INT64(19) INT64(20)] " +
375+
"[INT64(15) INT64(16) INT64(17) INT64(18) INT64(19) INT64(20) INT64(21)] " +
376+
"[INT64(16) INT64(17) INT64(18) INT64(19) INT64(20) INT64(21) INT64(22)] " +
377+
"[INT64(17) INT64(18) INT64(19) INT64(20) INT64(21) INT64(22) INT64(23)] " +
378+
"[INT64(18) INT64(19) INT64(20) INT64(21) INT64(22) INT64(23) INT64(24)] " +
379+
"[INT64(19) INT64(20) INT64(21) INT64(22) INT64(23) INT64(24) INT64(25)] " +
380+
"[INT64(20) INT64(21) INT64(22) INT64(23) INT64(24) INT64(25) INT64(26)]]"
294381
assert.Equal(t, expected, fmt.Sprintf("%v", result.Rows))
295382
}

go/vt/vtexplain/testdata/test-schema.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ CREATE TABLE orders_id_lookup (
112112
primary key(id)
113113
);
114114

115+
CREATE TABLE orders_id_lookup_exclusive_read_lock (
116+
id int NOT NULL,
117+
keyspace_id varbinary(128),
118+
primary key(id)
119+
);
120+
121+
CREATE TABLE orders_id_lookup_shared_read_lock (
122+
id int NOT NULL,
123+
keyspace_id varbinary(128),
124+
primary key(id)
125+
);
126+
127+
CREATE TABLE orders_id_lookup_no_read_lock (
128+
id int NOT NULL,
129+
keyspace_id varbinary(128),
130+
primary key(id)
131+
);
132+
115133
CREATE TABLE orders_id_lookup_no_verify (
116134
id int NOT NULL,
117135
keyspace_id varbinary(128),

go/vt/vtexplain/testdata/test-vschema.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,36 @@
1919
},
2020
"owner": "orders"
2121
},
22+
"orders_id_vdx_exclusive_read_lock": {
23+
"type": "lookup_unique",
24+
"params": {
25+
"table": "orders_id_lookup_exclusive_read_lock",
26+
"from": "id",
27+
"to": "keyspace_id",
28+
"read_lock": "exclusive"
29+
},
30+
"owner": "orders"
31+
},
32+
"orders_id_vdx_shared_read_lock": {
33+
"type": "lookup_unique",
34+
"params": {
35+
"table": "orders_id_lookup_shared_read_lock",
36+
"from": "id",
37+
"to": "keyspace_id",
38+
"read_lock": "shared"
39+
},
40+
"owner": "orders"
41+
},
42+
"orders_id_vdx_no_read_lock": {
43+
"type": "lookup_unique",
44+
"params": {
45+
"table": "orders_id_lookup_no_read_lock",
46+
"from": "id",
47+
"to": "keyspace_id",
48+
"read_lock": "none"
49+
},
50+
"owner": "orders"
51+
},
2252
"orders_id_vdx_no_verify": {
2353
"type": "lookup_unique",
2454
"params": {
@@ -175,6 +205,14 @@
175205
}
176206
]
177207
},
208+
"orders_id_lookup_no_read_lock": {
209+
"column_vindexes": [
210+
{
211+
"column": "id",
212+
"name": "hash"
213+
}
214+
]
215+
},
178216
"orders_id_lookup_no_verify": {
179217
"column_vindexes": [
180218
{

0 commit comments

Comments
 (0)