Causes are three read law: are due to concurrent access of data leads to changes
1. dirty read (read uncommitted)
A transaction reads data B transaction has not submitted, then the transaction rollback operation if an error occurs and B, then A transaction is to read dirty data.
2. Non-repeatable read (read many times before and found inconsistent data)
A read operation is performed in the transaction, because the transaction A is relatively large, complete with before and after reading the data may need to go through a very long time. When a transaction A has finished reading data; then event B performs the change operation, the previous data was revised; when the transaction A string of data that is read a second time and found the contents of the read data with previously different, that is, data is not repeated.
A transaction | Transaction B | |
1 | Begin transaction | |
2 | First read data, Xiao Ming age of 20 | |
3 | Begin transaction | |
4 | Other operations | |
5 | Change Xiao Ming age of 30 | |
6 | Commit the transaction | |
7 | Reading second data, this time for the age is 30 Xiaoming | |
Remark | In accordance with normal logic, taken twice before and after the data A transaction should be consistent |
3. The phantom read (read many times before and after, the amount of data inconsistency is found)
A total amount of the transaction after performing a read operation requires two statistics, the total amount of data before the inquiry at once; B performed an operation where transaction total amount of new data, and submit; A for the second event the total amount of data read, discovered for the first time with a different number of statistics, as had the same illusion, for no reason more than a few data.
A transaction | Transaction B | |
1 | Begin transaction | |
2 | The first query, assuming the amount of data is 100 | |
3 | Begin transaction | |
4 | Other operations | |
5 | 100 newly added data | |
6 | Commit the transaction | |
7 | The second inquiry, found that the amount of data has to 200 | |
Remark | In accordance with normal logic, taken twice before and after the data A transaction should be consistent |