Mysql 在引擎为InnoDB的表中,最坏情况下会锁定多少行?
MySQL社区服务器,服务器版本:5.6.24Mysql 在引擎为InnoDB的表中,最坏情况下会锁定多少行?,mysql,innodb,Mysql,Innodb,MySQL社区服务器,服务器版本:5.6.24 mysql> show create table user\G *************************** 1. row *************************** Table: user Create Table: CREATE TABLE `user` ( `number` int(11) DEFAULT NULL, KEY `idx_number` (`number`) ) ENGINE=I
mysql> show create table user\G
*************************** 1. row ***************************
Table: user
Create Table: CREATE TABLE `user` (
`number` int(11) DEFAULT NULL,
KEY `idx_number` (`number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
mysql> SELECT * FROM user;
+--------+
| number |
+--------+
| 10 |
| 11 |
| 12 |
| 13 |
| 14 |
| 14 |
+--------+
6 rows in set (0.00 sec)
表user
的引擎是InnoDB
问题1:
执行以下语句时:
select * from user where number = 10 for update;
select * from user where number = 14 for update;
,最坏情况下将锁定多少行?不止一行
问题2:
执行以下语句时:
select * from user where number = 10 for update;
select * from user where number = 14 for update;
,最坏情况下将锁定多少行?超过两行?因为该字段已被索引,所以在第一种情况下,只有一行将被阻止,在第二种情况下,由于innodb使用了基于索引的行级锁定,所以有两行。因为该字段已被索引,所以在innodb的情况下也会被阻止 答案1 只有一行被锁定 答案2 只有两行被锁定