表结构和测试数据
CREATE TABLE `t` (
`id` int(11) NOT NULL,
`c` int(11) DEFAULT NULL,
`d` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `c` (`c`)
) ENGINE=InnoDB;
insert into t values(0,0,0),(5,5,5),
(10,10,10),(15,15,15),(20,20,20),(25,25,25);
疑问
select * from t where id>9 and id<12 order by id desc for update;
执行这条SQL,加锁范围是主键索引上的(0,5]、(5,10]和(10, 15)?
不懂(0,5]这个区间为什么会加锁?
因为你的这句SQL里面有排序,把排序去掉就行了:
希望能帮助到你。