Dirty read, non-repeatable read, Phantom read

Source: Internet
Author: User

1. Dirty read : Dirty read refers to when a transaction is accessing the data, and the data has been modified, and this modification has not been committed to the database, then another transaction also accesses the data, and then used this data.

2. Non-repeatable reads : Refers to the same data that is read multiple times within a transaction. When this transaction is not finished, another transaction accesses the same data. Then, between the two read data in the first transaction, the data that the first transaction two reads may be different because of the modification of the second transaction. This occurs when the data that is read two times within a transaction is not the same and is therefore called non-repeatable read. For example, an editor reads the same document two times, but between two reads, the author rewrites the document. When the editor reads the document for the second time, the document has changed. The original read is not repeatable. You can avoid this problem if the editor can read the document only after the author has finished writing it all.

3. Phantom reads : A phenomenon that occurs when a transaction is not executed independently, for example, the first transaction modifies data in a table that involves all rows of data in the table. At the same time, the second transaction modifies the data in the table by inserting a new row of data into the table. Then the user who will be working on the first transaction in the future finds that there are no modified rows of data in the table, as if the illusion had occurred. For example, an editor changes the document submitted by the author, but when the production department merges its changes into the primary copy of the document, it finds that the author has added the unedited new material to the document. This problem can be avoided if no one is able to add new material to the document until the editor and production department have finished processing the original document.

Supplemental: Metadata-based Spring declarative transactions:

The isolation attribute supports a total of five transaction settings, as described below:

L default uses the isolation level set by the database (default), which is determined by the DBA's default setting to determine the isolation level.

L read_uncommitted Dirty Read, non-repeatable read, Phantom read (lowest isolation level, high concurrency)

L read_committed will appear non-repeatable read, Phantom read problem (lock the row being read)

L Repeatable_read will read (lock all rows Read)

L SERIALIZABLE Ensure that all situations do not occur (lock table)

the key to non-repeatable reading is to modify:
The same condition that you read the data, read it again and find that the value is different
The focus of Phantom reading is to add or delete
The same conditions, the 1th and 2nd readings of the number of records are not the same

  Dirty Read   non-repeatable read     Phantom Read  &nbs P;
serializable  will not   will not        < /td>   will not   
repeatable read  will not   will not               
R EAD committed   will not   will             will     
Read Uncommitted will     will &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&N bsp;   

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.