[Unforgettable memory method] transaction isolation level

Source: Internet
Author: User
When I saw spring3.x a few days ago, I saw the transaction isolation level. Five common transaction concurrency problems are mentioned here, this is what everyone is familiar with: dirty reads, Phantom reads, non-repeated reads, loss of the first type of updates, and loss of the second type of updates. Today, I will focus on the first three most common problems, of course, in the most understandable way. First, what is dirty?

When I saw spring3.x a few days ago, I saw the transaction isolation level. Five common transaction concurrency problems are mentioned here, this is what everyone is familiar with: dirty reads, Phantom reads, non-repeated reads, loss of the first type of updates, and loss of the second type of updates. Today, I will focus on the first three most common problems, of course, in the most understandable way. First, what is dirty?

When I saw spring3.x a few days ago, I saw the transaction isolation level. Five common transaction concurrency problems are mentioned here, this is what everyone is familiar with: dirty reads, Phantom reads, non-repeated reads, loss of the first type of updates, and loss of the second type of updates. Today, I will focus on the first three most common problems, of course, in the most understandable way.

First, what is dirty read?

Academic explanation: Dirty reading means that when a transaction is accessing data and modifying the data has not been committed to the database, another transaction also accesses the data and then uses the data.

My explanation: you are cooking and put the cut food aside to prepare a pot. At this time, my wife told you to open the meal and then put the pile of dishes you have not yet prepared on the table.

What is non-repeated read?

Academic explanation: repeatable reading: Refers to reading the same data multiple times in a transaction. When the transaction is not completed, another transaction also accesses the same data. Therefore, the data read twice in the first transaction may be different because of the modification of the second transaction. In this way, the data read twice in a transaction is different, so it is called non-repeated read.

My explanation: when you are the conductor of a band and when the violin solo in the first movement begins, you think it is wonderful. When the violin solo in the second movement arrives, you saw him disappear. The audience told you that he had gone to the bathroom halfway. He hasn't returned yet.

What is Phantom read?

Academic explanation: this refers to a phenomenon that occurs when a transaction is not executed independently. For example, the first transaction modifies the data in a table, which involves all the data rows in the table. At the same time, the second transaction also modifies the data in this table. This modification inserts a new row of data into the table. In the future, the user who operates the first transaction will find that there are still data rows in the table that have not been modified, just like an illusion.

My explanation: I use the same scenario as "do not read repeatedly". When you play the first movement, you think the music is wonderful, but when it comes to the second movement, you suddenly felt that the music was not harmonious, And then you found that the band suddenly had an extra drummer.

What is the difference between non-repeated read and phantom read?

Repeatable refers to the first time you pay attention to a person in the band, and the second time you see him, there is a change.

Phantom reading refers to a band composed of many people that you paid attention to for the first time. When you saw this band for the first time, there was another person in the band.

Repeated reading is not intended for individual, a piece of data.

Phantom read targets a set and multiple data entries.

Finally, let's look at the four isolation levels of transactions. Pay attention to the top-down order, but the concurrency speed is decreasing.

MySQL5 default transaction isolation level: REPEATABLE-READ

View the transaction isolation level of MySQL5: select @ tx_isolation;

Modify the transaction isolation level of MySQL5: set transaction isolation level read committed;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.