How many rows will be locked at worst in a table whose engine is InnoDB?

时间:2015-07-03 10:24:15

标签: mysql innodb

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 ?

2 个答案:

答案 0 :(得分:0)

因为这个字段被索引所以在第一种情况下只会阻塞单行而在第二种情况下会有2行作为innodb使用基于索引的行级别锁定。

答案 1 :(得分:0)

因为该字段已被索引,所以在INNODB的情况下

回答1

只锁定了一行。

回答2

只锁定了2行。