On the understanding of dirty reading, phantom reading and non-repetition reading

Source: Internet
Author: User
Tags repetition

Generally we are familiar with the four kinds of isolation modes of business, from pine to strict in order:

-READ UNCOMMITTED (READ UNCOMMITTED): Dirty reads, Phantom reads, non-repeatable reads may occur in this mode-read Committed (Read Committed): Phantom read, non-repeatable read in this mode-repeatable read (REPEATABLE Read) : Phantom read-serial (Serialize) may occur in this mode: No phantom read   so dirty read, Phantom Line, non-repeatable read what does it mean? -Dirty Read: Other transactions (execution of a single SELECT statement also counted as a transaction) can read data that has been updated by a transaction (including insertions and deletions) but uncommitted. Dirty Reading is an application that should be avoided because it reads unreliable data (I think this is called Phantom Line more image, actually not). The general database is not set to this mode, but it is sometimes used. The benefit of dirty reads is that the table or record is not locked when read, and can be queued around the write queue to avoid waiting. If you want to select all the data in a table in a particularly frequent update, you can display the specified isolation level: SELECT .... at isolation 0 -non-repeatable READ: This is a comparison of the execution results of two identical SELECT statements in the same transaction. If the result is the same as before and after, it is repeatable, and if the results can be different before and after, it is not repeatable to read. This feature can be literally seen.       Non-repeatable read mode no dirty reads first, that is, the data being read is submitted. In a transaction, the read operation is not an exclusive lock, the next time an identical SELECT statement execution, the hit dataset may have been modified by other transactions, this time, can still read the same content?       Therefore, to achieve repeatable read results, the database needs to do more things, for example, to read the data row to share the lock, and keep to the end of the transaction, to prohibit other transactions to modify it. This can degrade the performance of the database. The isolation level of the serial is more stringent than repeatable reading. The isolation level of the general database is set only to read Committed. This is the result of both reliability and performance.       above also mentions only the lock on the hit data row to prevent other transactions from modifying it. But not mentioned, what if other transactions increase the qualifying data rows? Some databases have a new two levels defined for this scenario: read stability and cursor stability. The former does not restrict new rows of data that match the criteria, while the latter blocks the addition of such rows.  -Phantom read: means that two executions of the same SELECT statement will result in different results, the second read will add a row of data, and does not say that the two executions are in the same transaction. OneIn a situation like this, phantom reading should be exactly what we need. But sometimes it's not, if you open a cursor, you don't want the new record to be added to the data set that the cursor hit when you manipulate the cursor. The isolation level is   cursor stability and can prevent phantom reads.  

Understanding of Dirty reads, Phantom reads, non-repeatable reads

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.