search
HomeDatabaseMysql TutorialDatabase - A brief discussion of four transaction isolation levels

The database provides four transaction isolation levels. Different isolation levels are implemented using different lock classes.

Among the four isolation levels, Serializable is the highest level and Read Uncommited is the lowest. .
The default isolation level of most databases is: Read Commited, such as Sql Server, Oracle.
The default isolation level of a few databases is Repeatable Read, such as MySQL InnoDB storage engine
Even It is the lowest level, and the first type of lost update problem will not occur.
1. Dirty read (the transaction is not committed, read in advance): Dirty read means when a transaction is accessing data and the data is modified , and this modification has not yet been submitted to the database. At this time, another transaction also accesses this data and then uses this data.
2. Non-repeatable reading (inconsistency between two reads): 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 reads of data 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 all finished writing.
3. Phantom read: refers to a phenomenon that occurs when transactions are not executed independently. For example, the first transaction modifies the data in a table, and this modification involves 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.
4. The first type of update loss (rollback loss):
When two transactions update the same data source, if the first transaction is submitted and the other transaction is revoked, then the first transaction will be The updates made by the firm were also cancelled. In other words, the latest transaction done by the first transaction is lost.
5. The second type of update loss (coverage loss):
The second type of update loss is a concurrency problem often encountered in practical applications. It is essentially the same type of concurrency problem as non-repeatable read. It is usually considered Considered as a special case of non-repeatable reads: when two or more transactions querythe same record and then each update the row based on the original query results, the second type of lost update will occur. Because each transaction is unaware of the existence of other transactions, the modifications made by the last transaction to the record will overwrite the committed updates made by other transactions to the record...
Supplement: Spring declaration based on metadata Sexual affairs:

Isolation Attributes supports a total of five transaction settings, the details are as follows:

l          DEFAULT 使用数据库设置的隔离级别 ( 默认 ) ,由 DBA 默认的设置来决定隔离级别 . 
l          READ_UNCOMMITTED 会出现脏读、不可重复读、幻读 ( 隔离级别最低,并发性能高 ) 
l          READ_COMMITTED  会出现不可重复读、幻读问题(锁定正在读取的行) 
l          REPEATABLE_READ 会出幻读(锁定所读取的所有行) 
l          SERIALIZABLE 保证所有的情况不会发生(锁表)

The focus of non-repeatable reading is to modify:
The same conditions, the data you have read, read it again and find that the value 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

-------------------------- --------------------------------
Transaction propagation behavior type

Spring in TransactionDefinitionInterface specifies 7 types of transaction propagation behaviors,

They specify how transactions are propagated when transaction methods and nested calls to transaction methods occur:

Table 1 Transaction Propagation Behavior type

Transaction propagation behavior type
Description

PROPAGATION_REQUIRED
If there is no current transaction, create a new transaction. If there is already a transaction, add it to this transaction. This is the most common choice.

PROPAGATION_SUPPORTS
Supports the current transaction. If there is no current transaction, it will be executed in a non-transactional manner.

PROPAGATION_MANDATORY
Use the current transaction. If there is no current transaction, an exception will be thrown.

PROPAGATION_REQUIRES_NEW
Create a new transaction. If a transaction currently exists, suspend the current transaction.

PROPAGATION_NOT_SUPPORTED
Perform operations in a non-transactional manner. If a transaction currently exists, suspend the current transaction.

PROPAGATION_NEVER
Executed in a non-transactional manner, if a transaction currently exists, an exception will be thrown.

PROPAGATION_NESTED
If a transaction currently exists, it will be executed within the nested transaction. If there is no current transaction, perform similar operations to PROPAGATION_REQUIRED.

----------------------------------------------- -------------
Simple means no templates are needed. xhtml is the default, with some modules provided by struts2.
For example, it is possible to add m ...>

Mainly to facilitate interface warning and error message processing and page verification
Take a look at struts.properties
or

org/apache/struts2/default.properties
struts.ui.theme=xhtml  
struts.ui.templateDir=template  
struts.ui.templateSuffix=ftl  
你可以在struts.xml中添加
<constant name="struts.ui.theme" value="simple" />来修改这个参数
The last one, as the name suggests, is combined with css to process these contents. If you are a beginner, you don’t need to consider these. If you don’t want these template contents to affect your development, you can change it to simple.

If your page uses css layout and you want to use the enhanced functions of struts2, use css_xhtml to get a better user experience.


The above is the detailed content of Database - A brief discussion of four transaction isolation levels. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL's Role: Databases in Web ApplicationsMySQL's Role: Databases in Web ApplicationsApr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

MySQL: Building Your First DatabaseMySQL: Building Your First DatabaseApr 17, 2025 am 12:22 AM

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL: A Beginner-Friendly Approach to Data StorageMySQL: A Beginner-Friendly Approach to Data StorageApr 17, 2025 am 12:21 AM

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

Is MySQL Beginner-Friendly? Assessing the Learning CurveIs MySQL Beginner-Friendly? Assessing the Learning CurveApr 17, 2025 am 12:19 AM

MySQL is suitable for beginners because: 1) easy to install and configure, 2) rich learning resources, 3) intuitive SQL syntax, 4) powerful tool support. Nevertheless, beginners need to overcome challenges such as database design, query optimization, security management, and data backup.

Is SQL a Programming Language? Clarifying the TerminologyIs SQL a Programming Language? Clarifying the TerminologyApr 17, 2025 am 12:17 AM

Yes,SQLisaprogramminglanguagespecializedfordatamanagement.1)It'sdeclarative,focusingonwhattoachieveratherthanhow.2)SQLisessentialforquerying,inserting,updating,anddeletingdatainrelationaldatabases.3)Whileuser-friendly,itrequiresoptimizationtoavoidper

Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Apr 16, 2025 am 12:20 AM

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL: Database Management System vs. Programming LanguageMySQL: Database Management System vs. Programming LanguageApr 16, 2025 am 12:19 AM

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL: Managing Data with SQL CommandsMySQL: Managing Data with SQL CommandsApr 16, 2025 am 12:19 AM

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft