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

What are the isolation levels in the database

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

What isolation levels are in the database? I believe that many inexperienced people are helpless about this. For this reason, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

1, Read uncommitted.

A transaction reads something that another transaction has not committed. This situation must be avoided. Because uncommitted data from other transactions can be rolled back at any time, programs should not be allowed to read uncommitted data from a transaction at any time. If you read uncommitted data from another transaction, this is called a dirty read. To solve the dirty read problem, increase the transaction isolation level of the database by setting the transaction isolation level to read committed.

2, Read Submitted, Read Committed.

This isolation level solves the dirty read problem.

At this isolation level, parallel execution between two uncommitted transactions is not allowed, but it does allow one transaction to execute and commit while the other is executing. In this way, there will be a situation where the values of a row of data selected twice before and after the first transaction may be different. The reason for the change in value is that transaction 2 performed an update operation on the row of data in the interspersed execution. In the same transaction, the problem that the values selected twice are not the same is called a non-repeatable read problem. To solve the non-repeatable read problem, set the isolation level of the data to repeatable read.

3, can be read repeatedly. Repeatable Read。

At this isolation level, the problem of non-repeatable reads can be solved.

At this isolation level, no other transactions are allowed to operate on a row of data while it is being used by one transaction. Repeatable reads should lock rows in the database. Under this isolation level, other transactions are still allowed to insert and delete data in the table, so it will appear that during the execution of transaction 1, if two rows that meet a certain condition are selected, if another transaction is directly executed in these two selects, insert or delete certain rows, the results that meet the same condition will appear twice. The first select seems to have an illusion. Therefore, this problem is also called phantom reading. To solve the phantom read problem, you need to set the isolation level of the database to serialize.

4, serialization, Serialization.

Serialization can solve the problem of phantom reading.

It requires the execution of transactions to be completely serial. So you lose the efficiency of concurrency.

Mysql's default isolation level is repeatable.

In summary, there are four transaction isolation levels for data, from low to high: read uncommitted, read committed, repeatable read, and serialized. There are three problems associated with database transaction isolation levels: dirty reads, non-repeatable reads, and phantom reads. Dirty read problems need to be solved with read committed, but read committed will have non-repeatable read problems. The problem of non-repeatable reading needs to be solved by repeatable reading, but repeatable reading will have the problem of phantom reading. The phantom reading problem needs to be solved by serialization.

After reading the above, do you know what isolation levels are available in the database? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

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: 0

*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

Database

Wechat

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

12
Report