2. transactions four isolation levels
1. If two threads are modified concurrently, They will be disruptive to each other , and the lock mechanism must be used to prevent concurrent modification of multiple threads.
2. If two threads are queried concurrently , There is no thread safety issue
3. If two threads a modification , a query ... will have 3 Types of questions:
1). Dirty reads : One transaction reads to another transaction UNCOMMITTED Data
2). non-repeatable read : --- Row-level issues (change)
3). Virtual Read ( Phantom Read ): refers to a transaction that reads a different transaction the inserted data , causing inconsistencies in the read and backward reading --- table-level issues (additions and deletions)
Four isolation levels :
do not prevent any isolation problems dirty read / non-repeatability / ( Phantom read ) question
can prevent dirty reading problems Span style= "FONT-FAMILY:CALIBRI;" >/ virtual read ( Phantom read ) question
REPEATABLE READ- prevents dirty reads / non-repeatable read problems , but does not prevent virtual reads ( Phantom reads ) Problem
Serializable- database is designed as a single-threaded database to prevent all of the above issues
from the security considerations : serializable>repeatable read>read Committed>read Uncommitted
consider in terms of efficiency : Read Uncommitted>read committed>repeatable read>serializable
When real data is used , based on the needs of your own database , comprehensive analysis of security and efficiency requirements , Select an isolation level to run the database at this isolation level .
MySQL By default is the repeatable read isolation level
Oracle By default is the Read Committed isolation level
Query the isolation level of the current database : SELECT @ @tx_isolation;
set Isolation Levels : Set [global/session] transaction isolation level xxxx; where if you do not write the default is Session refers to the isolation level when modifying the current client and database interactions , and if you use Golbal, The default isolation level for the database is modified .
locking mechanism in the database ---- Shared Locks , Exclusive Lock :
in thenon- Serializable Isolation LeveldoEnquirywithout any locks ., while under the Serializable isolation level. EnquiryPlusShared Locks. features : shared and shared locks can coexist , but shared and exclusive locks cannot coexist
at all isolation levels Delete and change The operation will be added Exclusive Lock . features : cannot coexist with any other lock
Transactions four isolation Levels