当前位置:网站首页>[Mysql]--Transaction, transaction isolation level, dirty read, non-repeatable read, phantom read analysis
[Mysql]--Transaction, transaction isolation level, dirty read, non-repeatable read, phantom read analysis
2022-08-09 16:14:00 【Ran959】
La la la, let's talk about affairs today~
If you like me, like me~
What is a transaction?
A transaction in a database is a batch of operations performed on a database
In the same transaction, these operations either all execute or all fail.
a. A transaction is a atomic operation.is the smallest execution unit.(Can consist of one or more SQL statements)
b. In the same transaction, all statements are successfully executed, and the entire transaction successful.
One transaction failed, and the entire transaction failed.
Limit: Only InnoDB and BDB type database tables support transactions.
Characteristics/Principles of Transactions (ACID)
Atomicity (Atomicity):
The entire transaction process is like atomic operations, either all succeed or all fail.
This atomicity is seen from the final result, and from the final result the process is indivisible.
Consistency (Consist):
The integrity of the database not corrupted before the transaction started and after the transaction ended.u>.
For example, one person transfers money to another person, and one person has already deducted the money, but the other person has not received it. This is inconsistent.
Isolated (Isolated):
The execution of transactions is non-interfering, and it is impossible for one transaction to see the data at a certain moment in the middle of other transactions when they are running.
The ability of the database to allow multiple concurrent transactions to read, write and modify its data at the same time. Isolation can prevent data inconsistency due to cross execution when multiple transactions are executed concurrently.
Transaction isolation is divided into: Read uncommitted (Read uncommitted), Read committedspan> (Read committed), repeatable read (Readpeatble read), serialization(Serialzable)
Durability (Durability):
Once a transaction is committed, its change to the data in the database is Permanent.
Means that after the transaction is completed, the changes made by the transaction to the database are persisted in the database and will not be rolled back.
Transaction isolation level
InnoDB's default isolation level is repeatable read
Read uncommitted (Read uncommitted):
Simply put: all transactions can see the data of uncommitted transactions.
Concurrency will occur: dirty read, non-repeatable read, phantom read.
Read committed (Read committed):
The transaction can only be seen after the transaction has been successfully committed.
Concurrency will occur: non-repeatable read, phantom read.
Repeatable read (Readpeatble read):
Multiple queries within the same transaction returned different data.
Concurrency will occur: phantom reading.
Serialzable (Serialzable):
Forced ordering, adding a shared lock on each read row.The most expensive but most reliable transaction isolation level.
Concurrency will occur: it will lead to a large number of timeouts and lock competition.
Problems caused by different isolation levels:
Dirty read (Dirty read):
A transaction is accessing the data and making changes, but before committing, another transaction also accesses the data and uses it, which causes dirty reads.
Summary: read the unmodified records.
Unrepeatable read (Unrepeatableread):
refers to reading the same data multiple times within a transaction, and before the end, another transaction also accesses the data, then the first transaction is between two data reads, because the third transactionChange, the first transaction is read twice and it is not the same.
Summary: Because it was modified by others, I read twice is differentspan>.
Phantom read (Phantom read):
One is modifying and one is adding and deleting.The first person felt that he had hallucinations, and the data kept changing.
Summary: Others have added or deleted the table, and their own reading and modification are inconsistent.
Please give me a thumbs up after reading it~~
边栏推荐
猜你喜欢

启动报错:Caused by: org.apache.ibatis.binding.BindingException汇总解决

【原神】手机版原神下错版本不能登录怎么办?B服修改为官服

DMPE-PEG-Mal Maleimide-PEG-DMPE dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide

如何设计一个高并发系统?

Shell programming loop statement

DBCO-PEG-DSPE, Phospholipid-Polyethylene Glycol-Dibenzocyclooctyne, Reaction Without Copper Ion Catalysis

22岁测试工程师上来就内卷,起薪居然就18k,这谁顶得住?

985测试工程师被吊打,学历和经验到底谁更重要?

Anaconda3安装后无法启动,启动闪退 2020-9

一种基于视频帧差异视频卡顿检测方案
随机推荐
Shell programming loop statement
基于FPGA的FIR滤波器的实现(2)—采用kaiserord & fir2 & firpm函数设计
How to achieve stable profit through the stock quantitative trading interface?
常见的四种电阻之间有什么不同?
回归测试:意义、挑战、最佳实践和工具
docker安装seata(指定配置文件、数据库、容器数据卷等)
985测试工程师被吊打,学历和经验到底谁更重要?
经典面试题 之 SQL优化
In the process of quantitative trading, retail investors can do this
道路标识信息 (RSI)
A Preliminary Study on Baidu Open Source e-chart
Regular Expressions for Shell Programming
My MySQL database was attacked and deleted for ransom, forcing me to use all my might to recover data
Redis6.2.1配置文件详解
Servlet的生命周期
How to flexibly use the advantages of the quantitative trading interface to complement each other?
[MySql]实现多表查询-一对一,一对多
一些需要思考的物理问题
MongoDB adds permission management
Bean的生命周期