Commit b89f1791 authored by mskold@mysql.com's avatar mskold@mysql.com

Added lock test on index scan

parent 030f63fd
...@@ -63,62 +63,89 @@ pk u o ...@@ -63,62 +63,89 @@ pk u o
5 5 5 5 5 5
insert into t1 values (1,1,1); insert into t1 values (1,1,1);
drop table t1; drop table t1;
create table t1 (x integer not null primary key, y varchar(32)) engine = ndb; create table t1 (x integer not null primary key, y varchar(32), z integer, key(z)) engine = ndb;
insert into t1 values (1,'one'), (2,'two'),(3,"three"); insert into t1 values (1,'one',1), (2,'two',2),(3,"three",3);
begin; begin;
select * from t1 where x = 1 for update; select * from t1 where x = 1 for update;
x y x y z
1 one 1 one 1
begin; begin;
select * from t1 where x = 2 for update; select * from t1 where x = 2 for update;
x y x y z
2 two 2 two 2
select * from t1 where x = 1 for update; select * from t1 where x = 1 for update;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction ERROR HY000: Lock wait timeout exceeded; try restarting transaction
rollback; rollback;
commit; commit;
begin; begin;
select * from t1 where y = 'one' or y = 'three' for update; select * from t1 where y = 'one' or y = 'three' for update;
x y x y z
3 three 3 three 3
1 one 1 one 1
begin; begin;
select * from t1 where x = 2 for update; select * from t1 where x = 2 for update;
x y x y z
2 two 2 two 2
select * from t1 where x = 1 for update; select * from t1 where x = 1 for update;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction ERROR HY000: Lock wait timeout exceeded; try restarting transaction
rollback; rollback;
commit; commit;
begin; begin;
select * from t1 where z > 1 and z < 3 for update;
x y z
2 two 2
begin;
select * from t1 where x = 1 for update;
x y z
1 one 1
select * from t1 where x = 2 for update;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
rollback;
commit;
begin;
select * from t1 where x = 1 lock in share mode; select * from t1 where x = 1 lock in share mode;
x y x y z
1 one 1 one 1
begin; begin;
select * from t1 where x = 1 lock in share mode; select * from t1 where x = 1 lock in share mode;
x y x y z
1 one 1 one 1
select * from t1 where x = 2 for update; select * from t1 where x = 2 for update;
x y x y z
2 two 2 two 2
select * from t1 where x = 1 for update; select * from t1 where x = 1 for update;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction ERROR HY000: Lock wait timeout exceeded; try restarting transaction
rollback; rollback;
commit; commit;
begin; begin;
select * from t1 where y = 'one' or y = 'three' lock in share mode; select * from t1 where y = 'one' or y = 'three' lock in share mode;
x y x y z
3 three 3 three 3
1 one 1 one 1
begin; begin;
select * from t1 where y = 'one' lock in share mode; select * from t1 where y = 'one' lock in share mode;
x y x y z
1 one 1 one 1
select * from t1 where x = 2 for update; select * from t1 where x = 2 for update;
x y x y z
2 two 2 two 2
select * from t1 where x = 1 for update; select * from t1 where x = 1 for update;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction ERROR HY000: Lock wait timeout exceeded; try restarting transaction
rollback; rollback;
commit; commit;
begin;
select * from t1 where z > 1 and z < 3 lock in share mode;
x y z
2 two 2
begin;
select * from t1 where z = 1 lock in share mode;
x y z
1 one 1
select * from t1 where x = 1 for update;
x y z
1 one 1
select * from t1 where x = 2 for update;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
rollback;
commit;
drop table t1; drop table t1;
...@@ -71,9 +71,9 @@ drop table t1; ...@@ -71,9 +71,9 @@ drop table t1;
# Lock for update # Lock for update
create table t1 (x integer not null primary key, y varchar(32)) engine = ndb; create table t1 (x integer not null primary key, y varchar(32), z integer, key(z)) engine = ndb;
insert into t1 values (1,'one'), (2,'two'),(3,"three"); insert into t1 values (1,'one',1), (2,'two',2),(3,"three",3);
# PK access # PK access
connection con1; connection con1;
...@@ -90,7 +90,7 @@ rollback; ...@@ -90,7 +90,7 @@ rollback;
connection con1; connection con1;
commit; commit;
# scan # table scan
connection con1; connection con1;
begin; begin;
select * from t1 where y = 'one' or y = 'three' for update; select * from t1 where y = 'one' or y = 'three' for update;
...@@ -107,6 +107,23 @@ rollback; ...@@ -107,6 +107,23 @@ rollback;
connection con1; connection con1;
commit; commit;
# 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;
# share locking # share locking
# PK access # PK access
...@@ -125,7 +142,7 @@ rollback; ...@@ -125,7 +142,7 @@ rollback;
connection con1; connection con1;
commit; commit;
# scan # table scan
connection con1; connection con1;
begin; begin;
select * from t1 where y = 'one' or y = 'three' lock in share mode; select * from t1 where y = 'one' or y = 'three' lock in share mode;
...@@ -143,6 +160,24 @@ rollback; ...@@ -143,6 +160,24 @@ rollback;
connection con1; connection con1;
commit; commit;
# 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;
drop table t1; drop table t1;
# End of 4.1 tests # End of 4.1 tests
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment