


What is the difference between dirty read, phantom read and non-repeatable read?
The difference between dirty read, phantom read and non-repeatable read: 1. Dirty read means when a transaction is accessing data and the data is modified; 2. Non-repeatable read means that within a transaction, Read the same data multiple times; 3. Phantom reading refers to a phenomenon that occurs when transactions are not executed independently.
【Related learning recommendations: mysql tutorial】
The difference between dirty reading, phantom reading, and non-repeatable reading:
1. Dirty reading: Dirty reading means that when a transaction is accessing data, and the data is The modification has not yet been committed to the database. At this time, another transaction also accesses the data and then uses the data.
2. Non-repeatable reading: refers to reading the same data multiple times within a transaction. Before this transaction ends, another transaction also accesses the same data. Then, between the two data reads in the first transaction, due to the modification of the second transaction, the data read twice by the first transaction may be different. In this way, the data read twice within a transaction is different, so it is called non-repeatable read. For example, an editor reads the same document twice, but between reads the author rewrites the document. When the editor reads the document a second time, the document has changed. Raw reads are not repeatable. This problem can be avoided if editors can only read the document after the author has finished writing.
3. Phantom read: refers to a phenomenon that occurs when a transaction is not executed independently. For example, the first transaction modifies the data in a table. This modification involves to all data rows in the table. At the same time, the second transaction also modifies the data in this table. This modification inserts a row of new data into the table. Then, in the future, the user who operates the first transaction will find that there are still unmodified data rows in the table, as if a hallucination has occurred. For example, an editor changes a document submitted by an author, but when production merges their changes into the master copy of the document, it is discovered that the author has added new, unedited material to the document. This problem can be avoided if no one can add new material to the document until the editors and production department have finished working on the original document.
Supplement: Spring declarative transactions based on metadata:
The Isolation attribute supports a total of five transaction settings, the details are as follows:
DEFAULT uses the isolation level set by the database (default), and the isolation level is determined by the DBA's default settings.
READ_UNCOMMITTED will cause dirty reads, non-repeatable reads, and phantom reads ( The lowest isolation level and high concurrency performance)
READ_COMMITTED Non-repeatable read and phantom read problems will occur (locking the row being read)
REPEATABLE_READ will produce phantom reads (lock all rows read)
SERIALIZABLE guarantees that all situations will not occur (lock the table)
The focus of non-repeatable reading is modification:
In the same transaction, the data read twice is different.
The focus of phantom reading is to add or delete
Under the same conditions, the number of records read out for the first and second times is different
Dirty read:
emphasizes that the second transaction is not new enough.
The above is the detailed content of What is the difference between dirty read, phantom read and non-repeatable read?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.
