当前位置:网站首页>MySQL transaction
MySQL transaction
2022-07-18 02:00:00 【_ ady】
List of articles
Business
Definition : If a business operation contains multiple steps , Managed by affairs , So these operations are either successful at the same time , Or fail at the same time .
characteristic : ACID
- Atomic: Atomicity , Is an indivisible minimum operating unit , Or at the same time , Or fail at the same time .
- Consistency: persistence , When a transaction is committed or rolled back , The database will persist the data .
- Isolation: Isolation, , Between multiple transactions . Are independent of each other .
- Durability: Uniformity , Before and after transaction operation , The total amount of data remains the same
Concurrency problems
In a typical application , Multiple transactions run concurrently , Often operate the same data to complete their own tasks ( Multiple users operate on unified data ). Concurrency is necessary , But it may cause the following problems .
Dirty reading (Dirty read): When a transaction is accessing data and modifying the data , This modification has not yet been committed to the database , At this time, another transaction also accesses the data , And then I used this data . Because this data is not submitted yet , So the data read by another transaction is “ Dirty data ”, basis “ Dirty data ” The operation may not be correct .
Missing changes (Lost to modify): When a transaction reads a data , Another transaction also accesses the data , After modifying the data in the first transaction , The second transaction also modifies the data . In this way, the modification result in the first transaction will be lost , So it's called lost modification . for example : Business 1 Read data from a table A=20, Business 2 Also read A=20, Business 1 modify A=A-1, Business 2 Also modify A=A-1, final result A=19, Business 1 The modification of is lost .
It can't be read repeatedly (Unrepeatableread): Reading the same data multiple times in a transaction . Before the end of the business , Another transaction also accesses the data . that , Between two reads in the first transaction , Due to the modification of the second transaction, the data read by the first transaction twice may be different . This happens when the data read twice in a transaction is different , So it's called unrepeatable reading .
Fantasy reading (Phantom read): Unreal reading is similar to nonrepeatable reading . It happens in a transaction (T1) Read a few lines of data , Then another concurrent transaction (T2) When some data is inserted . In the subsequent query , The first thing (T1) There will be more records that don't exist , It's like an illusion , So it's called Unreal reading .
| species | I understand | Mnemonics |
|---|---|---|
| Dirty reading | One transaction reads data modified by another transaction but not committed | S=1000,A modify 800, But didn't submit ,B Read 800,A Roll back , Lead to B Read false data . |
| Missing changes | 2 One transaction modifies one data at the same time | S=1000,A It is amended as follows 900,B It is amended as follows 900, At the same time to modify , |
| It can't be read repeatedly | The point is to modify , A transaction reads the same data and gets different results | S=1000,A First read 1000,B Modify it 800,A Read again as 800 |
| Fantasy reading | Focus on adding or deleting | A transaction uses the same condition to query and get different numbers of results |
SQL Isolation level
READ-UNCOMMITTED( Read uncommitted ): Lowest isolation level , Allow read of uncommitted data changes , Can cause dirty reading 、 Phantom or unrepeatable reading
READ-COMMITTED( Read committed ): Allow to read data submitted by concurrent transactions , Can prevent dirty reading , But phantom or unrepeatable reads can still occur
REPEATABLE-READ( Repeatable ): Multiple reads of the same field are consistent , Unless the data is modified by the transaction itself , Can prevent dirty and unrepeatable read , But phantom reading can still happen .
SERIALIZABLE( Serializable ): Highest isolation level , Completely obey ACID Isolation level . All transactions are executed one by one , In this way, there is no interference between transactions , in other words , This level prevents dirty reads 、 Unrepeatable reading and phantom reading .
| Isolation level | Dirty reading | It can't be read repeatedly | Fantasy reading |
|---|---|---|---|
| READ-UNCOMMITTED | 1 | 1 | 1 |
| READ-COMMITTED | 0 | 1 | 1 |
| REPEATABLE-READ | 0 | 0 | 1 |
| SERIALIZABLE | 0 | 0 | 0 |
边栏推荐
- What are the problems we need to pay attention to in setting the standard of Baidu search basic information?
- [Verilog] 32-bit single precision floating-point number comparison size
- [exercise C] number of varieties of daffodils
- Introduction to redis
- Inner class
- 2020-10-11
- 泛云桌面关键技术分析
- Determine whether the currently requested network is internal or external
- 容器面试问题
- Iotop command (monitor disk IO status)
猜你喜欢

Data transmission: Practice of batch extraction of isomorphic and heterogeneous IP data sources

树莓派远程 桌面显示不全

Servlet api code example: server version confession wall

百家号排名会丢吗,不稳定怎么办?

redis持久化——rdb
![[C exercise] input the month and year, and calculate the number of days in the month](/img/41/11d02273e27eee3bf97815da03bca5.png)
[C exercise] input the month and year, and calculate the number of days in the month

知乎SEO怎么做,如何提高知乎SEO排名?

The type initializer of "opencvsharp.mat" threw an exception

对比一下优质【测试报告】模板与你自己的有何不同?

容器面试问题
随机推荐
WinForm控件属性大全
AI应用启示录:安防市场的蜜糖和砒霜
树莓派远程 桌面显示不全
How to do Zhihu SEO and how to improve Zhihu SEO ranking?
Educational Codeforces Round 112 (Rated for Div. 2) D. Say No to Palindromes(前缀和+思维)
第四十期:JS函数默认参数引发的思考
对比一下优质【测试报告】模板与你自己的有何不同?
针对采集丢权益,企业站,还值得深耕内容吗?
反射面试
10分钟自定义搭建行人分析系统,检测跟踪、行为识别、人体属性All-in-One!
第三十六期:近期文档计划
已备案域名,严格管控买卖,你知道吗?
Servlet api code example: server version confession wall
Educational codeforces round 112 (rated for Div. 2) d. say no to palindromes (prefix and + thinking)
[C exercise] inverted string
[C exercise] print all "Narcissus numbers" from 0 to 100000
C language (program environment and preprocessing)
百家号排名不错,转化率怎么提升呢?
The domain name has been filed, and the trading is strictly controlled. Do you know?
Apt get cannot use syntax error