~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
-- source include/have_innodb.inc
2
3
#
4
# Check and select innodb lock type
5
#
6
7
set global innodb_table_locks=1;
8
9
select @@innodb_table_locks;
10
11
#
12
# Testing of explicit table locks with enforced table locks
13
#
14
15
connect (con1,localhost,root,,);
16
connect (con2,localhost,root,,);
17
18
--disable_warnings
19
drop table if exists t1;
20
--enable_warnings
21
22
#
23
# Testing of explicit table locks with enforced table locks
24
#
25
26
set @@innodb_table_locks=1;
27
28
connection con1;
29
create table t1 (id integer, x integer) engine=INNODB;
30
insert into t1 values(0, 0);
31
set autocommit=0;
32
SELECT * from t1 where id = 0 FOR UPDATE;
33
34
connection con2;
35
set autocommit=0;
36
37
# The following statement should hang because con1 is locking the page
38
--send
39
lock table t1 write;
40
--sleep 2
41
42
connection con1;
43
update t1 set x=1 where id = 0;
44
select * from t1;
45
commit;
46
47
connection con2;
48
reap;
49
update t1 set x=2 where id = 0;
50
commit;
51
unlock tables;
52
53
connection con1;
54
select * from t1;
55
commit;
56
57
drop table t1;
58
59
#
60
# Try with old lock method (where LOCK TABLE is ignored by InnoDB)
61
#
62
63
set @@innodb_table_locks=0;
64
65
create table t1 (id integer primary key, x integer) engine=INNODB;
66
insert into t1 values(0, 0),(1,1),(2,2);
67
commit;
68
SELECT * from t1 where id = 0 FOR UPDATE;
69
70
connection con2;
71
set autocommit=0;
72
set @@innodb_table_locks=0;
73
74
# The following statement should work becase innodb doesn't check table locks
75
lock table t1 write;
76
77
connection con1;
78
79
# This will be locked by MySQL
80
--send
81
update t1 set x=10 where id = 2;
82
--sleep 2
83
84
connection con2;
85
86
# Note that we will get a deadlock if we try to select any rows marked
87
# for update by con1 !
88
89
SELECT * from t1 where id = 2;
90
UPDATE t1 set x=3 where id = 2;
91
commit;
92
SELECT * from t1;
93
commit;
94
unlock tables;
95
96
connection con1;
97
reap;
98
commit;
99
select * from t1;
100
drop table t1;
101
102
# End of 4.1 tests