Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.
Transaction isolation:
Read Uncommitted (read uncommitted content)
For example, if you sell a train ticket, the ticket you get is the first one. After you get the ticket, you can immediately modify it and change it to a locked state, but you don’t have to buy it.
Another transaction also said that it wanted to query 1 ticket. At this time, the query also queried the ticket for the first seat in front. Because the transaction on its side has not been submitted, it sees the data that has not been modified. The data has been modified. If you also issue an update modification here, it will be stuck.
As shown below:
The transaction query on the left shows that the ticket No. 1 is modified, but the transaction query on the other side still shows that the ticket No. 1 is unsold. In fact, the ticket has been locked.
So you can only see the submitted data, not the uncommitted data, because the transaction on your left is uncommitted, so what you see is the data before the submission, you have locked the first ticket, I should give you the second ticket, because your first ticket may not be successful, you can only be successful if others give up that ticket
As shown in the figure below: So there will be a read uncommitted data isolation transaction, also known as dirty read mode, which means that the data you read is not necessarily valid data, enter the following statement to change to dirty read mode
set tx_isolation='READ-UNCOMMITTED';
After changing to dirty read mode, the query will not query No. 1 at this time.
As shown below, if you lock No. 2, it finds No. 3, if you lock No. 3, it finds No. 4
Select @@tx_isolation Query the current transaction isolation level is re-read by default
Dirty read patterns are good and bad:
Benefits Tickets can see the status in time
The downside is that the data may be rolled back
As shown in the figure below: The disadvantage of dirty reading is that, for example, in the following financial example, the modification amount of the financial transaction is 10,000 yuan, and the employee queries 10,000 yuan, and then the financial department makes a rollback and then when you query, it becomes 0. This is Dirty read bad point
Read Committed
Repeatable Read
Serializable (serializable)