The problems of database transaction concurrency are: update lost, Dirty read, non-repeatable read, Phantom read. Suppose Zhang San run a merchant bank card, the balance of 100 yuan, respectively, explain the above situation.
1. Update lost: Update of one transaction overwrites the update of another transaction. Transaction A: Save 100 yuan to the bank card. Transaction B: Save 200 yuan to the bank card. A and B read the balance of the bank card at the same time, update the balance separately, and the transaction B that was submitted overwrites the update of transaction A. Update loss is essentially a conflict of write operations, and the workaround is to write one by one.
2. Dirty read: One transaction reads uncommitted data from another transaction. Transaction A: Zhang San wife transfers $100 to Zhang San. Transaction B: Zhang San queries the balance. Transaction A after the transfer (not yet submitted), transaction B query more than 100 yuan. Transaction A is rolled back because of a problem, such as a time-out. The data queried by transaction B is false data. Dirty reading is essentially a conflict between read and write operations, and the solution is to read it after writing.
3, non-repeatable READ: A transaction two times read the same data, two reads inconsistent data. Transaction A: Zhang San wife transfers $100 to Zhang San. Transaction B: 32 query balances. Transaction B queries the balance for the first time, transaction A has not been transferred, the second query balances, transaction A has been transferred, resulting in one transaction, two reads the same data, read the data inconsistent. Non-repeatable reading is essentially a conflict between read and write operations, and the solution is to read and write again.
4, Phantom read: A transaction two times read a range of records, two read the number of records inconsistent. Transaction A: Zhang San wife two queries Zhang San has several bank cards. Transaction B: Zhang San a new bank card. Transaction A for the first time to query the number of bank cards, Zhang San has not new bank cards, the second time to check the number of cards, Zhang San has a new bank card, resulting in two read the number of cards are different. Phantom reading is essentially a conflict between read and write operations, and the solution is to read and write again.
Transaction ISOLATION LEVEL-description