Commit b32ffec8 authored by monty@mysql.com's avatar monty@mysql.com

Fix test case for innodb-lock

parent 9f8d47d8
drop table if exists t1;
select @@innodb_table_locks; select @@innodb_table_locks;
@@innodb_table_locks @@innodb_table_locks
0 1
drop table if exists t1;
set @@innodb_table_locks=1; set @@innodb_table_locks=1;
create table t1 (id integer, x integer) engine=INNODB; create table t1 (id integer, x integer) engine=INNODB;
insert into t1 values(0, 0); insert into t1 values(0, 0);
...@@ -25,24 +25,32 @@ id x ...@@ -25,24 +25,32 @@ id x
commit; commit;
drop table t1; drop table t1;
set @@innodb_table_locks=0; set @@innodb_table_locks=0;
create table t1 (id integer, x integer) engine=INNODB; create table t1 (id integer primary key, x integer) engine=INNODB;
insert into t1 values(0, 0); insert into t1 values(0, 0),(1,1),(2,2);
set autocommit=0; commit;
SELECT * from t1 where id = 0 FOR UPDATE; SELECT * from t1 where id = 0 FOR UPDATE;
id x id x
0 0 0 0
set autocommit=0; set autocommit=0;
set @@innodb_table_locks=0;
lock table t1 write; lock table t1 write;
update t1 set x=1 where id = 0; update t1 set x=10 where id = 2;
select * from t1; SELECT * from t1 where id = 2;
id x id x
0 1 2 2
UPDATE t1 set x=3 where id = 2;
commit; commit;
update t1 set x=2 where id = 0; SELECT * from t1;
id x
0 0
1 1
2 3
commit; commit;
unlock tables; unlock tables;
commit;
select * from t1; select * from t1;
id x id x
0 2 0 0
commit; 1 1
2 10
drop table t1; drop table t1;
-- source include/have_innodb.inc -- source include/have_innodb.inc
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
drop table if exists t1;
# #
# Check and select innodb lock type # Check and select innodb lock type
# #
...@@ -14,6 +10,14 @@ select @@innodb_table_locks; ...@@ -14,6 +10,14 @@ select @@innodb_table_locks;
# Testing of explicit table locks with enforced table locks # Testing of explicit table locks with enforced table locks
# #
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
drop table if exists t1;
#
# Testing of explicit table locks with enforced table locks
#
set @@innodb_table_locks=1; set @@innodb_table_locks=1;
connection con1; connection con1;
...@@ -48,37 +52,44 @@ commit; ...@@ -48,37 +52,44 @@ commit;
drop table t1; drop table t1;
# #
# Try with old lock method (where LOCK TABLE is ignored) # Try with old lock method (where LOCK TABLE is ignored by InnoDB)
# #
set @@innodb_table_locks=0; set @@innodb_table_locks=0;
create table t1 (id integer, x integer) engine=INNODB; create table t1 (id integer primary key, x integer) engine=INNODB;
insert into t1 values(0, 0); insert into t1 values(0, 0),(1,1),(2,2);
set autocommit=0; commit;
SELECT * from t1 where id = 0 FOR UPDATE; SELECT * from t1 where id = 0 FOR UPDATE;
connection con2; connection con2;
set autocommit=0; set autocommit=0;
set @@innodb_table_locks=0;
# The following statement should hang because con1 is locking the page # The following statement should work becase innodb doesn't check table locks
--send
lock table t1 write; lock table t1 write;
--sleep 2;
connection con1; connection con1;
update t1 set x=1 where id = 0;
select * from t1; # This will be locked by MySQL
commit; --send
update t1 set x=10 where id = 2;
--sleep 2
connection con2; connection con2;
reap;
update t1 set x=2 where id = 0; # Note that we will get a deadlock if we try to select any rows marked
# for update by con1 !
SELECT * from t1 where id = 2;
UPDATE t1 set x=3 where id = 2;
commit;
SELECT * from t1;
commit; commit;
unlock tables; unlock tables;
connection con1; connection con1;
select * from t1; reap;
commit; commit;
select * from t1;
drop table t1; drop table t1;
...@@ -552,8 +552,14 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) ...@@ -552,8 +552,14 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type)
!lock->write_wait.data && !lock->write_wait.data &&
lock->write.data->type == TL_WRITE_ALLOW_WRITE)) lock->write.data->type == TL_WRITE_ALLOW_WRITE))
{ {
/* We have already got a write lock or all locks are /*
TL_WRITE_ALLOW_WRITE */ We have already got a write lock or all locks are
TL_WRITE_ALLOW_WRITE
*/
DBUG_PRINT("info", ("write_wait.data: 0x%lx old_type: %d",
(ulong) lock->write_wait.data,
lock->write.data->type));
(*lock->write.last)=data; /* Add to running fifo */ (*lock->write.last)=data; /* Add to running fifo */
data->prev=lock->write.last; data->prev=lock->write.last;
lock->write.last= &data->next; lock->write.last= &data->next;
...@@ -568,6 +574,8 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type) ...@@ -568,6 +574,8 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type)
} }
else else
{ {
DBUG_PRINT("info", ("write_wait.data: 0x%lx",
(ulong) lock->write_wait.data));
if (!lock->write_wait.data) if (!lock->write_wait.data)
{ /* no scheduled write locks */ { /* no scheduled write locks */
if (lock_type == TL_WRITE_CONCURRENT_INSERT && if (lock_type == TL_WRITE_CONCURRENT_INSERT &&
......
...@@ -3704,7 +3704,7 @@ struct my_option my_long_options[] = ...@@ -3704,7 +3704,7 @@ struct my_option my_long_options[] =
"If Innodb should enforce LOCK TABLE", "If Innodb should enforce LOCK TABLE",
(gptr*) &global_system_variables.innodb_table_locks, (gptr*) &global_system_variables.innodb_table_locks,
(gptr*) &global_system_variables.innodb_table_locks, (gptr*) &global_system_variables.innodb_table_locks,
0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0}, 0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
#endif /* End HAVE_INNOBASE_DB */ #endif /* End HAVE_INNOBASE_DB */
{"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
0, 0, 0, 0, 0}, 0, 0, 0, 0, 0},
......
...@@ -826,6 +826,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, ...@@ -826,6 +826,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name,
DBUG_RETURN(0); DBUG_RETURN(0);
} }
table->query_id=thd->query_id; table->query_id=thd->query_id;
DBUG_PRINT("info",("Using temporary table"));
goto reset; goto reset;
} }
} }
...@@ -840,6 +841,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, ...@@ -840,6 +841,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name,
table->query_id != thd->query_id) table->query_id != thd->query_id)
{ {
table->query_id=thd->query_id; table->query_id=thd->query_id;
DBUG_PRINT("info",("Using locked table"));
goto reset; goto reset;
} }
} }
......
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