The company paid a salary, the leader of the 5000 yuan to the long-expensive account, but the transaction did not submit, and long expensive to check the account, found that the pay has been to account, is 5000 yuan whole, very happy. But unfortunately, the leader found that the amount of money sent to long is not right, is 2000 yuan, and then quickly rolled back to business, modify the amount, the transaction will be submitted, the last long your actual salary only 2000 yuan, long you empty joy.
The above situation, that is what we call dirty Read, two concurrent transactions, "transaction A: Leaders to long your pay", "Transaction B: Long you query Payroll account", transaction B read the transaction A has not yet committed data.
When the isolation level is set to read UNCOMMITTED, dirty reads can occur and how to avoid dirty reads, see the next isolation level.
- Read Committed reading Commit
Long you take the payroll card to spend, the system read to the Cary really have 2000 yuan, and at this time her wife Xie Bigfoot also just in the online transfer, Xie Bigfoot put the salary card of 2000 yuan to his account, and in the long before you submit the business, when the long your deduction, the system check to long your pay card has no money, deduction failure, Long you very puzzled, obviously card money, why ...
The above situation, that is what we call non-repeatable read, two concurrent transactions, "transaction A: Long expensive consumption", "Transaction B: Long expensive wife Xie Bigfoot online transfer", transaction a read the data in advance, transaction B immediately updated the data, and committed the transaction, and transaction a read the data again, the data has changed.
When the isolation level is set to read Committed, dirty reads are avoided, but may cause non-repeatable reads. The default level for most databases is read committed, such as SQL Server, Oracle. To resolve the issue of non-repeatable reads, see the next isolation level.
- REPEATABLE READ repeat
You can avoid non-repeatable reads when the isolation level is set to repeatable read. When the long you take the payroll card to spend, once the system began to read the Payroll card information (that is, the start of the transaction), long expensive wife can not be modified, that is, long expensive wife can not be transferred at this time.
Although repeatable read avoids non-repeatable reads, it is possible to have phantom reads.
Xiedajiao View long-expensive payroll card consumption records. One day, she was inquiring into the total consumption amount of the letter of the long month (select SUM (amount) from transaction where month = this month) is 80 yuan, and the long expensive at this time is good outside Hu eats the sea plug to pay at the checkout counter, consumes 1000 yuan, That is, a new 1000-dollar consumption record (insert transaction ... ), and submitted a transaction, and then Xiedajiao will be long your monthly consumption of the details of the printing to A4 paper, but found that the total consumption of 1080 yuan, Xie Bigfoot is very surprised, thought there was an illusion, the Phantom Read this produced.
To put it simply, Phantom reads when a user reads a range of data rows (not the same row of data), another transaction inserts a new row within that range, and when the user reads the data row of that range, a new phantom row is found.
Serializable, serialization. The most stringent transaction isolation. Requires transaction serialization execution, which is executed one after another and cannot be executed concurrently. There is no problem, but the efficiency is too low, in practice, it is rarely set.