gap锁 对于unique index 和Ununique index
Session 1:
mysql> select * from s100;
+-----+------+------+
| sn | id | info |
+-----+------+------+
| 227 | 1 | 1a |
| 228 | 3 | 3a |
| 229 | 6 | 6a |
| 230 | 9 | 9a |
| 231 | 12 | 12a |
| 232 | 15 | 15a |
| 233 | 18 | 18a |
+-----+------+------+
7 rows in set (0.00 sec) mysql> show index from s100;
+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| s100 | 0 | PRIMARY | 1 | sn | A | 7 | NULL | NULL | | BTREE | | |
| s100 | 1 | s100_idx1 | 1 | id | A | 7 | NULL | NULL | YES | BTREE | | |
+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec) mysql> show variables like '%tx_isolation%';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| tx_isolation | REPEATABLE-READ |
+---------------+-----------------+
1 row in set (0.00 sec) mysql> update s100 set info='bbb' where id=12;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0 Session 2: mysql> insert into s100(id,info) select 13,'xxxxxxx'; ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
mysql>
mysql>
mysql>
mysql> insert into s100(id,info) select 12,'xxxxxxx';
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
mysql> insert into s100(id,info) select 14,'xxxxxxx';
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
mysql> insert into s100(id,info) select 15,'xxxxxxx';
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0 会从12 锁到14 改成unique index 呢? Session 1:
mysql> show index from s100;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| s100 | 0 | PRIMARY | 1 | sn | A | 7 | NULL | NULL | | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.00 sec) mysql> create unique index s100_idx1 on s100(id);
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> update s100 set info='bbb' where id=12;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0 mysql> show index from s100;
+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| s100 | 0 | PRIMARY | 1 | sn | A | 8 | NULL | NULL | | BTREE | | |
| s100 | 0 | s100_idx1 | 1 | id | A | 8 | NULL | NULL | YES | BTREE | | |
+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec) Session 2: Database changed
mysql> insert into s100(id,info) select 13,'xxxxxxx';
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0 此时正常
gap锁 对于unique index 和Ununique index的更多相关文章
- Gap 锁
14.3.1 InnoDB Locking InnoDB 锁 本章节描述InnoDB 使用的锁类型: Shared and Exclusive Locks Intention Locks Record ...
- Mysql加锁过程详解(7)-初步理解MySQL的gap锁
Mysql加锁过程详解(1)-基本知识 Mysql加锁过程详解(2)-关于mysql 幻读理解 Mysql加锁过程详解(3)-关于mysql 幻读理解 Mysql加锁过程详解(4)-select fo ...
- 死锁案例 GAP 锁 没有就插入,存在就更新
https://mp.weixin.qq.com/s/2obpN57D8hyorCMnIu_YAg 死锁案例八 文 | 杨一 on 运维 转 | 来源:公众号yangyidba 一.前言 死锁其实是一 ...
- InnoDB的锁机制浅析(二)—探索InnoDB中的锁(Record锁/Gap锁/Next-key锁/插入意向锁)
Record锁/Gap锁/Next-key锁/插入意向锁 文章总共分为五个部分: InnoDB的锁机制浅析(一)-基本概念/兼容矩阵 InnoDB的锁机制浅析(二)-探索InnoDB中的锁(Recor ...
- PostgreSQL index types and index bloating
warehouse_db=# create table item (item_id integer not null,item_name text,item_price numeric,item_da ...
- MySQL 执行计划中Extra(Using where,Using index,Using index condition,Using index,Using where)的浅析
关于如何理解MySQL执行计划中Extra列的Using where.Using Index.Using index condition,Using index,Using where这四者的区别 ...
- mysql 索引查询 、创建 create index 与 add index 的区别
1.索引查询 ------TABLE_SCHEMA 库名:TABLE 表名 ------AND UPPER(INDEX_NAME) != 'PRIMARY' 只查询索引,不需要主键 SELECT ...
- JQ first-child与:first的区别以及nth-child(index)与eq(index)的区别
1.first-child和:first区别 first-child 是指选取每个父元素的第一个子元素 如$("div:first-child")指每个父级里的第一个div孩子 ...
- Index Seek和Index Scan的区别
Index Seek是Sql Server执行查询语句时利用建立的索引进行查找,索引是B树结构,Sql Server先查找索引树的根节点,一级一级向下查找,在查找到相应叶子节点后,取出叶子节点的数据. ...
随机推荐
- POJ Octal Fractions(JAVA水过)
题目链接:id=1131" target="_blank">CLICK HERE~ 尽管java一下模拟水过,可是我看到别人的一段奇妙代码,贴出和大家共享. imp ...
- CF(435D - Special Grid)dp
题目链接:http://codeforces.com/problemset/problem/435/D 题意:求三角形个数,三个点必须的白点上,而且三条边必须是横线,竖线或对角线,三条边上不同意出现黑 ...
- 幻世(OurDream)2D图形引擎使用教程11——播放媒体文件(1)
声明:本教程版权归Lizcst Software Lab所有,欢迎转载,但是转载必须保留本段声明文字,并注明文章来源:http://blog.csdn.net/kflizcst 谢谢合作! 播放媒体是 ...
- 一、Python-----之变量
1.变量存在的意义就是在程序中存储一些临时的数据.2.程序运行的时候回调用变量的临时数据. 变量起名规则: 变量名只能是字符.数字或下划线的任意组合 变量名的第一个字符不能是数字 以下关键字不能声明为 ...
- Java之从控制台读入数据
0 引言 从控制台中读取数据是一个比较常用的功能,在 JDK 5.0 以前的版本中的实现是比较复杂的,需要手工处理系统的输入流.有意思的是,从 JDK 5.0 版本开始,能从控制台中输入数据的方 ...
- 仿StackOverflow开发在线问答系统
仿StackOverflow开发在线问答系统 [第二期11月9日开课]使用Python Flask Web开发框架实现一套类似StackOverflow的在线问答平台LouQA,具备提问,回答,评论点 ...
- dsdfdsfd
aibang.com/show/1816725179-1268699976/product/7069113.html aibang.com/show/1816725179-1268699976/pro ...
- MySQL中innodb引擎分析(初始化)
MySQL的存储引擎是以插件形式工作的,这应该是MySQL的一大特色了吧! 依据<深入理解MySQL>的内容,5.1版本号时存储引擎的插件化都还不是彻底,确切的说是刚加入的特性.为MySQ ...
- 谁是Docker的开发人员
由CHRIS DAWSON发表在thenewstack/DATA RESEARCH qianhen123/CHB译 我们分析了Docker的容器库并提出两个问题: 1.Docker的贡献者们感兴趣的其 ...
- 在Web Api中快速实现JSonp
本文翻译自:http://www.codeproject.com/Tips/631685/JSONP-in-ASP-NET-Web-API-Quick-Get-Started Concept: 同源策 ...