RR模式下利用区间锁防止幻读,RC模式没有区间锁会出现幻读
Session 1:
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec) mysql> select * from SmsTest where phoneNo between 30 and 40 for update;
+----+---------+-------------+--------+
| sn | phoneNo | channelType | status |
+----+---------+-------------+--------+
| 30 | 30 | 2 | 1 |
| 31 | 31 | 2 | 1 |
| 32 | 32 | 2 | 1 |
| 33 | 33 | 2 | 1 |
| 34 | 34 | 2 | 1 |
| 35 | 35 | 2 | 1 |
| 36 | 36 | 2 | 1 |
| 37 | 37 | 2 | 1 |
| 38 | 38 | 2 | 1 |
| 39 | 39 | 2 | 1 |
| 40 | 40 | 2 | 1 |
+----+---------+-------------+--------+
11 rows in set (0.00 sec) mysql> explain select * from SmsTest where phoneNo between 30 and 40 for update;
+----+-------------+---------+-------+---------------+--------------+---------+------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------+--------------+---------+------+------+-----------------------+
| 1 | SIMPLE | SmsTest | range | SmsTest_idx1 | SmsTest_idx1 | 4 | NULL | 11 | Using index condition |
+----+-------------+---------+-------+---------------+--------------+---------+------+------+-----------------------+
1 row in set (0.00 sec) Session 2: mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(28,1,1);
Query OK, 1 row affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(29,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(30,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(31,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(32,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(33,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(34,1,1);--hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(40,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(41,1,1);
Query OK, 1 row affected (0.01 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(42,1,1);
Query OK, 1 row affected (0.04 sec) 在30-40这个区间无法插入,RR需要区间锁来防止幻读 修改事务隔离为transaction-isolation =READ-COMMITTED mysql> select @@tx_isolation;
+----------------+
| @@tx_isolation |
+----------------+
| READ-COMMITTED |
+----------------+
1 row in set (0.00 sec) mysql> start transaction;
Query OK, 0 rows affected (0.00 sec) mysql> select * from SmsTest where phoneNo between 30 and 40 for update;
+----+---------+-------------+--------+
| sn | phoneNo | channelType | status |
+----+---------+-------------+--------+
| 30 | 30 | 2 | 1 |
| 31 | 31 | 2 | 1 |
| 32 | 32 | 2 | 1 |
| 33 | 33 | 2 | 1 |
| 34 | 34 | 2 | 1 |
| 35 | 35 | 2 | 1 |
| 36 | 36 | 2 | 1 |
| 37 | 37 | 2 | 1 |
| 38 | 38 | 2 | 1 |
| 39 | 39 | 2 | 1 |
| 40 | 40 | 2 | 1 |
+----+---------+-------------+--------+
11 rows in set (0.01 sec) mysql> explain select * from SmsTest where phoneNo between 30 and 40 for update;
+----+-------------+---------+-------+---------------+--------------+---------+------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------+--------------+---------+------+------+-----------------------+
| 1 | SIMPLE | SmsTest | range | SmsTest_idx1 | SmsTest_idx1 | 4 | NULL | 11 | Using index condition |
+----+-------------+---------+-------+---------------+--------------+---------+------+------+-----------------------+
1 row in set (0.01 sec) Session2: Database changed
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(28,1,1);
Query OK, 1 row affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(29,1,1);
Query OK, 1 row affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(30,1,1);
Query OK, 1 row affected (0.00 sec) mysql> commit;
Query OK, 0 rows affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(31,1,1);
Query OK, 1 row affected (0.00 sec) Session 1: mysql> select * from SmsTest where phoneNo between 30 and 40 for update;
+-------+---------+-------------+--------+
| sn | phoneNo | channelType | status |
+-------+---------+-------------+--------+
| 30 | 30 | 2 | 1 |
| 45292 | 30 | 1 | 1 |
| 31 | 31 | 2 | 1 |
| 32 | 32 | 2 | 1 |
| 33 | 33 | 2 | 1 |
| 34 | 34 | 2 | 1 |
| 35 | 35 | 2 | 1 |
| 36 | 36 | 2 | 1 |
| 37 | 37 | 2 | 1 |
| 38 | 38 | 2 | 1 |
| 39 | 39 | 2 | 1 |
| 40 | 40 | 2 | 1 |
+-------+---------+-------------+--------+
12 rows in set (0.00 sec) mysql> select * from SmsTest where phoneNo between 30 and 40 for update;
+-------+---------+-------------+--------+
| sn | phoneNo | channelType | status |
+-------+---------+-------------+--------+
| 30 | 30 | 2 | 1 |
| 45292 | 30 | 1 | 1 |
| 31 | 31 | 2 | 1 |
| 45293 | 31 | 1 | 1 |
| 32 | 32 | 2 | 1 |
| 33 | 33 | 2 | 1 |
| 34 | 34 | 2 | 1 |
| 35 | 35 | 2 | 1 |
| 36 | 36 | 2 | 1 |
| 37 | 37 | 2 | 1 |
| 38 | 38 | 2 | 1 |
| 39 | 39 | 2 | 1 |
| 40 | 40 | 2 | 1 |
+-------+---------+-------------+--------+
13 rows in set (0.01 sec) 结论 RR模式下 需要区间锁来防止幻读, RC模式下,没有区间锁,会出现幻读
RR模式下利用区间锁防止幻读,RC模式没有区间锁会出现幻读的更多相关文章
- x86架构:保护模式下利用中断实现抢占式多任务运行
站在用户角度考虑,一个合格的操作系统即使在单核下也能 "同时" 执行多个任务,这就要求CPU以非常快的频率在不同任务之间切换,让普通人根本感觉不到任务的切换.windwo ...
- Myeclipse在debug模式下没加断点程序卡住,start模式下可以正常启动
参考<eclipse在debug模式下卡住,start模式下可以启动>,地址:https://blog.csdn.net/jack_chen1994/article/details/761 ...
- 使用eclipse启动tomcat,正常模式下可以启动tomcat,却在debug模式下无法启动tomcat 问题解决
这个问题可能是由于eclipse和tomcat的交互而产生的,在以debug模式启动tomcat时,发生了读取文件错误,eclipse自动设置了断点,导致tomcat不能正常启动. 解决方法把brea ...
- 16位模式/32位模式下PUSH指令探究——《x86汇编语言:从实模式到保护模式》读书笔记16
一.Intel 32 位处理器的工作模式 如上图所示,Intel 32 位处理器有3种工作模式. (1)实模式:工作方式相当于一个8086 (2)保护模式:提供支持多任务环境的工作方式,建立保护机制 ...
- 用VMWare搭建服务器集群不能上外网的三种模式下对应解决办法
前言 决心要花费宝贵时间写下这篇心得,是因为从昨天晚上到今天上午被这个VMWare模拟搭建的服务器集群不能上外网的问题搞得很心烦,最后决定跟它杠上了!上午还通过远程连接得到了“空白”同学的帮助,在此表 ...
- MVVM模式下弹出窗体
原地址:http://www.cnblogs.com/yk250/p/5773425.html 在mvvm模式下弹出窗体,有使用接口模式传入参数new一个对象的,还有的是继承于一个window,然后在 ...
- CFUpdate高速模式下出现Error #2038提示的解决方案
使用CFUpdate上传文件,在IE模式下是正常的,切换到高速模式下出现提示Error #2038错误,文件无法上传. 向作者了解到需要设置challs_flash_update函数中的a.url为绝 ...
- sql server 备份与恢复系列五 完整模式下的备份与还原
一.概述 前面介绍了简单恢复模式和大容量恢复模式,这篇继续写完整恢复模式下的备份与还原.在完整恢复模式里最大的优点是只要能成功备份尾日志,就可以还原到日志备份内包含的任何时点("时点恢复&q ...
- eclipse的debug模式下启动不了tomcat
使用eclipse启动tomcat,正常模式下可以启动tomcat,却在debug模式下无法启动tomcat. 这个问题可能是由于eclipse和tomcat的交互而产生的,在以debug模式启动to ...
随机推荐
- NSNotificationCenter消息机制的介绍
转载自http://www.cnblogs.com/pengyingh/articles/2367374.html NSNotificationCenter的作用是专门提供程序中不同类之间的消息通讯而 ...
- Android(java)学习笔记201:网络图片浏览器的实现(ANR)
1.我们在Android下,实现使用http协议进行网络通信,请求网络数据.这里是获取网络上的图片信息,让它可以显示在手机上: 但是我们这个手机连接网络是很费时间,如果我们在主线程(UI线程)中写这个 ...
- PHP 5.6启动失败failed to open configuration file '/usr/local/php/etc/php-fpm.conf'
PHP编译安装完毕,启动失败,提示 [-Jun- ::] ERROR: failed to open configuration ) [-Jun- ::] ERROR: failed to load ...
- 实现一个线程安全的Queue队列
使用装饰者模式实现一个线程安全的Queue队列. public class SynchronizedQueue<E> implements Queue<E>, Serializ ...
- centos mysql 编译安装
centos mysql 编译安装 1.安装 创建MySQL用户 sudo useradd mysql 下载MySQL的源码包,我们这里使用的时5.5.18 安装依赖 sudo yum -y inst ...
- 解决mybatis使用枚举的转换
解决mybatis使用枚举的转换 >>>>>>>>>>>>>>>>>>>>> ...
- How to customize authentication to my own set of tables in asp.net web api 2?
ssuming your table is called AppUser, convert your own AppUser domain object to IUser(using Microsof ...
- js中浮点型运算 注意点
先看张图: 这是一个JS浮点数运算Bug,导致我树状图,数据合计不正确,,,,,,两个小数相加,出来那么多位小数 (这是修该之后的) 网上找到以下解决方式: 方法一:有js自定义函数 <sc ...
- ORA-01653:表空间扩展失败的问题
以下内容来源于ORA-01653:表空间扩展失败的问题 今天发现,原来设备的数据表空间只有5M,已经满了,上网去找发现要进行扩展空间. 一.脚本修改方式: ----查询表空间使用情况---使用DB ...
- webViewDidFinishLoad 执行多次的问题
在做网页加载进度条的时候,发现UIWebViewDelegate中webViewDidFinishLoad方法会执行多次: - (void)webViewDidStartLoad:(UIWebView ...