Transaction ISOLATION LEVEL-description

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.