Turn: [transaction isolation level

Database transaction isolation level there are four kinds, from low to high, respectively Read uncommitted, Read committed, Repeatable read, Serializable. Moreover, there may be a dirty read in the concurrent operation of its services, the non-repeatable read, phantom read. Below elaborated on the concept of contact through their stories.


Read uncommitted

Uncommitted Read, by definition, a transaction can read another data uncommitted transactions.

Case in point: the boss to give programmers wages, programmer salary is 36,000 / month. However, the salaries paid to the owner accidentally pressed the wrong number, press into a 39 000 / month, the money has hit the programmer's account, but the transaction has not been submitted, at this moment, the programmer to check their wages this month, We found three thousand dollars more than usual, that raise very happy. But the boss promptly found wrong, almost immediately roll back the transaction submitted, the numbers changed to 36000 and then submit.

Analysis: The actual programmers this month's wages, or 36,000, but the programmer see is 39000. He saw the data when the boss did not commit the transaction. This is the dirty read.


How to solve that dirty read it? Read committed! Read committed, can solve the problem of dirty read.


Read committed

Read committed, by definition, is a transaction have to wait another transaction commits to read the data.

Case: Programmer holding credit card to enjoy life (Cary course, is only 36000), when he pays the bill (programmer affairs open), charging systems detected in advance of his Cary 3.6 million and at this time! ! Programmer's wife should serve as a home all the money transferred out and submit. When the charging system is ready to charge, and then detecting the amount of Cary, we have found no money (the second test amount of course turn out to wait for his wife to submit complete the transaction amount). Programmers will be very depressed, obviously Cary wealthy ...

Analysis: This is the read-committed, if the transaction data is updated (UPDATE) operation, a read operation to wait for the transaction to read data after the update transaction commits, can solve the problem of dirty read. But in this case, there has been the same query within a transaction scope but returned two different data, which is non-repeatable read.


That may be how to solve the non-repeatable read problem? Repeatable read!


Repeatable read

When repeated reading, data is read at the beginning (open transaction), the operation is no longer permitted to modify

Case: Programmer holding credit card to enjoy life (Cary course, is only 36000), when he pays the bill (open affairs, UPDATE not allowed to modify the operation of other matters), charging systems detected in advance of his Cary has 36000 . This time his wife can not be transferred out of the money. Then you can charge a toll system.

Analysis: Repeatable Read can solve non-repeatable read problem. Written here, it is to be understood that, corresponding to non-repeatable read is modified, i.e. UPDATE operation. But it may also have phantom read problem. Because the problem phantom read operation corresponding to the insertion INSERT, UPDATE operation instead.


What will appear when the phantom read?

Case in point: the programmer one day to spend, spend $ 2,000, and then his wife went to see him spending records today (full table scan FTS, wife affairs open), see indeed spent two thousand dollars, at this , programmers spent 10,000 bought a computer, that is a new INSERT consumer records and submit. When the wife of the programmer print a list of records consumption (wife transaction commits), found spent 12,000 yuan, appears to be an illusion, this is the phantom reads.


That phantom read how to solve the problem? Serializable!


Serialization Serializable

Serializable transaction isolation level is the highest, at this level, execution serialization order of the transaction, to avoid dirty reads, non-repeatable read and phantom read. But this is inefficient transaction isolation level, database comparison consumption performance, is not generally used.


It is worth mentioning: Most database default transaction isolation level is Read committed, such as Sql Server, Oracle. Mysql default isolation level is Repeatable read.

 

Transfer: https://www.cnblogs.com/ubuntu1/p/8999403.html

Guess you like

Origin www.cnblogs.com/fangyanr/p/11714228.html