当前位置:网站首页>MySQL InnoDB transaction related records
MySQL InnoDB transaction related records
2022-07-19 04:31:00 【Mr. Xiangzai】
One 、 Transaction isolation level
MySQL :: MySQL 8.0 Reference Manual :: 15.7.2.1 Transaction Isolation Levels
Two 、InnoDB Different from SQL Statement to set the lock
MySQL :: MySQL 8.0 Reference Manual :: 15.7.3 Locks Set by Different SQL Statements in InnoDB
summary :
1、 SELECT ... FROM Is a consistent read , Read the snapshot of the database without setting the lock , Unless the transaction isolation level is set to SERIALIZABLE. about SERIALIZABLE Level , Search sets the shared next key lock on the index record it encounters . however , For statements that lock rows with unique indexes to search for unique rows , Only one index record lock is needed .
2、 For locked reads (SELECTwithFOR UPDATE or FOR SHARE)、 UPDATE and DELETE sentence , The lock used depends on whether the statement uses a unique index with a unique search condition or a range type search condition .
2.1 For a unique index with unique search criteria , InnoDB Lock only the index records found , Without locking the gap before it . That is, the line lock .
2.2 For other search criteria and non unique indexes , InnoDB Lock the index range of the scan , Use clearance lock Or the next key lock
For locking reads (SELECT with FOR UPDATE or FOR SHARE), UPDATE, and DELETE statements, locking depends on whether the statement uses a unique index with a unique search condition, or a range-type search condition.
For a unique index with a unique search condition, InnoDB locks only the index record found, not the gap before it.
For other search conditions, InnoDB locks the index range scanned, using gap locks or next-key locks to block insertions by other sessions into the gaps covered by the range. For information about gap locks and next-key locks, see Section 15.7.1, “InnoDB Locking”.
What is clearance lock ?
A gap lock is a lock on a gap between index records .
The function of clearance lock
Ensure that the data in a certain gap will not change in case of locking . For example, I mysql Repeatable read at the default isolation level (RR).
When a statement that uses a unique index to search for a unique row , No gap lock required . As the following statement id Column has a unique index , At this time, only id The value is 10 Use record locks for rows .
select * from t where id = 10 for update;// Be careful : If it is a normal query, it is a snapshot read , No need to lock , added for update It's not an ordinary query
If , In the above statement id When the column is not indexed or non unique , The statement will generate a gap lock .
If , There are multiple query criteria in the search criteria ( Even if each column has a unique index ), There will also be clearance locks .
It should be noted that , When id When there is no index on the column ,SQL The full table scan of the clustered index will be used for filtering , Because filtering is in MySQL Server At the level of . So every record ( Whether the conditions are met or not ) Will be added X lock . however , For efficiency ,MySQL Optimized , For records that do not meet the conditions , Will put the lock after judgment , In the end , It's the lock on the record that meets the condition . But lock on records that do not meet the conditions / The lock release action will not be omitted . So when there is no index , Data rows that do not meet the conditions will have a time-consuming process of locking and releasing locks .

边栏推荐
- C language explanation series - practice and consolidation of circular sentences, explanation of binary search
- About the problem of database, the concept of uniqueness and non repetition
- MAUI 框架入門學習05 MVVM數據模型理解
- OSPF routing control, anti ring related knowledge
- 成熟的线程要懂得拒绝
- Swift 【Class】【struct】
- LeetCode之最大正方形(暴力求解和动态规划求解)
- V4l2 learning materials collection
- 使用kaggle跑李宏毅机器学习作业
- Intel experts share: how to program efficiently on XPU architecture? Zhiqiang Research Institute
猜你喜欢

Distributed notes (02) - redis of distributed cache (brief description of uses, features, high availability solutions redis cluster, tweetproxy, CODIS)
![[ruoyi Vue plus] learning notes 30 - redisson (VI) bounded blocking queue (redisson source code + Lua script)](/img/56/f52d13f86764768eee190e22ba136a.png)
[ruoyi Vue plus] learning notes 30 - redisson (VI) bounded blocking queue (redisson source code + Lua script)

对称加密与非对称加密

Machine learning 11: cost sensitive learning

ospf综合实验

C语言基础犄角旮旯的知识之数据类型

智能硬件语音控制的时频图分类挑战赛2.0(思路以及结果,目前top5)

Build a portrait matting server based on openvino model server

Nearly 90% of servers can be saved, but the anti fraud efficiency has increased significantly. Why is PayPal's plan to break the "Ai memory wall" so cost-effective?

ospf防环
随机推荐
Wechat e-book reading applet graduation design of applet completion works (3) background function
LeetCode之最大正方形(暴力求解和动态规划求解)
Simulation Implementation of library function
[Huang ah code] Introduction to MySQL - 5. Database tips: a single column group by will, and multiple columns?
leetcode209. Minimum length subarray
MAUI 框架入門學習05 MVVM數據模型理解
Explain pod and container resource management and allocation in detail (CPU and memory allocation, temporary storage management)
iptables防止nmap扫描以及binlog详解
Xdc 2022 Intel technology special session: Intel Software and hardware technology builds the cornerstone of cloud computing architecture
How to open the applet for people near wechat (the way to open the applet near wechat)
PyTorch Image Models(timm)库
Cabasicanimation pause \ enterprise action
Vs Code common shortcut keys
数据分析报告这样写,才算真正读懂了数据
leetcode977. 有序数组的平方
HCR慧辰北坡而行,一只游入数字营销服务的巨兽
Impersonate the server for requests
ospf综合实验
Wechat e-book reading of applet completion works (7) Interim inspection report
[ruoyi Vue plus] learning notes 30 - redisson (VI) bounded blocking queue (redisson source code + Lua script)