Commit ec8779e9 authored by unknown's avatar unknown

Fix test case for innodb-lock


mysql-test/r/innodb-lock.result:
  Fix test case (old one didn't test things correctly)
mysql-test/t/innodb-lock.test:
  Fix test case (old one didn't test things correctly)
mysys/thr_lock.c:
  More debugging information
sql/mysqld.cc:
  Enable innodb_table_locks as default, as otherwise there is a possibility for deadlocks
sql/sql_base.cc:
  More debug information
parent 95f0e39a
drop table if exists t1;
select @@innodb_table_locks;
@@innodb_table_locks
0
1
drop table if exists t1;
set @@innodb_table_locks=1;
create table t1 (id integer, x integer) engine=INNODB;
insert into t1 values(0, 0);
......@@ -25,24 +25,32 @@ id x
commit;
drop table t1;
set @@innodb_table_locks=0;
create table t1 (id integer, x integer) engine=INNODB;
insert into t1 values(0, 0);
set autocommit=0;
create table t1 (id integer primary key, x integer) engine=INNODB;
insert into t1 values(0, 0),(1,1),(2,2);
commit;
SELECT * from t1 where id = 0 FOR UPDATE;
id x
0 0
set autocommit=0;
set @@innodb_table_locks=0;
lock table t1 write;
update t1 set x=1 where id = 0;
select * from t1;
update t1 set x=10 where id = 2;
SELECT * from t1 where id = 2;
id x
0 1
2 2
UPDATE t1 set x=3 where id = 2;
commit;
update t1 set x=2 where id = 0;
SELECT * from t1;
id x
0 0
1 1
2 3
commit;
unlock tables;
commit;
select * from t1;
id x
0 2
commit;
0 0
1 1
2 10
drop table t1;
-- source include/have_innodb.inc
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
drop table if exists t1;
#
# Check and select innodb lock type
#
......@@ -14,6 +10,14 @@ select @@innodb_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;
connection con1;
......@@ -48,37 +52,44 @@ commit;
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;
create table t1 (id integer, x integer) engine=INNODB;
insert into t1 values(0, 0);
set autocommit=0;
create table t1 (id integer primary key, x integer) engine=INNODB;
insert into t1 values(0, 0),(1,1),(2,2);
commit;
SELECT * from t1 where id = 0 FOR UPDATE;
connection con2;
set autocommit=0;
set @@innodb_table_locks=0;
# The following statement should hang because con1 is locking the page
--send
# The following statement should work becase innodb doesn't check table locks
lock table t1 write;
--sleep 2;
connection con1;
update t1 set x=1 where id = 0;
select * from t1;
commit;
# This will be locked by MySQL
--send
update t1 set x=10 where id = 2;
--sleep 2
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;
unlock tables;
connection con1;
select * from t1;
reap;
commit;
select * from t1;
drop table t1;
......@@ -552,8 +552,14 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type)
!lock->write_wait.data &&
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 */
data->prev=lock->write.last;
lock->write.last= &data->next;
......@@ -568,6 +574,8 @@ int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type)
}
else
{
DBUG_PRINT("info", ("write_wait.data: 0x%lx",
(ulong) lock->write_wait.data));
if (!lock->write_wait.data)
{ /* no scheduled write locks */
if (lock_type == TL_WRITE_CONCURRENT_INSERT &&
......
......@@ -3704,7 +3704,7 @@ struct my_option my_long_options[] =
"If Innodb should enforce LOCK TABLE",
(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 */
{"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
0, 0, 0, 0, 0},
......
......@@ -826,6 +826,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name,
DBUG_RETURN(0);
}
table->query_id=thd->query_id;
DBUG_PRINT("info",("Using temporary table"));
goto reset;
}
}
......@@ -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;
DBUG_PRINT("info",("Using locked table"));
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