当前位置:网站首页>MySQL lock leak detection and defect filling
MySQL lock leak detection and defect filling
2022-06-12 11:26:00 【YOSHINO_ Cream】
Preface
I saw it today This article —— Learn about common lock types I saw many locks I didn't know or have never seen , It is hereby recorded that .
Intent locks
Use scenarios / Birth background
stay innodb Under the engine , We have put row locks on a row of a table , At this time, you need to lock the table . At this time, the engine will traverse each row in the table one by one , Judge whether there is row lock , If yes, locking fails .
This is obviously inefficient , The intention lock was born .
Intent lock features
- Intentional locks are divided into read intentional locks (IS lock ) And freehand lock (IX lock ) And all are table level locks
- When a transaction needs to be row locked , Will first add an intention lock to the entire table , This solves the problem of traversing the entire table when adding a table lock , Greatly improved performance .
- Press the intention lock directly , Neither intent lock nor row lock is mutually exclusive .
Self increasing lock
Self increasing lock (AI lock ) Simply put, it is a lock used on auto incrementing columns , Mainly for insert statements , When a statement wants to insert data into a table , A self incrementing lock will be added first , Block other insert statements
Self incrementing locking features
- The self incrementing lock is incompatible with each other , The same table has only one auto increment lock
- The self incrementing lock does not comply with the two-phase protocol , When the insert statement succeeds , This self incrementing lock is automatically released
- Even if the transaction is rolled back , The value of the auto increment lock will not decrease back
Several strategies of self incrementing lock
The traditional auto increment strategy has a great impact on the concurrency of insert statements , therefore MySQL It's optimized , A lightweight mechanism is introduced mutex To replace the self incrementing lock .
Through parameters innodb_automic_lock_mode Appoint
innodb_automic_lock_mode = 0 Indicates the use of a traditional self incrementing lock .
innodb_automic_lock_mode=1 Means a compromise , According to the specific situation , It is highly possible to use traditional self incrementing locks , It can also be used mutex Lightweight self incrementing lock . The details are as follows
1.simple insert When the execution engine can clearly know the number to insert by analyzing the statement insert The statement is simple insert. I will use mutex
2. bulk insert It is impossible to know how many rows are inserted by analyzing the statement ( example :INSERT INTO t VALUES SELECT * FROM t1) The insert statement for is bulk insert. In this case, traditional insert
3. mixed insert You are not sure whether you need to allocate columns with sub value added ( example INSERT INTO table VALUES(1,‘a’), (NULL,‘b’), (5, ‘C’), (NULL, ‘d’) ), In this case, the insertion amount in the worst case will be obtained for allocation , Use mutex.innodb_automic_lock_mode=2 All use mutex
Row lock correlation
Record locks
It is the row lock we usually understand
Record lock characteristics
- When we lock the secondary index , It will be Lock the corresponding cluster index
- When the index is not available , A full scan will be performed , Lock all scanned rows . Due to the two-stage agreement , These locks are only released when the transaction is committed , Obviously, it will greatly affect the concurrency . therefore MySQL This mechanism is optimized , When the scanned line is server After the layer is judged as unqualified , It will immediately release the lock of changing profession .( This clearly undermines the two-phase agreement )
Clearance lock (gap lock)
Is a way to load a lock between two indexes , There are... In total when adding the current bid 15 rows , The statement to be operated covers all the records , Then its clearance lock can be added to (-∞,0)(0,5)(5,10)(10,15)(15,superNum) superNum yes innodb The maximum value automatically added to each table .
Next-Key lock
The combination of clearance lock and record lock is called next-key, It is the same as before , At this point, the record of the lock becomes (-∞,0](0,5](5,10](10,15](15,superNum] . Each lock section is open in front and closed in back , Avoid repeated locking and missing locking .
Clearance lock .Next-key lock characteristic
- There is no conflict between clearance lock and clearance lock
- Gap locking only conflicts with inserting statements into this interval .
Insert intention lock
Insert intent lock is a special kind of gap lock , Only in INSERT Statement
Insert Intention 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.
Multiple transactions , At the same index , When inserting records in the same range interval , If the insertion position does not conflict , Not blocking each other .
边栏推荐
- M-Arch(番外11)GD32L233评测-PWM驱动有源蜂鸣器
- go基于阿里云实现发送短信
- 自然语言处理nlp 数据集下载地址
- Socket programming UDP
- 人類想要擁有金錢、權力、美麗、永生、幸福……但海龜只想做一只海龜
- VirtualBox 虚拟机因系统异常关机虚拟机启动项不见了
- redis 總結
- DS18B20 digital thermometer (I) electrical characteristics, power supply and wiring mode
- Clickhouse column basic data type description
- MCUXpresso开发NXP RT1060(3)——移植LVGL到NXP RT1060
猜你喜欢

AcWing 131. 直方图中最大的矩形(单调栈经典运用 模板)

Create vite source code analysis

字节序 - 如何判断大端小端

Network topology

AcWing 128. 编辑器(对顶栈 实现序列内部指定位置高效修改)

DS18B20 digital thermometer (I) electrical characteristics, parasitic power supply mode and remote wiring

人类想要拥有金钱、权力、美丽、永生、幸福……但海龟只想做一只海龟

VirtualBox 虚拟机因系统异常关机虚拟机启动项不见了

【蓝桥杯单片机 国赛 第十一届】

MCUXpresso开发NXP RT1060(3)——移植LVGL到NXP RT1060
随机推荐
Grid layout
k52.第一章 基于kubeadm安装kubernetes v1.22 -- 集群部署
K59. Chapter 2 installing kubernetes V1.23 based on binary packages -- cluster deployment
DS18B20 digital thermometer (I) electrical characteristics, power supply and wiring mode
疫情居家办公体验 | 社区征文
M-arch (fanwai 11) gd32l233 evaluation PWM driven active buzzer
Lambda表达式 | 浅解
AcWing 1921. Rearranging cows (ring diagram)
^33变量提升和函数提升面试题
redis 總結
selenium使用代理IP
scanf返回值被忽略的原因及其解决方法
【CF1392D】D. Omkar and Bed Wars(环形与后效性dp)
SharDingJDBC-5.1.0按月水平分表+读写分离,自动创表、自动刷新节点表
redis 总结
2022-06-11: note that in this document, graph is not the meaning of adjacency matrix, but a bipartite graph. In the adjacency matrix with length N, there are n points, matrix[i][j]
记录一下使用JPA时遇到的坑
Humans want to have money, power, beauty, eternal life and happiness... But turtles only want to be a turtle
AcWing 1912. 里程表(枚举)
AcWing 131. 直方图中最大的矩形(单调栈经典运用 模板)