ndb_lock.test 3.66 KB
Newer Older
unknown's avatar
unknown committed
1
-- source include/have_ndb.inc
unknown's avatar
unknown committed
2
-- source include/not_embedded.inc
unknown's avatar
unknown committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

connect (con1,localhost,root,,);
connect (con2,localhost,root,,);

--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7;
--enable_warnings

#
# Transaction lock test to show that the NDB 
# table handler is working properly with
# transaction locks
#

#
# Testing of scan isolation
#
connection con1;
create table t1 (x integer not null primary key, y varchar(32)) engine = ndb;
insert into t1 values (1,'one'), (2,'two');
23
select * from t1 order by x;
unknown's avatar
unknown committed
24 25

connection con2;
26
select * from t1 order by x;
unknown's avatar
unknown committed
27 28

connection con1;
29 30 31
start transaction; 
insert into t1 values (3,'three'); 
select * from t1 order by x;
unknown's avatar
unknown committed
32 33

connection con2;
34 35
start transaction; 
select * from t1 order by x;
unknown's avatar
unknown committed
36 37 38 39 40

connection con1;
commit;

connection con2;
41
select * from t1 order by x;
unknown's avatar
unknown committed
42
commit;
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

drop table t1;

###
# Bug#6020
create table t1 (pk integer not null primary key, u int not null, o int not null, 
                 unique(u), key(o)) engine = ndb;
insert into t1 values (1,1,1), (2,2,2), (3,3,3), (4,4,4), (5,5,5);

lock tables t1 write;
delete from t1 where pk = 1;
unlock tables;
select * from t1 order by pk;
insert into t1 values (1,1,1);

lock tables t1 write;
delete from t1 where u = 1;
unlock tables;
select * from t1 order by pk;
insert into t1 values (1,1,1);

lock tables t1 write;
delete from t1 where o = 1;
unlock tables;
select * from t1 order by pk;
insert into t1 values (1,1,1);

drop table t1;

72 73
# Lock for update

unknown's avatar
unknown committed
74
create table t1 (x integer not null primary key, y varchar(32), z integer, key(z)) engine = ndb;
75

unknown's avatar
unknown committed
76
insert into t1 values (1,'one',1), (2,'two',2),(3,"three",3); 
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

# PK access
connection con1;
begin;
select * from t1 where x = 1 for update;

connection con2;
begin;
select * from t1 where x = 2 for update;
--error 1205
select * from t1 where x = 1 for update;
rollback;

connection con1;
commit;

unknown's avatar
unknown committed
93
# table scan
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
connection con1;
begin;
select * from t1 where y = 'one' or y = 'three' for update;

connection con2;
begin;
# Have to check with pk access here since scans take locks on
# all rows and then release them in chunks
select * from t1 where x = 2 for update;
--error 1205
select * from t1 where x = 1 for update;
rollback;

connection con1;
commit;

unknown's avatar
unknown committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
# index scan
connection con1;
begin;
select * from t1 where z > 1 and z < 3 for update;

connection con2;
begin;
# Have to check with pk access here since scans take locks on
# all rows and then release them in chunks
select * from t1 where x = 1 for update;
--error 1205
select * from t1 where x = 2 for update;
rollback;

connection con1;
commit;

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
# share locking

# PK access
connection con1;
begin;
select * from t1 where x = 1 lock in share mode;

connection con2;
begin;
select * from t1 where x = 1 lock in share mode;
select * from t1 where x = 2 for update;
--error 1205
select * from t1 where x = 1 for update;
rollback;

connection con1;
commit;

unknown's avatar
unknown committed
145
# table scan
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
connection con1;
begin;
select * from t1 where y = 'one' or y = 'three' lock in share mode;

connection con2;
begin;
select * from t1 where y = 'one' lock in share mode;
# Have to check with pk access here since scans take locks on
# all rows and then release them in chunks
select * from t1 where x = 2 for update;
--error 1205
select * from t1 where x = 1 for update;
rollback;

connection con1;
commit;

unknown's avatar
unknown committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
# index scan
connection con1;
begin;
select * from t1 where z > 1 and z < 3 lock in share mode;

connection con2;
begin;
select * from t1 where z = 1 lock in share mode;
# Have to check with pk access here since scans take locks on
# all rows and then release them in chunks
select * from t1 where x = 1 for update;
--error 1205
select * from t1 where x = 2 for update;
rollback;

connection con1;
commit;

181 182
drop table t1;

183
# End of 4.1 tests