Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A brief introduction to Mysql transaction isolation levels

2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

The main content of this article is "A brief introduction to Mysql transaction isolation level". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "A brief introduction to the Mysql transaction isolation level".

When the engine of our database is InnoDB.

The isolation levels of transactions are divided into uncommitted reads (read uncommitted), committed reads (read committed), repeatable reads (repeatable read), and serialization (serializable).

Unsubmitted read

Uncommitted read means, for example, that the original value of name is Xiaogang, and then there is a transaction B'update table set name = 'Xiaoming' where id = 1`, which has not yet committed the transaction. At the same time, transaction An also starts. There is a select statement 'select name from table where id = 1`. The value of name obtained at this isolation level is Xiaoming rather than Xiaogang. In case transaction B rolls back, the name in the actual database is still Xiaogang, but transaction A returns a Xiaoming, which is called dirty read.

Submitted for reading

According to the above example, in the case of committed read, the result of transaction A's select name is Xiaogang, not Xiaoming, because at this isolation level, one transaction can only read committed transaction data modified by another transaction. But there is a phenomenon.

Let's take the above example. If transaction B commits implicitly at this time, then the select name result of transaction An is clear, which is fine, but transaction An is not finished, and transaction B then `commit = 'Little Red' where id = 1` and commit implicitly. Then transaction An executes `red = 1` again and returns Xiao Hong. This phenomenon is called unrepeatable.

Repeatable read

Repeatable readability means that one transaction can only read committed transaction data modified by another transaction, but the data read for the first time, even if this value is modified by another transaction, when this transaction reads the data again, it is the same as the first time, and will not change with the modification of other transactions.

The difference between this and a committed read is that the value it reads repeatedly is the same. So it was aptly named repeatable. According to this isolation level, the example above is

Serialization

The above three isolation levels can read and write the same record concurrently, but only read-read concurrency can be performed in serialized format. As long as there is a transaction that operates the write of a record, other transactions that want to access the record have to wait.

Generally no one uses serialization, the performance is relatively low, commonly used is committed read and repeatable read. The implementations of committed and repeatable readings are mainly basic version chains and readView. The difference between them is actually the strategy for generating readView.

At this point, I believe you have a deeper understanding of "A brief introduction to the Mysql transaction isolation level". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 204

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report