From fc9da882276b996e4d258ee33fd70188eddbf0d4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Jun 2006 09:27:04 +0200 Subject: [PATCH 1/2] Moved back comment to correct method --- sql/ha_ndbcluster.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 161b1ead2e0..1031c4f635c 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -3426,11 +3426,10 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) } /* - Start a transaction for running a statement if one is not - already running in a transaction. This will be the case in - a BEGIN; COMMIT; block - When using LOCK TABLE's external_lock will start a transaction - since ndb does not currently does not support table locking + Unlock the last row read in an open scan. + Rows are unlocked by default in ndb, but + for SELECT FOR UPDATE and SELECT LOCK WIT SHARE MODE + locks are kept if unlock_row() is not called. */ void ha_ndbcluster::unlock_row() @@ -3442,6 +3441,14 @@ void ha_ndbcluster::unlock_row() DBUG_VOID_RETURN; } +/* + Start a transaction for running a statement if one is not + already running in a transaction. This will be the case in + a BEGIN; COMMIT; block + When using LOCK TABLE's external_lock will start a transaction + since ndb does not currently does not support table locking +*/ + int ha_ndbcluster::start_stmt(THD *thd) { int error=0; From a3f3696697f1ef991ea856fc9dd7bb113309555a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Jun 2006 09:28:27 +0200 Subject: [PATCH 2/2] Added lock test on index scan --- mysql-test/r/ndb_lock.result | 77 ++++++++++++++++++++++++------------ mysql-test/t/ndb_lock.test | 43 ++++++++++++++++++-- 2 files changed, 91 insertions(+), 29 deletions(-) diff --git a/mysql-test/r/ndb_lock.result b/mysql-test/r/ndb_lock.result index 0267d092047..281b02b8228 100644 --- a/mysql-test/r/ndb_lock.result +++ b/mysql-test/r/ndb_lock.result @@ -63,62 +63,89 @@ pk u o 5 5 5 insert into t1 values (1,1,1); drop table t1; -create table t1 (x integer not null primary key, y varchar(32)) engine = ndb; -insert into t1 values (1,'one'), (2,'two'),(3,"three"); +create table t1 (x integer not null primary key, y varchar(32), z integer, key(z)) engine = ndb; +insert into t1 values (1,'one',1), (2,'two',2),(3,"three",3); begin; select * from t1 where x = 1 for update; -x y -1 one +x y z +1 one 1 begin; select * from t1 where x = 2 for update; -x y -2 two +x y z +2 two 2 select * from t1 where x = 1 for update; ERROR HY000: Lock wait timeout exceeded; try restarting transaction rollback; commit; begin; select * from t1 where y = 'one' or y = 'three' for update; -x y -3 three -1 one +x y z +3 three 3 +1 one 1 begin; select * from t1 where x = 2 for update; -x y -2 two +x y z +2 two 2 select * from t1 where x = 1 for update; ERROR HY000: Lock wait timeout exceeded; try restarting transaction rollback; commit; begin; -select * from t1 where x = 1 lock in share mode; -x y -1 one +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; -x y -1 one +x y z +1 one 1 +begin; +select * from t1 where x = 1 lock in share mode; +x y z +1 one 1 select * from t1 where x = 2 for update; -x y -2 two +x y z +2 two 2 select * from t1 where x = 1 for update; ERROR HY000: Lock wait timeout exceeded; try restarting transaction rollback; commit; begin; select * from t1 where y = 'one' or y = 'three' lock in share mode; -x y -3 three -1 one +x y z +3 three 3 +1 one 1 begin; select * from t1 where y = 'one' lock in share mode; -x y -1 one +x y z +1 one 1 select * from t1 where x = 2 for update; -x y -2 two +x y z +2 two 2 select * from t1 where x = 1 for update; ERROR HY000: Lock wait timeout exceeded; try restarting transaction rollback; 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; diff --git a/mysql-test/t/ndb_lock.test b/mysql-test/t/ndb_lock.test index 42721c7d3f5..db42b7ec2dd 100644 --- a/mysql-test/t/ndb_lock.test +++ b/mysql-test/t/ndb_lock.test @@ -71,9 +71,9 @@ drop table t1; # 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 connection con1; @@ -90,7 +90,7 @@ rollback; connection con1; commit; -# scan +# table scan connection con1; begin; select * from t1 where y = 'one' or y = 'three' for update; @@ -107,6 +107,23 @@ rollback; connection con1; 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 # PK access @@ -125,7 +142,7 @@ rollback; connection con1; commit; -# scan +# table scan connection con1; begin; select * from t1 where y = 'one' or y = 'three' lock in share mode; @@ -143,6 +160,24 @@ rollback; connection con1; 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; # End of 4.1 tests