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疑问:
这里为什么被锁住,他们更新的不是同一行.==============================================================
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疑问:
这里为什么被锁住,他们更新的不是同一行.==============================================================
update test_innodb_lock set b=22
where b=6;
上面的语句有使用到索引吗?
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这个是足够数据的条件下为何也会锁住?
在不同的隔离级别下锁是不一样的,默认是repeatable read,在这种情况下假如不执行select for update是不会产生间隙锁的。第二个问题是因为innodb的锁机制是基于索引的,你把第二个例子把a、b的索引都删掉,然后增加一个a和b的联合索引,你再试验一下,看还锁不
哥,你试验了没