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
17connection default;
18begin;
19--eval select * from $table for update;
20
21connection $con_aux;
22begin;
23--send_eval $statement;
24
25--enable_result_log
26--enable_query_log
27
28connection 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.
35let $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
43if ($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.
50connection $con_aux;
51--reap
52rollback;
53connection default;
54rollback;
55--echo Success: '$statement' doesn't take row locks on '$table'.
56}
57if (!$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.
62rollback;
63connection $con_aux;
64--reap
65rollback;
66connection default;
67--echo Error: '$statement' takes some row locks on '$table'!
68}
69
70--enable_result_log
71--enable_query_log
72