MySQL Community Server, Server version: 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=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)
The engine of table user
is InnoDB.
Question 1:
When execute the following statement:
select * from user where number = 10 for update;
, how many rows will be locked at worst ? More than one rows ?
Question 2:
When execute the following statement:
select * from user where number = 14 for update;
, how many rows will be locked at worst ? More than two rows ?
答案 0 :(得分:0)
因为这个字段被索引所以在第一种情况下只会阻塞单行而在第二种情况下会有2行作为innodb使用基于索引的行级别锁定。
答案 1 :(得分:0)
因为该字段已被索引,所以在INNODB的情况下
回答1
只锁定了一行。
回答2
只锁定了2行。