Four isolation levels and characteristics of database transactions

Before we understand the database isolation level first recall problems you may encounter when reading data from the database:

(1) dirty reads

A transaction data update operation, but also completed, another transaction reads the data at this time, if at this time since the first transaction was rolled back operation fails, then the time to read additional transaction data is dirty data.

(2) non-repeatable read

A transaction, for example, a data reading, and Transaction B immediately modify the data and submit the transaction to the database, the data is again read transaction A different result is obtained, the non-repeatable read transmission.

ps: In some cases, non-repeatable read is not a problem, such as we have repeatedly query a data query of course, to get the final result based. But there may occur in other cases the problem, for example, may be different for the same data A and B in turn queries, A and B can play up ......

(3) Magic Reading

Case in point: transaction A table of all the data are cleared to 0, then insert the data at this time a 2 transaction B, A and then you can find that at this time there was a 2 for the data, as occurred in the same illusion.

The four isolation levels

(1)Read uncommitted

  Uncommitted Read, read transaction has not yet submitted will be read, there will be a dirty read phenomenon. ---- write enable read

(2)Read committed

  Reading submit, it is a read-only transaction after submission, if the transaction data is updated (UPDATE) operation, a read operation to wait for the transaction to read data after the update transaction commits, can solve the problem of dirty read. It appeared in the same query within a transaction scope but returned two different data, which is non-repeatable read. ---- write disable read

(3)Repeatable read

  When repeatable read, the read data is at the beginning (open transaction), modification operations are no longer allowed. ---- prohibited read write, write prohibit all transactions.

(4)Serializable

  Serializable transaction isolation level is the highest, at this level, execution serialization order of the transaction, to avoid dirty reads, non-repeatable read and phantom read. But this is inefficient transaction isolation level, database comparison consumption performance, is not generally used.

 

Four characteristics of the transaction:

Atomicity (atomicity): atomicity refers to all operations in the transaction included either all succeed, or all fail rollback

Consistency (consistency): Consistency means that the transaction must transform the database from one consistent state to another consistent state, that is to say before and after a transaction execution and implementation must be in a consistent state.

Isolation (isolation): Isolation of a user when a plurality of concurrent access to the database, such as operation with a table, a database for each user transaction open, operation not being disturbed by other transactions to the plurality of concurrent transactions between isolated

Persistence (durability): Once the transaction commits, its changes will be made permanently saved to the database. At this point even if the system crashes, the modified data will not be lost.

Guess you like

Origin www.cnblogs.com/leonandyou/p/11306466.html