~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/t/innodb_mysql_lock2.test

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-06-21 15:31:05 UTC
  • mfrom: (1.1.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20100621153105-pbbz3t6nyrf9t2zq
Tags: upstream-5.1.48
ImportĀ upstreamĀ versionĀ 5.1.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This test covers behavior for InnoDB tables.
 
2
--source include/have_innodb.inc
 
3
# This test requires statement/mixed mode binary logging.
 
4
# Row-based mode puts weaker serializability requirements
 
5
# so weaker locks are acquired for it.
 
6
--source include/have_binlog_format_mixed_or_statement.inc
 
7
# Save the initial number of concurrent sessions.
 
8
--source include/count_sessions.inc
 
9
 
 
10
--echo #
 
11
--echo # Test how do we handle locking in various cases when
 
12
--echo # we read data from InnoDB tables.
 
13
--echo #
 
14
--echo # In fact by performing this test we check two things:
 
15
--echo # 1) That SQL-layer correctly determine type of thr_lock.c
 
16
--echo #    lock to be acquired/passed to InnoDB engine.
 
17
--echo # 2) That InnoDB engine correctly interprets this lock
 
18
--echo #    type and takes necessary row locks or does not
 
19
--echo #    take them if they are not necessary.
 
20
--echo #
 
21
 
 
22
--echo # This test makes sense only in REPEATABLE-READ mode as
 
23
--echo # in SERIALIZABLE mode all statements that read data take
 
24
--echo # shared lock on them to enforce its semantics.
 
25
select @@session.tx_isolation;
 
26
 
 
27
--echo # Prepare playground by creating tables, views,
 
28
--echo # routines and triggers used in tests.
 
29
connect (con1, localhost, root,,);
 
30
connection default;
 
31
--disable_warnings
 
32
drop table if exists t0, t1, t2, t3, t4, t5, te;
 
33
drop view if exists v1, v2;
 
34
drop procedure if exists p1;
 
35
drop procedure if exists p2;
 
36
drop function if exists f1;
 
37
drop function if exists f2;
 
38
drop function if exists f3;
 
39
drop function if exists f4;
 
40
drop function if exists f5;
 
41
drop function if exists f6;
 
42
drop function if exists f7;
 
43
drop function if exists f8;
 
44
drop function if exists f9;
 
45
drop function if exists f10;
 
46
drop function if exists f11;
 
47
drop function if exists f12;
 
48
drop function if exists f13;
 
49
drop function if exists f14;
 
50
drop function if exists f15;
 
51
--enable_warnings
 
52
create table t1 (i int primary key) engine=innodb;
 
53
insert into t1 values (1), (2), (3), (4), (5);
 
54
create table t2 (j int primary key) engine=innodb;
 
55
insert into t2 values (1), (2), (3), (4), (5);
 
56
create table t3 (k int primary key) engine=innodb;
 
57
insert into t3 values (1), (2), (3);
 
58
create table t4 (l int primary key) engine=innodb;
 
59
insert into t4 values (1);
 
60
create table t5 (l int primary key) engine=innodb;
 
61
insert into t5 values (1);
 
62
create table te(e int primary key);
 
63
insert into te values (1);
 
64
create view v1 as select i from t1;
 
65
create view v2 as select j from t2 where j in (select i from t1);
 
66
create procedure p1(k int) insert into t2 values (k);
 
67
delimiter |;
 
68
create function f1() returns int
 
69
begin
 
70
  declare j int;
 
71
  select i from t1 where i = 1 into j;
 
72
  return j;
 
73
end|
 
74
create function f2() returns int
 
75
begin
 
76
  declare k int;
 
77
  select i from t1 where i = 1 into k;
 
78
  insert into t2 values (k + 5);
 
79
  return 0;
 
80
end|
 
81
create function f3() returns int
 
82
begin
 
83
  return (select i from t1 where i = 3);
 
84
end|
 
85
create function f4() returns int
 
86
begin
 
87
  if (select i from t1 where i = 3) then
 
88
    return 1;
 
89
  else
 
90
    return 0;
 
91
  end if;
 
92
end|
 
93
create function f5() returns int
 
94
begin
 
95
  insert into t2 values ((select i from t1 where i = 1) + 5);
 
96
  return 0;
 
97
end|
 
98
create function f6() returns int
 
99
begin
 
100
  declare k int;
 
101
  select i from v1 where i = 1 into k;
 
102
  return k;
 
103
end|
 
104
create function f7() returns int
 
105
begin
 
106
  declare k int;
 
107
  select j from v2 where j = 1 into k;
 
108
  return k;
 
109
end|
 
110
create function f8() returns int
 
111
begin
 
112
  declare k int;
 
113
  select i from v1 where i = 1 into k;
 
114
  insert into t2 values (k+5);
 
115
  return k;
 
116
end|
 
117
create function f9() returns int
 
118
begin
 
119
  update v2 set j=j+10 where j=1;
 
120
  return 1;
 
121
end|
 
122
create function f10() returns int
 
123
begin
 
124
  return f1();
 
125
end|
 
126
create function f11() returns int
 
127
begin
 
128
  declare k int;
 
129
  set k= f1();
 
130
  insert into t2 values (k+5);
 
131
  return k;
 
132
end|
 
133
create function f12(p int) returns int
 
134
begin
 
135
  insert into t2 values (p);
 
136
  return p;
 
137
end|
 
138
create function f13(p int) returns int
 
139
begin
 
140
  return p;
 
141
end|
 
142
create procedure p2(inout p int)
 
143
begin
 
144
  select i from t1 where i = 1 into p;
 
145
end|
 
146
create function f14() returns int
 
147
begin
 
148
  declare k int;
 
149
  call p2(k);
 
150
  insert into t2 values (k+5);
 
151
  return k;
 
152
end|
 
153
create function f15() returns int
 
154
begin
 
155
  declare k int;
 
156
  call p2(k);
 
157
  return k;
 
158
end|
 
159
create trigger t4_bi before insert on t4 for each row
 
160
begin
 
161
  declare k int;
 
162
  select i from t1 where i=1 into k;
 
163
  set new.l= k+1;
 
164
end|
 
165
create trigger t4_bu before update on t4 for each row
 
166
begin
 
167
  if (select i from t1 where i=1) then
 
168
    set new.l= 2;
 
169
  end if;
 
170
end|
 
171
--echo # Trigger below uses insertion of duplicate key in 'te'
 
172
--echo # table as a way to abort delete operation.
 
173
create trigger t4_bd before delete on t4 for each row
 
174
begin
 
175
  if !(select i from v1 where i=1) then
 
176
    insert into te values (1);
 
177
  end if;
 
178
end|
 
179
create trigger t5_bi before insert on t5 for each row
 
180
begin
 
181
  set new.l= f1()+1;
 
182
end|
 
183
create trigger t5_bu before update on t5 for each row
 
184
begin
 
185
  declare j int;
 
186
  call p2(j);
 
187
  set new.l= j + 1;
 
188
end|
 
189
delimiter ;|
 
190
 
 
191
--echo #
 
192
--echo # Set common variables to be used by scripts called below.
 
193
--echo #
 
194
let $con_aux= con1; 
 
195
let $table= t1;
 
196
 
 
197
 
 
198
--echo #
 
199
--echo # 1. Statements that read tables and do not use subqueries.
 
200
--echo #
 
201
 
 
202
--echo #
 
203
--echo # 1.1 Simple SELECT statement.
 
204
--echo #
 
205
--echo # No locks are necessary as this statement won't be written
 
206
--echo # to the binary log and InnoDB supports snapshots.
 
207
let $statement= select * from t1;
 
208
--source include/check_no_row_lock.inc
 
209
 
 
210
--echo #
 
211
--echo # 1.2 Multi-UPDATE statement.
 
212
--echo #
 
213
--echo # Has to take shared locks on rows in the table being read as this
 
214
--echo # statement will be written to the binary log and therefore should
 
215
--echo # be serialized with concurrent statements.
 
216
let $statement= update t2, t1 set j= j - 1 where i = j;
 
217
let $wait_statement= $statement;
 
218
--source include/check_shared_row_lock.inc
 
219
 
 
220
--echo #
 
221
--echo # 1.3 Multi-DELETE statement.
 
222
--echo #
 
223
--echo # The above is true for this statement as well.
 
224
let $statement= delete t2 from t1, t2 where i = j;
 
225
let $wait_statement= $statement;
 
226
--source include/check_shared_row_lock.inc
 
227
 
 
228
--echo #
 
229
--echo # 1.4 DESCRIBE statement.
 
230
--echo #
 
231
--echo # This statement does not really read data from the
 
232
--echo # target table and thus does not take any lock on it.
 
233
--echo # We check this for completeness of coverage.
 
234
let $statement= describe t1;
 
235
--source include/check_no_row_lock.inc
 
236
 
 
237
--echo #
 
238
--echo # 1.5 SHOW statements.
 
239
--echo # 
 
240
--echo # The above is true for SHOW statements as well.
 
241
let $statement= show create table t1;
 
242
--source include/check_no_row_lock.inc
 
243
let $statement= show keys from t1;
 
244
--source include/check_no_row_lock.inc
 
245
 
 
246
 
 
247
--echo #
 
248
--echo # 2. Statements which read tables through subqueries.
 
249
--echo #
 
250
 
 
251
--echo #
 
252
--echo # 2.1 CALL with a subquery.
 
253
--echo # 
 
254
--echo # A strong lock is not necessary as this statement is not
 
255
--echo # written to the binary log as a whole (it is written
 
256
--echo # statement-by-statement) and thanks to MVCC we can always get
 
257
--echo # versions of rows prior to the update that has locked them.
 
258
--echo # But in practice InnoDB does locking reads for all statements
 
259
--echo # other than SELECT (unless it is a READ-COMITTED mode or
 
260
--echo # innodb_locks_unsafe_for_binlog is ON).
 
261
let $statement= call p1((select i + 5 from t1 where i = 1));
 
262
let $wait_statement= $statement;
 
263
--source include/check_shared_row_lock.inc
 
264
 
 
265
--echo #
 
266
--echo # 2.2 CREATE TABLE with a subquery.
 
267
--echo #
 
268
--echo # Has to take shared locks on rows in the table being read as
 
269
--echo # this statement is written to the binary log and therefore
 
270
--echo # should be serialized with concurrent statements.
 
271
let $statement= create table t0 engine=innodb select * from t1;
 
272
let $wait_statement= $statement;
 
273
--source include/check_shared_row_lock.inc
 
274
drop table t0;
 
275
let $statement= create table t0 engine=innodb select j from t2 where j in (select i from t1);
 
276
let $wait_statement= $statement;
 
277
--source include/check_shared_row_lock.inc
 
278
drop table t0;
 
279
 
 
280
--echo #
 
281
--echo # 2.3 DELETE with a subquery.
 
282
--echo #
 
283
--echo # The above is true for this statement as well.
 
284
let $statement= delete from t2 where j in (select i from t1);
 
285
let $wait_statement= $statement;
 
286
--source include/check_shared_row_lock.inc
 
287
 
 
288
--echo #
 
289
--echo # 2.4 MULTI-DELETE with a subquery.
 
290
--echo #
 
291
--echo # Same is true for this statement as well.
 
292
let $statement= delete t2 from t3, t2 where k = j and j in (select i from t1);
 
293
let $wait_statement= $statement;
 
294
--source include/check_shared_row_lock.inc
 
295
 
 
296
--echo #
 
297
--echo # 2.5 DO with a subquery.
 
298
--echo #
 
299
--echo # In theory should not take row locks as it is not logged.
 
300
--echo # In practice InnoDB takes shared row locks.
 
301
let $statement= do (select i from t1 where i = 1);
 
302
let $wait_statement= $statement;
 
303
--source include/check_shared_row_lock.inc
 
304
 
 
305
--echo #
 
306
--echo # 2.6 INSERT with a subquery.
 
307
--echo #
 
308
--echo # Has to take shared locks on rows in the table being read as
 
309
--echo # this statement is written to the binary log and therefore
 
310
--echo # should be serialized with concurrent statements.
 
311
let $statement= insert into t2 select i+5 from t1;
 
312
let $wait_statement= $statement;
 
313
--source include/check_shared_row_lock.inc
 
314
let $statement= insert into t2 values ((select i+5 from t1 where i = 4));
 
315
let $wait_statement= $statement;
 
316
--source include/check_shared_row_lock.inc
 
317
 
 
318
--echo #
 
319
--echo # 2.7 LOAD DATA with a subquery.
 
320
--echo # 
 
321
--echo # The above is true for this statement as well.
 
322
let $statement= load data infile '../../std_data/rpl_loaddata.dat' into table t2 (@a, @b) set j= @b + (select i from t1 where i = 1);
 
323
let $wait_statement= $statement;
 
324
--source include/check_shared_row_lock.inc
 
325
 
 
326
--echo #
 
327
--echo # 2.8 REPLACE with a subquery.
 
328
--echo # 
 
329
--echo # Same is true for this statement as well.
 
330
let $statement= replace into t2 select i+5 from t1;
 
331
let $wait_statement= $statement;
 
332
--source include/check_shared_row_lock.inc
 
333
let $statement= replace into t2 values ((select i+5 from t1 where i = 4));
 
334
let $wait_statement= $statement;
 
335
--source include/check_shared_row_lock.inc
 
336
 
 
337
--echo #
 
338
--echo # 2.9 SELECT with a subquery.
 
339
--echo #
 
340
--echo # Locks are not necessary as this statement is not written
 
341
--echo # to the binary log and thanks to MVCC we can always get
 
342
--echo # versions of rows prior to the update that has locked them.
 
343
--echo #
 
344
--echo # Also serves as a test case for bug #46947 "Embedded SELECT
 
345
--echo # without FOR UPDATE is causing a lock".
 
346
let $statement= select * from t2 where j in (select i from t1);
 
347
--source include/check_no_row_lock.inc
 
348
 
 
349
--echo #
 
350
--echo # 2.10 SET with a subquery.
 
351
--echo #
 
352
--echo # In theory should not require locking as it is not written
 
353
--echo # to the binary log. In practice InnoDB acquires shared row
 
354
--echo # locks.
 
355
let $statement= set @a:= (select i from t1 where i = 1);
 
356
let $wait_statement= $statement;
 
357
--source include/check_shared_row_lock.inc
 
358
 
 
359
--echo #
 
360
--echo # 2.11 SHOW with a subquery.
 
361
--echo # 
 
362
--echo # Similarly to the previous case, in theory should not require locking
 
363
--echo # as it is not written to the binary log. In practice InnoDB
 
364
--echo # acquires shared row locks.
 
365
let $statement= show tables from test where Tables_in_test = 't2' and (select i from t1 where i = 1);
 
366
let $wait_statement= $statement;
 
367
--source include/check_shared_row_lock.inc
 
368
let $statement= show columns from t2 where (select i from t1 where i = 1);
 
369
let $wait_statement= $statement;
 
370
--source include/check_shared_row_lock.inc
 
371
 
 
372
--echo #
 
373
--echo # 2.12 UPDATE with a subquery.
 
374
--echo #
 
375
--echo # Has to take shared locks on rows in the table being read as
 
376
--echo # this statement is written to the binary log and therefore
 
377
--echo # should be serialized with concurrent statements.
 
378
let $statement= update t2 set j= j-10 where j in (select i from t1);
 
379
let $wait_statement= $statement;
 
380
--source include/check_shared_row_lock.inc
 
381
 
 
382
--echo #
 
383
--echo # 2.13 MULTI-UPDATE with a subquery.
 
384
--echo #
 
385
--echo # Same is true for this statement as well.
 
386
let $statement= update t2, t3 set j= j -10 where j=k and j in (select i from t1);
 
387
let $wait_statement= $statement;
 
388
--source include/check_shared_row_lock.inc
 
389
 
 
390
 
 
391
--echo #
 
392
--echo # 3. Statements which read tables through a view.
 
393
--echo #
 
394
 
 
395
--echo #
 
396
--echo # 3.1 SELECT statement which uses some table through a view.
 
397
--echo #
 
398
--echo # Since this statement is not written to the binary log
 
399
--echo # and old version of rows are accessible thanks to MVCC,
 
400
--echo # no locking is necessary.
 
401
let $statement= select * from v1;
 
402
--source include/check_no_row_lock.inc
 
403
let $statement= select * from v2;
 
404
--source include/check_no_row_lock.inc
 
405
let $statement= select * from t2 where j in (select i from v1);
 
406
--source include/check_no_row_lock.inc
 
407
let $statement= select * from t3 where k in (select j from v2);
 
408
--source include/check_no_row_lock.inc
 
409
 
 
410
--echo #
 
411
--echo # 3.2 Statements which modify a table and use views.
 
412
--echo #
 
413
--echo # Since such statements are going to be written to the binary
 
414
--echo # log they need to be serialized against concurrent statements
 
415
--echo # and therefore should take shared row locks on data read.
 
416
let $statement= update t2 set j= j-10 where j in (select i from v1);
 
417
let $wait_statement= $statement;
 
418
--source include/check_shared_row_lock.inc
 
419
let $statement= update t3 set k= k-10 where k in (select j from v2);
 
420
let $wait_statement= $statement;
 
421
--source include/check_shared_row_lock.inc
 
422
let $statement= update t2, v1 set j= j-10 where j = i;
 
423
let $wait_statement= $statement;
 
424
--source include/check_shared_row_lock.inc
 
425
let $statement= update v2 set j= j-10 where j = 3;
 
426
let $wait_statement= $statement;
 
427
--source include/check_shared_row_lock.inc
 
428
 
 
429
 
 
430
--echo #
 
431
--echo # 4. Statements which read tables through stored functions.
 
432
--echo #
 
433
 
 
434
--echo #
 
435
--echo # 4.1 SELECT/SET with a stored function which does not 
 
436
--echo #     modify data and uses SELECT in its turn.
 
437
--echo #
 
438
--echo # Calls to such functions won't get into the binary log and
 
439
--echo # thus don't need to acquire strong locks.
 
440
--echo # In 5.5 due to fix for bug #53921 "Wrong locks for SELECTs
 
441
--echo # used stored functions may lead to broken SBR" strong locks
 
442
--echo # are taken (we accepted it as a trade-off for this fix).
 
443
let $statement= select f1();
 
444
let $wait_statement= select i from t1 where i = 1 into j;
 
445
--source include/check_no_row_lock.inc
 
446
let $statement= set @a:= f1();
 
447
let $wait_statement= select i from t1 where i = 1 into j;
 
448
--source include/check_no_row_lock.inc
 
449
 
 
450
--echo #
 
451
--echo # 4.2 INSERT (or other statement which modifies data) with
 
452
--echo #     a stored function which does not modify data and uses
 
453
--echo #     SELECT.
 
454
--echo #
 
455
--echo # Since such statement is written to the binary log it should
 
456
--echo # be serialized with concurrent statements affecting the data
 
457
--echo # it uses. Therefore it should take row locks on the data
 
458
--echo # it reads.
 
459
--echo # But due to bug #53921 "Wrong locks for SELECTs used stored
 
460
--echo # functions may lead to broken SBR" no lock is taken.
 
461
let $statement= insert into t2 values (f1() + 5);
 
462
let $wait_statement= select i from t1 where i = 1 into j;
 
463
--source include/check_no_row_lock.inc
 
464
 
 
465
--echo #
 
466
--echo # 4.3 SELECT/SET with a stored function which
 
467
--echo #     reads and modifies data.
 
468
--echo #
 
469
--echo # Since a call to such function is written to the binary log,
 
470
--echo # it should be serialized with concurrent statements affecting
 
471
--echo # the data it uses. Hence, row locks on the data read
 
472
--echo # should be taken.
 
473
--echo # But due to bug #53921 "Wrong locks for SELECTs used stored
 
474
--echo # functions may lead to broken SBR" no lock is taken.
 
475
let $statement= select f2();
 
476
let $wait_statement= select i from t1 where i = 1 into k;
 
477
--source include/check_no_row_lock.inc
 
478
let $statement= set @a:= f2();
 
479
let $wait_statement= select i from t1 where i = 1 into k;
 
480
--source include/check_no_row_lock.inc
 
481
 
 
482
--echo #
 
483
--echo # 4.4. SELECT/SET with a stored function which does not
 
484
--echo #      modify data and reads a table through subselect
 
485
--echo #      in a control construct.
 
486
--echo #
 
487
--echo # Again, in theory a call to this function won't get to the
 
488
--echo # binary log and thus no locking is needed. But in practice
 
489
--echo # we don't detect this fact early enough (get_lock_type_for_table())
 
490
--echo # to avoid taking row locks.
 
491
let $statement= select f3();
 
492
let $wait_statement= $statement;
 
493
--source include/check_shared_row_lock.inc
 
494
let $statement= set @a:= f3();
 
495
let $wait_statement= $statement;
 
496
--source include/check_shared_row_lock.inc
 
497
let $statement= select f4();
 
498
let $wait_statement= $statement;
 
499
--source include/check_shared_row_lock.inc
 
500
let $statement= set @a:= f4();
 
501
let $wait_statement= $statement;
 
502
--source include/check_shared_row_lock.inc
 
503
 
 
504
--echo #
 
505
--echo # 4.5. INSERT (or other statement which modifies data) with
 
506
--echo #      a stored function which does not modify data and reads
 
507
--echo #      the table through a subselect in one of its control
 
508
--echo #      constructs.
 
509
--echo #
 
510
--echo # Since such statement is written to the binary log it should
 
511
--echo # be serialized with concurrent statements affecting data it
 
512
--echo # uses. Therefore it should take row locks on the data
 
513
--echo # it reads.
 
514
let $statement= insert into t2 values (f3() + 5);
 
515
let $wait_statement= $statement;
 
516
--source include/check_shared_row_lock.inc
 
517
let $statement= insert into t2 values (f4() + 6);
 
518
let $wait_statement= $statement;
 
519
--source include/check_shared_row_lock.inc
 
520
 
 
521
--echo #
 
522
--echo # 4.6 SELECT/SET which uses a stored function with
 
523
--echo #      DML which reads a table via a subquery.
 
524
--echo #
 
525
--echo # Since call to such function is written to the binary log
 
526
--echo # it should be serialized with concurrent statements.
 
527
--echo # Hence reads should take row locks.
 
528
let $statement= select f5();
 
529
let $wait_statement= insert into t2 values ((select i from t1 where i = 1) + 5);
 
530
--source include/check_shared_row_lock.inc
 
531
let $statement= set @a:= f5();
 
532
let $wait_statement= insert into t2 values ((select i from t1 where i = 1) + 5);
 
533
--source include/check_shared_row_lock.inc
 
534
 
 
535
--echo #
 
536
--echo # 4.7 SELECT/SET which uses a stored function which
 
537
--echo #     doesn't modify data and reads tables through
 
538
--echo #     a view.
 
539
--echo #
 
540
--echo # Once again, in theory, calls to such functions won't
 
541
--echo # get into the binary log and thus don't need row
 
542
--echo # locks. In practice this fact is discovered
 
543
--echo # too late to have any effect.
 
544
--echo # But due to bug #53921 "Wrong locks for SELECTs used stored
 
545
--echo # functions may lead to broken SBR" no lock is taken
 
546
--echo # in case of simple SELECT.
 
547
let $statement= select f6();
 
548
let $wait_statement= select i from v1 where i = 1 into k;
 
549
--source include/check_no_row_lock.inc
 
550
let $statement= set @a:= f6();
 
551
let $wait_statement= select i from v1 where i = 1 into k;
 
552
--source include/check_no_row_lock.inc
 
553
let $statement= select f7();
 
554
let $wait_statement= select j from v2 where j = 1 into k;
 
555
--source include/check_shared_row_lock.inc
 
556
let $statement= set @a:= f7();
 
557
let $wait_statement= select j from v2 where j = 1 into k;
 
558
--source include/check_shared_row_lock.inc
 
559
 
 
560
--echo #
 
561
--echo # 4.8 INSERT which uses stored function which
 
562
--echo #     doesn't modify data and reads a table
 
563
--echo #     through a view.
 
564
--echo #
 
565
--echo # Since such statement is written to the binary log and
 
566
--echo # should be serialized with concurrent statements affecting
 
567
--echo # the data it uses. Therefore it should take row locks on
 
568
--echo # the rows it reads.
 
569
--echo # But due to bug #53921 "Wrong locks for SELECTs used stored
 
570
--echo # functions may lead to broken SBR" no lock is taken
 
571
--echo # in case of simple SELECT.
 
572
let $statement= insert into t3 values (f6() + 5);
 
573
let $wait_statement= select i from v1 where i = 1 into k;
 
574
--source include/check_no_row_lock.inc
 
575
let $statement= insert into t3 values (f7() + 5);
 
576
let $wait_statement= select j from v2 where j = 1 into k;
 
577
--source include/check_shared_row_lock.inc
 
578
 
 
579
 
 
580
--echo #
 
581
--echo # 4.9 SELECT which uses a stored function which
 
582
--echo #     modifies data and reads tables through a view.
 
583
--echo #
 
584
--echo # Since a call to such function is written to the binary log
 
585
--echo # it should be serialized with concurrent statements.
 
586
--echo # Hence, reads should take row locks.
 
587
--echo # But due to bug #53921 "Wrong locks for SELECTs used stored
 
588
--echo # functions may lead to broken SBR" no lock is taken
 
589
--echo # in case of simple SELECT.
 
590
let $statement= select f8();
 
591
let $wait_statement= select i from v1 where i = 1 into k;
 
592
--source include/check_no_row_lock.inc
 
593
let $statement= select f9();
 
594
let $wait_statement= update v2 set j=j+10 where j=1;
 
595
--source include/check_shared_row_lock.inc
 
596
 
 
597
--echo #
 
598
--echo # 4.10 SELECT which uses stored function which doesn't modify
 
599
--echo #      data and reads a table indirectly, by calling another
 
600
--echo #      function.
 
601
--echo #
 
602
--echo # Calls to such functions won't get into the binary log and
 
603
--echo # thus don't need to acquire strong locks.
 
604
--echo # In 5.5 due to fix for bug #53921 "Wrong locks for SELECTs
 
605
--echo # used stored functions may lead to broken SBR" strong locks
 
606
--echo # are taken (we accepted it as a trade-off for this fix).
 
607
let $statement= select f10();
 
608
let $wait_statement= select i from t1 where i = 1 into j;
 
609
--source include/check_no_row_lock.inc
 
610
 
 
611
--echo #
 
612
--echo # 4.11 INSERT which uses a stored function which doesn't modify
 
613
--echo #      data and reads a table indirectly, by calling another
 
614
--echo #      function. 
 
615
--echo #
 
616
--echo # Since such statement is written to the binary log, it should
 
617
--echo # be serialized with concurrent statements affecting the data it
 
618
--echo # uses. Therefore it should take row locks on data it reads.
 
619
--echo # But due to bug #53921 "Wrong locks for SELECTs used stored
 
620
--echo # functions may lead to broken SBR" no lock is taken.
 
621
let $statement= insert into t2 values (f10() + 5);
 
622
let $wait_statement= select i from t1 where i = 1 into j;
 
623
--source include/check_no_row_lock.inc
 
624
 
 
625
--echo #
 
626
--echo # 4.12 SELECT which uses a stored function which modifies
 
627
--echo #      data and reads a table indirectly, by calling another
 
628
--echo #      function. 
 
629
--echo #
 
630
--echo # Since a call to such function is written to the binary log
 
631
--echo # it should be serialized from concurrent statements.
 
632
--echo # Hence, reads should take row locks.
 
633
--echo # But due to bug #53921 "Wrong locks for SELECTs used stored
 
634
--echo # functions may lead to broken SBR" no lock is taken.
 
635
let $statement= select f11();
 
636
let $wait_statement= select i from t1 where i = 1 into j;
 
637
--source include/check_no_row_lock.inc
 
638
 
 
639
--echo #
 
640
--echo # 4.13 SELECT that reads a table through a subquery passed
 
641
--echo #      as a parameter to a stored function which modifies
 
642
--echo #      data.
 
643
--echo #
 
644
--echo # Even though a call to this function is written to the
 
645
--echo # binary log, values of its parameters are written as literals.
 
646
--echo # So there is no need to acquire row locks on rows used in 
 
647
--echo # the subquery.
 
648
--echo # But due to the fact that in 5.1 for prelocked statements
 
649
--echo # THD::in_lock_tables is set to TRUE we acquire strong locks
 
650
--echo # (see also bug#44613 "SELECT statement inside FUNCTION takes
 
651
--echo # a shared lock" [sic!!!]).
 
652
let $statement= select f12((select i+10 from t1 where i=1));
 
653
let $wait_statement= $statement;
 
654
--source include/check_shared_row_lock.inc
 
655
 
 
656
--echo #
 
657
--echo # 4.14 INSERT that reads a table via a subquery passed
 
658
--echo #      as a parameter to a stored function which doesn't
 
659
--echo #      modify data.
 
660
--echo #
 
661
--echo # Since this statement is written to the binary log it should
 
662
--echo # be serialized with concurrent statements affecting the data it
 
663
--echo # uses. Therefore it should take row locks on the data it reads.
 
664
let $statement= insert into t2 values (f13((select i+10 from t1 where i=1)));
 
665
let $wait_statement= $statement;
 
666
--source include/check_shared_row_lock.inc
 
667
 
 
668
 
 
669
--echo #
 
670
--echo # 5. Statements that read tables through stored procedures.
 
671
--echo #
 
672
 
 
673
--echo #
 
674
--echo # 5.1 CALL statement which reads a table via SELECT.
 
675
--echo #
 
676
--echo # Since neither this statement nor its components are
 
677
--echo # written to the binary log, there is no need to take
 
678
--echo # row locks on the data it reads.
 
679
let $statement= call p2(@a);
 
680
--source include/check_no_row_lock.inc
 
681
 
 
682
--echo #
 
683
--echo # 5.2 Function that modifies data and uses CALL, 
 
684
--echo #     which reads a table through SELECT.
 
685
--echo #
 
686
--echo # Since a call to such function is written to the binary
 
687
--echo # log, it should be serialized with concurrent statements.
 
688
--echo # Hence, in this case reads should take row locks on data.
 
689
--echo # But due to bug #53921 "Wrong locks for SELECTs used stored
 
690
--echo # functions may lead to broken SBR" no lock is taken.
 
691
let $statement= select f14();
 
692
let $wait_statement= select i from t1 where i = 1 into p;
 
693
--source include/check_no_row_lock.inc
 
694
 
 
695
--echo #
 
696
--echo # 5.3 SELECT that calls a function that doesn't modify data and
 
697
--echo #     uses a CALL statement that reads a table via SELECT.
 
698
--echo #
 
699
--echo # Calls to such functions won't get into the binary log and
 
700
--echo # thus don't need to acquire strong locks.
 
701
--echo # In 5.5 due to fix for bug #53921 "Wrong locks for SELECTs
 
702
--echo # used stored functions may lead to broken SBR" strong locks
 
703
--echo # are taken (we accepted it as a trade-off for this fix).
 
704
let $statement= select f15();
 
705
let $wait_statement= select i from t1 where i = 1 into p;
 
706
--source include/check_no_row_lock.inc
 
707
 
 
708
--echo #
 
709
--echo # 5.4 INSERT which calls function which doesn't modify data and
 
710
--echo #     uses CALL statement which reads table through SELECT.
 
711
--echo #
 
712
--echo # Since such statement is written to the binary log it should
 
713
--echo # be serialized with concurrent statements affecting data it
 
714
--echo # uses. Therefore it should take row locks on data it reads.
 
715
--echo # But due to bug #53921 "Wrong locks for SELECTs used stored
 
716
--echo # functions may lead to broken SBR" no lock is taken.
 
717
let $statement= insert into t2 values (f15()+5);
 
718
let $wait_statement= select i from t1 where i = 1 into p;
 
719
--source include/check_no_row_lock.inc
 
720
 
 
721
 
 
722
--echo #
 
723
--echo # 6. Statements that use triggers.
 
724
--echo #
 
725
 
 
726
--echo #
 
727
--echo # 6.1 Statement invoking a trigger that reads table via SELECT.
 
728
--echo #
 
729
--echo # Since this statement is written to the binary log it should
 
730
--echo # be serialized with concurrent statements affecting the data
 
731
--echo # it uses. Therefore, it should take row locks on the data
 
732
--echo # it reads.
 
733
--echo # But due to bug #53921 "Wrong locks for SELECTs used stored
 
734
--echo # functions may lead to broken SBR" no lock is taken.
 
735
let $statement= insert into t4 values (2);
 
736
let $wait_statement= select i from t1 where i=1 into k;
 
737
--source include/check_no_row_lock.inc
 
738
 
 
739
--echo #
 
740
--echo # 6.2 Statement invoking a trigger that reads table through
 
741
--echo #     a subquery in a control construct.
 
742
--echo #
 
743
--echo # The above is true for this statement as well.
 
744
let $statement= update t4 set l= 2 where l = 1;
 
745
let $wait_statement= $statement;
 
746
--source include/check_shared_row_lock.inc
 
747
 
 
748
--echo #
 
749
--echo # 6.3 Statement invoking a trigger that reads a table through
 
750
--echo #     a view.
 
751
--echo #
 
752
--echo # And for this statement.
 
753
let $statement= delete from t4 where l = 1;
 
754
let $wait_statement= $statement;
 
755
--source include/check_shared_row_lock.inc
 
756
 
 
757
--echo #
 
758
--echo # 6.4 Statement invoking a trigger that reads a table through
 
759
--echo #     a stored function.
 
760
--echo #
 
761
--echo # And for this statement.
 
762
--echo # But due to bug #53921 "Wrong locks for SELECTs used stored
 
763
--echo # functions may lead to broken SBR" no lock is taken.
 
764
let $statement= insert into t5 values (2);
 
765
let $wait_statement= select i from t1 where i = 1 into j;
 
766
--source include/check_no_row_lock.inc
 
767
 
 
768
--echo #
 
769
--echo # 6.5 Statement invoking a trigger that reads a table through
 
770
--echo #     stored procedure.
 
771
--echo #
 
772
--echo # And for this statement.
 
773
--echo # But due to bug #53921 "Wrong locks for SELECTs used stored
 
774
--echo # functions may lead to broken SBR" no lock is taken.
 
775
let $statement= update t5 set l= 2 where l = 1;
 
776
let $wait_statement= select i from t1 where i = 1 into p;
 
777
--source include/check_no_row_lock.inc
 
778
 
 
779
--echo # Clean-up.
 
780
drop function f1;
 
781
drop function f2;
 
782
drop function f3;
 
783
drop function f4;
 
784
drop function f5;
 
785
drop function f6;
 
786
drop function f7;
 
787
drop function f8;
 
788
drop function f9;
 
789
drop function f10;
 
790
drop function f11;
 
791
drop function f12;
 
792
drop function f13;
 
793
drop function f14;
 
794
drop function f15;
 
795
drop view v1, v2;
 
796
drop procedure p1;
 
797
drop procedure p2;
 
798
drop table t1, t2, t3, t4, t5, te;
 
799
disconnect con1;
 
800
 
 
801
# Check that all connections opened by test cases in this file are really
 
802
# gone so execution of other tests won't be affected by their presence.
 
803
--source include/wait_until_count_sessions.inc