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

« back to all changes in this revision

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