当前位置:网站首页>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 .

边栏推荐
- Typeorm MySQL upsert operation
- CAD video course recommendation station B
- mysql中的视图、触发器和存储过程
- Intensive reading series of papers
- 64. Minimum path sum: given an M x n grid containing non negative integers, please find a path from the upper left corner to the lower right corner, so that the sum of the numbers on the path is the m
- Insert the laptop into the headset and still play it out (the personal test is valid)
- Mqant in-depth analysis
- 基于STM32的SG90舵机实验含代码(HAL库)
- The adaptation of go language under windows10:vscode
- 【微信小程序】超易懂的条件渲染和列表渲染
猜你喜欢

priority_ Introduction and use of queue

对称加密与非对称加密
![[Huang ah code] Introduction to MySQL - 5. Database tips: a single column group by will, and multiple columns?](/img/4d/552c4251779705a6dfd4ceb59c4261.png)
[Huang ah code] Introduction to MySQL - 5. Database tips: a single column group by will, and multiple columns?

Wechat e-book reading applet graduation design of applet completion works (1) development outline

Software testing - Advanced

VB.NET插件开发- 提取文件

MAUI 框架入门学习05 MVVM数据模型理解

基于JIRA7.9.2定制修改

Wechat e-book reading applet graduation project (6) opening defense ppt

Common methods of C string
随机推荐
ASP. Net1==visual studio create asp net demo
基于JIRA7.9.2定制修改
C language explanation series - practice and consolidation of circular sentences, explanation of binary search
LeetCode之最大正方形(暴力求解和动态规划求解)
Intel experts share: how to program efficiently on XPU architecture? Zhiqiang Research Institute
WPF cannot find resource file problem
Software testing - Advanced
06 MAUI,WPF使用 MVVM Toolkit 框架 构建 MVVM 程序
深度学习中的标量、向量、矩阵和张量的区别
Overview of Baidu map technology, and application development of basic API and webapi
Machine learning 10: Integrated Learning
若依框架包名修改器
Wechat e-book reading of small program graduation project (4) opening report
Set administrator permissions for idea and console
donet framework4. X==windows form application new project, through system Data. SqlClient connects to sqlserver to query
64. 最小路径和:给定一个包含非负整数的 m x n 网格 grid ,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。 说明:每次只能向下或者向右移动一步。
MySQL中的删除:delete、drop、Truncate三者的区别
How to configure binlog
leetcode977. Square of ordered array
surging作者出具压测结果