Commit ed8ec2cf authored by unknown's avatar unknown
Browse files

Code cleanups (done during review of new code)

Rename innodb_table_locks_old_behavior -> innodb_table_locks
Set innodb_table_locks to off by default to get same behaviour as in MySQL 4.0.20
(This means that Innodb ignore table locks by default, which makes it easier to combine MyISAM and InnoDB to simulate a transaction)


libmysql/libmysql.c:
  Use ulong instead of unsigned long
  Reuse _dig_vec()
myisam/myisampack.c:
  Simplify code
mysql-test/r/innodb-lock.result:
  new test case
mysql-test/t/innodb-lock.test:
  new test case
sql/ha_innodb.cc:
  Rename innodb_table_locks_old_behavior -> innodb_table_locks
sql/mysqld.cc:
  Rename innodb_table_locks_old_behavior -> innodb_table_locks
  Set this off by default to get same behaviour as in MySQL 4.0.20
sql/set_var.cc:
  Rename innodb_table_locks_old_behavior -> innodb_table_locks
sql/sql_class.h:
  Rename innodb_table_locks_old_behavior -> innodb_table_locks
parent 2428fb5c
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -3170,20 +3170,18 @@ void my_net_local_init(NET *net)
  encoded string, not including the terminating null character.
*/

unsigned long
mysql_hex_string(char *to, const char *from, unsigned long length)
ulong mysql_hex_string(char *to, const char *from, ulong length)
{
  char *to0= to;
  const char *end;
  static char hex[]= "0123456789ABCDEF";
            
  for (end= from + length; from < end; from++)
  {
    *to++= hex[((unsigned char) *from) >> 4];
    *to++= hex[((unsigned char) *from) & 0x0F];
    *to++= _dig_vec[((unsigned char) *from) >> 4];
    *to++= _dig_vec[((unsigned char) *from) & 0x0F];
  }
  *to= '\0';
  return to-to0;
  return (ulong) (to-to0);
}

/*
+5 −7
Original line number Diff line number Diff line
@@ -418,14 +418,12 @@ static bool open_isam_files(PACK_MRG_INFO *mrg,char **names,uint count)
  mrg->src_file_has_indexes_disabled= 0;
  for (i=0; i < count ; i++)
  {
    if ((mrg->file[i]=open_isam_file(names[i],O_RDONLY)))
    {
      mrg->src_file_has_indexes_disabled |= 
        (mrg->file[i]->s->state.key_map != 
         (1ULL << mrg->file[i]->s->base.keys) - 1);
    }
    else
    if (!(mrg->file[i]=open_isam_file(names[i],O_RDONLY)))
      goto error;

    mrg->src_file_has_indexes_disabled|= ((mrg->file[i]->s->state.key_map != 
                                           (((ulonglong) 1) <<
                                            mrg->file[i]->s->base. keys) - 1));
  }
  /* Check that files are identical */
  for (j=0 ; j < count-1 ; j++)
+26 −0
Original line number Diff line number Diff line
drop table if exists t1;
select @@innodb_table_locks;
@@innodb_table_locks
0
set @@innodb_table_locks=1;
create table t1 (id integer, x integer) engine=INNODB;
insert into t1 values(0, 0);
set autocommit=0;
SELECT * from t1 where id = 0 FOR UPDATE;
id	x
0	0
set autocommit=0;
lock table t1 write;
update t1 set x=1 where id = 0;
select * from t1;
id	x
0	1
commit;
update t1 set x=2 where id = 0;
commit;
unlock tables;
select * from t1;
id	x
0	2
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;
+45 −1
Original line number Diff line number Diff line
@@ -5,10 +5,54 @@ connect (con2,localhost,root,,);
drop table if exists t1;

#
# Testing of explicit table locks
# Check and select innodb lock type
#

select @@innodb_table_locks;

#
# Testing of explicit table locks with enforced table locks
#

set @@innodb_table_locks=1;

connection con1;
create table t1 (id integer, x integer) engine=INNODB;
insert into t1 values(0, 0);
set autocommit=0;
SELECT * from t1 where id = 0 FOR UPDATE;

connection con2;
set autocommit=0;

# The following statement should hang because con1 is locking the page
--send
lock table t1 write;
--sleep 2;

connection con1;
update t1 set x=1 where id = 0;
select * from t1;
commit;

connection con2;
reap;
update t1 set x=2 where id = 0;
commit;
unlock tables;

connection con1;
select * from t1;
commit;

drop table t1;

#
# Try with old lock method (where LOCK TABLE is ignored)
#

set @@innodb_table_locks=0;

create table t1 (id integer, x integer) engine=INNODB;
insert into t1 values(0, 0);
set autocommit=0;
+1 −1
Original line number Diff line number Diff line
@@ -4694,7 +4694,7 @@ ha_innobase::external_lock(

		if (prebuilt->select_lock_type != LOCK_NONE) {
			if (thd->in_lock_tables &&
			    !thd->variables.innodb_table_locks_old_behavior) {
			    thd->variables.innodb_table_locks) {
				ulint	error;
				error = row_lock_table_for_mysql(prebuilt);

Loading