Innodb的行级锁的特性
2017-08-24 00:20
183 查看
Innodb的行级锁依赖于索引,如果条件字段上没有索引,将会锁定全表。
mysql> create table t1 ( id int ) ;
Query OK, 0 rows affected (0.09 sec)
mysql> insert into t1 values(1 ), (2), ( 3) ;
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from t1 ;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
SESSION2:
mysql> start transaction ;
Query OK, 0 rows affected (0.00 sec)
mysql> update t1 set id = 4 where id = 1 ; #这时会给整个表加写锁!!因为没有索引
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
SESSION1:
mysql> update t1 set id = 5 where id = 2 ;
出现等待。
SESSION2:
mysql> commit ;
Query OK, 0 rows affected (0.00 sec)
SESSION1:
阻塞消失。
Query OK, 1 row affected (14.17 sec)
Rows matched: 1 Changed: 1 Warnings: 0
小实验
SESSION1:mysql> create table t1 ( id int ) ;
Query OK, 0 rows affected (0.09 sec)
mysql> insert into t1 values(1 ), (2), ( 3) ;
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from t1 ;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
SESSION2:
mysql> start transaction ;
Query OK, 0 rows affected (0.00 sec)
mysql> update t1 set id = 4 where id = 1 ; #这时会给整个表加写锁!!因为没有索引
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
SESSION1:
mysql> update t1 set id = 5 where id = 2 ;
出现等待。
SESSION2:
mysql> commit ;
Query OK, 0 rows affected (0.00 sec)
SESSION1:
阻塞消失。
Query OK, 1 row affected (14.17 sec)
Rows matched: 1 Changed: 1 Warnings: 0
相关文章推荐
- mysql 存储引擎MYSIAM和INNODB特性比较
- MySQL · 特性分析 · innodb 锁分裂继承与迁移
- Innodb关键特性一 insert buffer
- InnoDB的三个关键特性
- 读书笔记:MySQL InnoDB存储引擎关键特性
- InnoDB Plugin特性介绍:让Buffer Pool不被污染
- Innodb储存的特性
- innodb buffer pool相关特性
- InnoDB主要特性、概念和架构
- InnoDB关键特性之刷新邻接页-异步IO
- MySQL · 引擎特性 · InnoDB COUNT(*) 优化(?)
- innoDB的关键特性二--针对索引的插入缓存Insert Buffer
- Innodb的三大关健特性
- 【mysql】Innodb三大特性之insert buffer
- 快速了解Mysql几种存储引擎(MyISAM、INNODB、MEMORY)特性
- MySQL · 引擎特性 · InnoDB undo log 漫游
- MySQL · 引擎特性 · InnoDB IO子系统
- INNODB 关键特性
- 【mysql】Innodb三大特性之double write