Lost updates the database, dirty reads, non-repeatable read, phantom read

1. lost updates

When A transaction retraction, the update data B transaction has been submitted covers.

 

 

 

 

2. dirty read

A dirty read transaction occurs in the A read transaction is another modified B, but the data has not been submitted.
If B rollback, the transaction A read data is invalid.

 

 

 

 

3. Non-repeatable read

 

A mean within a transaction, a plurality of times to read the same data, but does not end the transaction A, B another transaction is modifying the data.
Transaction A then B after reading the data transaction to modify the data again, A transaction may read data and the first read data is not the same.

 

This occurs twice in a read transaction data is not the same, which can not be referred to repeatedly read.

 

 

 

Magic Reading (for insert, delete operations)
phantom read occurs when two identical query execution, the second query results returned with the first query set are not the same.

Isolation level
Read UnCommitted (read uncommitted) - update to address the loss of
the lowest level of isolation. A transaction can read the updated results of another transaction did not commit.

Read Committed (Read Committed) - resolved lost updates, dirty reads
default isolation level used by most of the database. Update the result of a transaction only after the transaction commits, the other transaction can read the results with a packet of data updates.

Repeatable Read (repeated reading) - resolved lost updates, dirty reads, non-repeatable reads
the default level of mysql. The entire transaction process, read the results on the same sum of the data is the same, regardless of whether other transactions in the shared data is updated, and whether or not to submit updated.

Serializable (serialization) - resolved lost updates, dirty reads, non-repeatable read, phantom read
highest level of isolation. All transactions executed operations in sequential order. Note that this will lead to decreased concurrency, the worst performance. Usually concurrent with the corresponding locking mechanism to replace it with other concurrent level.

 

The above data to address inconsistencies operational issues be resolved through the database locking mechanism. Click the lock object divided into row-level locking and table-level locking; locking relationship point of view based on concurrent transactions: divided into shared and exclusive locks. To change the data, row on row in the database must be applied to make the changes exclusive lock, insert update delete general will implicitly adopt the necessary line lock. Lock-based mechanism, the four face database transaction isolation level, users only need to set the transaction isolation level, the transaction will be analyzed sql statement and automatically select the appropriate lock. It is noteworthy that, the higher the isolation level, the worse the performance of the database concurrency, that isolation level and concurrent performance transactional database into a negative correlation.

Specific details of the isolation level as shown below:

Guess you like

Origin www.cnblogs.com/sidesky/p/12465372.html