MySQL Lock--INSERT加锁规则
Insert操作加锁规则
1、INSERT操作会对新插入的记录加行锁(ROW LOCK)+排他锁(X LOCK),不会产生任何GAP锁和Next-Key锁 2、在插入记录前,会向插入记录所在位置申请意向插入Gap锁(Insertion Intention Gap Lock),相同区间的意向插入Gap锁不会冲突。 3、对于唯一索引,如果插入记录时表中已存在相同键值记录(被其他事务修改且未提交),即存在唯一键冲突,会尝试在已有记录上加读锁,然后等待。
官方文档:
INSERT sets an exclusive lock on the inserted row. This lock is an index-record lock, not a next-key lock (that is, there is no gap lock) and does not prevent other sessions from inserting into the gap before the inserted row. Prior to inserting the row, a type of gap lock called an insert intention gap lock is set. This lock signals the intent to insert in such a way that multiple transactions inserting into the same index gap need not wait for each other if they are not inserting at the same position within the gap. Suppose that there are index records with values of 4 and 7. Separate transactions that attempt to insert values of 5 and 6 each lock the gap between 4 and 7 with insert intention locks prior to obtaining the exclusive lock on the inserted row, but do not block each other because the rows are nonconflicting. If a duplicate-key error occurs, a shared lock on the duplicate index record is set. This use of a shared lock can result in deadlock should there be multiple sessions trying to insert the same row if another session already has an exclusive lock.
MySQL Lock--INSERT加锁规则的更多相关文章
- MySQL Lock--MySQL INSERT加锁学习
准备测试数据: ## 开启InnoDB Monitor SET GLOBAL innodb_status_output=ON; SET GLOBAL innodb_status_output_lock ...
- MySQL锁(四)行锁的加锁规则和案例
在上一篇文章,我们学习了间隙锁和next-key lock,但是不知道怎么加锁,有哪些规则.间隙锁的概念不太好理解,尤其是配合上行锁后,很容易在判断是否会出现锁等待的问题上犯错. 今天我们就来学习一下 ...
- 聊聊MySQL的加锁规则《死磕MySQL系列 十五》
大家好,我是咔咔 不期速成,日拱一卒 本期来聊聊MySQL的加锁规则,知道这些规则后可以判断SQL语句的加锁范围,同时也可以写出更好的SQL语句,防止幻读问题的产生,在能力范围内最大程度的提升MySQ ...
- MySQL Lock--MySQL加锁规则
===================================================================== 淘宝林晓斌总结 在可重复读事务隔离级别下,加锁规则如下: 原 ...
- 你了解MySQL的加锁规则吗?
注:加锁规则指的是next-key lock,如果还不了解next-key lock,请阅读上一篇博客 加锁规则可以概括为:两个原则.两个优化和一个bug: 原则1:加锁的基本单位是next-key ...
- [MySQL] lock知识梳理
MySQL Lock机制 INDEX: MySQL事务隔离级别 MVCC MySQL Lock类型 MySQL MDL CONTENT: 1. MySQL事务隔离级别 Read Uncommit RU ...
- 一条简单的更新语句,MySQL是如何加锁的?
看如下一条sql语句: # table T (id )) delete : MySQL在执行的过程中,是如何加锁呢? 在看下面这条语句: : 那这条语句呢?其实这其中包含太多知识点了.要回答这两个问题 ...
- MySQL优化--INSERT ON DUPLICATE UPDATE死锁
INSERT ON DUPLICATE UPDATE与死锁 在MySQL中提供两种插入更新的方式:REPLACE INTO和INSERT ON DUPLICATE UPDATE,简化了“存在则更新,不 ...
- MySQL字符集与排序规则总结
字符集与排序规则概念 在数据库当中都有字符集和排序规则的概念, 很多开发人员甚至包括有些DBA都会将这个混淆,当然这个情况也有一些情有可原的原因.一来两者本来就是相辅相成,相互依赖关联: 另外一方 ...
随机推荐
- Java小程序分析
public class Helloworld { public static void main(String[] args) { System.out.println("hello wo ...
- ReentrantReadWriteLock
ReentrantReadWriteLock 这个对象,有两个内部类,readLock和writeLock,都有一个aqs的属性sync,实例化的时候,获取的是从ReentrantReadWriteL ...
- UGUI动态绑定事件
using System.Collections.Generic;using UnityEngine;using UnityEngine.EventSystems;using UnityEngine. ...
- Python代码 注释
对某些代码进行标注说明,增加程序的可读性. 一.单行注释 以“#” 开头,#后面的所有东西都不会被运行 print("hello python") # 输出 `hello pyth ...
- L319 Zigbee test coding- field test fail-base on EFR32MG1
1 Test coding Zigbee test of Tx power and frequency for every channel. Testing Procedure1) Power up ...
- centos安装nginx和配置
安装所需环境 Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境. 一. gcc 安装安装 nginx 需要先 ...
- Day11作业及默写
1.写函数,传入n个数,返回字典{'max':最大值,'min':最小值} 例如:min_max(2,5,7,8,4) 返回:{'max':8,'min':2}(此题用到max(),min()内置函数 ...
- CentOS Minimal Install
ifup eth0chkconfig iptables offsestatus vi /etc/sysconfig/network-scripts/ifcfg-eth0 这样设置扣,记得重启网卡:[r ...
- .npy,.mat,.txt转换
.npy--->.txt: http://blog.csdn.net/wgf5845201314/article/details/73825785 .npy<->.mat: i ...
- YII2.0使用ActiveForm表单(转)
Controller控制器层代码 <?php namespace frontend\controllers; use frontend\models\UserForm; class UserCo ...