Database - 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 <# to your form. ##form ...>
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" />来修改这个参数
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!

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



Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.
