3
# Check and select innodb lock type
6
set global innodb_table_locks=1;
8
select @@innodb_table_locks;
11
# Testing of explicit table locks with enforced table locks
14
connect (con1,localhost,root,,);
15
connect (con2,localhost,root,,);
18
drop table if exists t1;
22
# Testing of explicit table locks with enforced table locks
25
set @@innodb_table_locks=1;
28
create table t1 (id integer, x integer) engine=INNODB;
29
insert into t1 values(0, 0);
31
SELECT * from t1 where id = 0 FOR UPDATE;
36
# The following statement should hang because con1 is locking the page
42
update t1 set x=1 where id = 0;
48
update t1 set x=2 where id = 0;
59
# Try with old lock method (where LOCK TABLE is ignored by InnoDB)
62
set @@innodb_table_locks=0;
64
create table t1 (id integer primary key, x integer) engine=INNODB;
65
insert into t1 values(0, 0),(1,1),(2,2);
67
SELECT * from t1 where id = 0 FOR UPDATE;
71
set @@innodb_table_locks=0;
73
# The following statement should work becase innodb doesn't check table locks
78
# This will be locked by MySQL
80
update t1 set x=10 where id = 2;
85
# Note that we will get a deadlock if we try to select any rows marked
86
# for update by con1 !
88
SELECT * from t1 where id = 2;
89
UPDATE t1 set x=3 where id = 2;