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
How to Grant Permissions to New MySQL UsersHow to Grant Permissions to New MySQL UsersMay 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

How to Add Users in MySQL: A Step-by-Step GuideHow to Add Users in MySQL: A Step-by-Step GuideMay 09, 2025 am 12:14 AM

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

MySQL: Adding a new user with complex permissionsMySQL: Adding a new user with complex permissionsMay 09, 2025 am 12:09 AM

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

MySQL: String Data Types and CollationsMySQL: String Data Types and CollationsMay 09, 2025 am 12:08 AM

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

MySQL: What length should I use for VARCHARs?MySQL: What length should I use for VARCHARs?May 09, 2025 am 12:06 AM

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

MySQL BLOB : are there any limits?MySQL BLOB : are there any limits?May 08, 2025 am 12:22 AM

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

MySQL : What are the best tools to automate users creation?MySQL : What are the best tools to automate users creation?May 08, 2025 am 12:22 AM

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

MySQL: Can I search inside a blob?MySQL: Can I search inside a blob?May 08, 2025 am 12:20 AM

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)