create table test_innodb_lock (a int(11),b varchar(16)) engine=innodb;
create index test_innodb_a_ind on test_innodb_lock(a);
create index test_innodb_lock_b_ind on test_innodb_lock(b);session 1:set autocommit =0;
update test_innodb_lock set b=22 
where b=6;session 2:update test_innodb_lock set b=33 
where b=5疑问:
这里为什么被锁住,他们更新的不是同一行.==============================================================

解决方案 »

  1.   

    请问狼头大哥:
    update test_innodb_lock set b=22 
    where b=6;
    上面的语句有使用到索引吗?
      

  2.   

    带另一个问题:
    session1:set autocommit=0;
    update test_innodb_lock
    set b = 'bbbbb' where a = 1 and b = 2session2:update test_innodb_lock
    set b = 'bbbbb' where a = 1 and b = 1100这个是足够数据的条件下为何也会锁住?
      

  3.   

    MYSQL使用的一种间隙锁,就是说两条记录之间的记录,虽然没有被访问,但是也被锁住了,好像是为了避免幻读而做的。你另外一个问题我觉得可能是间隙锁锁住了。
      

  4.   

    你要讨论这个问题,贴出你的show global variables like 'tx_isolation'; 
    在不同的隔离级别下锁是不一样的,默认是repeatable read,在这种情况下假如不执行select for update是不会产生间隙锁的。第二个问题是因为innodb的锁机制是基于索引的,你把第二个例子把a、b的索引都删掉,然后增加一个a和b的联合索引,你再试验一下,看还锁不
      

  5.   

    你把第二个例子把a、b的索引都删掉,然后增加一个a和b的联合索引,你再试验一下,看还锁不
    哥,你试验了没