MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
check_no_row_lock.inc
1 #
2 # SUMMARY
3 # Check if statement affecting or reading table '$table' doesn't
4 # take any kind of locks on its rows.
5 #
6 # PARAMETERS
7 # $table Table for which presence of row locks should be checked.
8 # $con_aux Name of auxiliary connection to be used by this script.
9 # $statement Statement to be checked.
10 #
11 # EXAMPLE
12 # innodb_mysql_lock2.test
13 #
14 --disable_result_log
15 --disable_query_log
16 
17 connection default;
18 begin;
19 --eval select * from $table for update;
20 
21 connection $con_aux;
22 begin;
23 --send_eval $statement;
24 
25 --enable_result_log
26 --enable_query_log
27 
28 connection default;
29 # Wait until statement is successfully executed while
30 # all rows in table are X-locked. This means that it
31 # does not acquire any row locks.
32 # We use wait_condition.inc instead of simply reaping
33 # statement here in order to avoid deadlocks if test
34 # fails and to time out gracefully instead.
35 let $wait_condition=
36  select count(*) = 0 from information_schema.processlist
37  where info = "$statement";
38 --source include/wait_condition.inc
39 
40 --disable_result_log
41 --disable_query_log
42 
43 if ($success)
44 {
45 # Apparently statement was successfully executed and thus it
46 # has not required any row locks.
47 # To be safe against wait_condition.inc succeeding due to
48 # races let us first reap the statement being checked to
49 # ensure that it has been successfully executed.
50 connection $con_aux;
51 --reap
52 rollback;
53 connection default;
54 rollback;
55 --echo Success: '$statement' doesn't take row locks on '$table'.
56 }
57 if (!$success)
58 {
59 # Waiting has timed out. Apparently statement was blocked on
60 # some row lock. So to be able to continue we need to unlock
61 # rows first.
62 rollback;
63 connection $con_aux;
64 --reap
65 rollback;
66 connection default;
67 --echo Error: '$statement' takes some row locks on '$table'!
68 }
69 
70 --enable_result_log
71 --enable_query_log