当前位置:网站首页>Sql--- related transactions
Sql--- related transactions
2022-07-02 01:03:00 【Game programming】
The four characteristics of affairs

- Atomicity (Atomicity): Transactions are the smallest unit of execution , Division is not allowed . The atomicity of the transaction ensures that the action is either complete , Or it doesn't work at all ;
Uniformity (Consistency): After the execution of the transaction , The database changes from one correct state to another ;
Isolation, (Isolation): When accessing the database concurrently , One user's transaction is not interfered by other transactions , The database between concurrent transactions is independent ;
persistence (Durability): After a transaction is committed . Its changes to the data in the database are persistent , Even if the database fails, it should not have any impact .
What are the problems of concurrent transactions
Dirty reading
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 .
What if A The value of a row of data updated is A value , But did not submit , At this point, the transaction B I checked the value of this line of data , The value you see is A value , Then transaction B Get it A Value to do various operations , however A Right again A Value has been modified , Lead to B Did a lot of operations with the wrong value .
Missing changes
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
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
Read the same data multiple times within 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 .
such as A Checking balance in , The first view of account balance is 300, here B Withdraw money from the account again 300,A The second time I checked the account, it was found that 0.
Fantasy reading
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 .
Simply speaking , You have a business A, Send a message first SQL sentence , There is a condition , To query a batch of data , Such as SELECT \* FROM table WHERE id > 10 . so what , It came out at the beginning 10 Data . Then this time , Other business B Several pieces of data were inserted into the table , And business B Also submitted , At this time, several lines of data are added .
Then business A At this point, the second query , Once again, as like as two peas before. SELECT \* FROM table WHERE id > 10 This article SQL sentence , Several pieces of data were inserted due to other transactions , This led to its query 12 Data .
Unreal reading is similar to nonrepeatable reading , Unreal reading is adding or missing a few lines of data , Unrepeatable reading refers to the modification of a single piece of data .
What are the transaction isolation levels ?MySQL The default isolation level for is ?
SQL The standard defines four isolation levels :
- 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 .

MySQL InnoDB Storage engine in REPEATABLE-READ( Can be reread ) The transaction isolation level uses Next-Key Lock Lock algorithm , So we can avoid the production of unreal reading , It works with other database systems ( Such as SQL Server) Is different . So InnoDB The default isolation level supported by the storage engine is REPEATABLE-READ( Can be reread ) The transaction isolation requirements can be fully guaranteed , That is to say SQL The standard SERIALIZABLE( Serializable ) Isolation level . But what you need to know is InnoDB The storage engine uses... By default REPEATABLE-READ( Can be reread ) There will be no loss of performance .
InnoDB There are three algorithms for storing engine locks :
Record lock: Locks on a single line record
Gap lock: Clearance lock , Lock a range , Not including the record itself
Next-key lock:record+gap Lock a range , Include the record itself Next-key lock That is, the data of this line and this piece , Are locked .
author : Garden baby Hutu
this paper [ SQL--- Related affairs ] Included in Game programming ️ - database , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome browser .
边栏推荐
- Creation of volume group for AIX storage management (I)
- DTL dephossite | prediction method of dephosphorylation sites based on Transfer Learning
- Powerful calendar wechat applet source code - support the main mode of doing more traffic
- 970 golang realizes the communication between multithreaded server and client
- 程序员该如何更好的规划自己的职业发展?
- [CTF] bjdctf 2020 Bar _ Bacystack2
- [eight sorts ①] insert sort (direct insert sort, Hill sort)
- PLC Analog input analog conversion FB s_ ITR (Mitsubishi FX3U)
- Global and Chinese markets of digital crosspoint switches and mux/demux 2022-2028: Research Report on technology, participants, trends, market size and share
- Comprehensive broadcast of global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Leetcode skimming: stack and queue 04 (delete all adjacent duplicates in the string)
![[dynamic planning] interval dp:p3205 Chorus](/img/25/3dc7132e1aaa5c0eca87382692fc12.jpg)
[dynamic planning] interval dp:p3205 Chorus

The pain of Xiao Sha

excel查找与引用函数

How to type spaces in latex
![[wechat authorized login] the small program developed by uniapp realizes the function of obtaining wechat authorized login](/img/c1/23be4399119f42d85a7b86fc8a59fc.png)
[wechat authorized login] the small program developed by uniapp realizes the function of obtaining wechat authorized login
![[eight sorts ②] select sort (select sort, heap sort)](/img/4b/da0d08230391d6ee48cd8cfd2f7240.png)
[eight sorts ②] select sort (select sort, heap sort)

Some understandings of graph convolution neural network r-gcn considering relations and some explanations of DGL official code

AIX存储管理之逻辑卷的创建及属性的查看和修改

Infiltration records of CFS shooting range in the fourth phase of the western regions' Dadu Mansion
随机推荐
Deb file installation
【八大排序①】插入排序(直接插入排序、希尔排序)
excel查找与引用函数
Global and Chinese markets for supply chain strategy and operation consulting 2022-2028: Research Report on technology, participants, trends, market size and share
2022 safety officer-b certificate examination practice questions simulated examination platform operation
How to determine whether the current script is in the node environment or the browser environment?
[conference resources] the Third International Conference on Automation Science and Engineering in 2022 (jcase 2022)
工作中非常重要的测试策略,你大概没注意过吧
测试人进阶技能:单元测试报告应用指南
一名优秀的软件测试人员,需要掌握哪些技能?
Basis of deep learning neural network
Creating logical volumes and viewing and modifying attributes for AIX storage management
sso单点登录的实现。
The 8-year salary change of testers makes netizens envy it: you pay me one year's salary per month
SSO single sign on implementation.
From 20s to 500ms, I used these three methods
程序员该如何更好的规划自己的职业发展?
Geek DIY open source solution sharing - digital amplitude frequency equalization power amplifier design (practical embedded electronic design works, comprehensive practice of software and hardware)
449 original code, complement code, inverse code
2022 operation of simulated examination platform for melting welding and thermal cutting work license