Understanding of dirty reads, non-repeatable reads, and Phantom reads in database transactions

Source: Internet
Author: User

The database has four isolation levels, namely:

Solation_read_uncommitted: Allows reading of changed uncommitted data, which can result in dirty reads, non-repeatable reads, and Phantom reads.
Isolation_read COMMITTED: Allows concurrent transactions to be read after committing, avoiding dirty reads, which can result in repeated reads and Phantom reads.
Isolation_repeatable_read: Consistent with multiple reads of the same field, which can result in phantom reads.
Isolation_serializable: The principle of complete compliance with acid, ensuring that no dirty reads, non-repeatable reads, and phantom reads occur.

Four different isolation levels represent the granularity of a database lock on a resource.

Dirty reads: Indicates that the database transaction does not add an exclusive lock when modifying a record, causing other transactions to be queried.

Non-repeatable READ: Indicates that a transaction adds an exclusive lock to a row of records when modifying a database record, which causes other transactions to not be queried and updated, but does not have an exclusive lock on the records of the query until a transaction is complete, and if a transaction queries the same record two times, between two queries, the other transaction may change the current record. The workaround is to lock the records of the query before a transaction is completed, and no other transaction modifications are allowed.

Phantom read: Similar to dirty read, but locked resource granularity is different, dirty read is the same transaction two times query the same record, return different results, and Phantom Read is conditionally query a range of data, such as SELECT * from the users where ID <=20, the first query is 20 records, The second query 19 records, a transaction between two queries, the other transaction deleted a record, resulting in a different two query results. Phantom reading should be a lock table to avoid, that is, lock a transaction query process all tables, can not be updated.

The above is a personal understanding, if there is a mistake, look correct.

Understanding of dirty reads, non-repeatable reads, and Phantom reads in database transactions

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.