There is the problem of concurrent transactions and isolation levels

The database is a multi-threaded applications, multi-threaded some of the problems there will be concurrent, here mainly for phantom read, do not answer repeated reading, do some dirty read Introduction

  Dirty read: A transaction reads data to another uncommitted transactions

  Non-repeatable read: multiple queries within a single transaction display of inconsistent

  Phantom read: inconsistent number of times within a transaction results returned by the query

There is a transaction database isolation, and isolation of different implementations, here leads to isolation level transaction isolation levels appear to solve the above mentioned problems.

Transaction isolation level is divided into:

  1. Uncommitted Read (Read uncommitted): the lowest database transaction isolation level, it may be that dirty reads, non-repeatable read, phantom read
  2. Read Committed (Read Committed): can only read between the transaction has been submitted, it is possible to solve the problem of dirty reads, but does not resolve the non-repeatable read, phantom read problem
  3. Repeatable read (Repeatable Reads): avoid dirty reads, non-repeatable read, phantom read can not be avoided
  4. Serialize (Serializable): can be understood as a single thread of execution, a transaction queued for execution, resolves dirty reads, non-repeatable read, phantom read problem
Transaction isolation level Dirty read Non-repeatable read Magic Reading
Uncommitted Read (read-uncommitted) × × ×
Read Committed (read-committed)  √  × ×
Repeatable Read (repeatable-read)  √  √ × 
Serialization (Serializable)  √ √   √

 Mysql supports four isolation level, the default isolation level is repeatable read.

 Oracle supports only: Read Committed, serialized both isolation level, the default isolation level is Read Committed

Note: Some people may have doubts, why is there such four levels of isolation, serialization not been resolved three problems? While serialization solve these three problems, but serialized execution efficiency is very inefficient, which has the code logic to control the transactions executed one by one, so here in order to improve efficiency, such as mysql default isolation level to be repeatable read, phantom read because people can accept, in exchange for a relatively high efficiency of concurrent processing

 

Guess you like

Origin www.cnblogs.com/gsic/p/12601948.html