Transaction isolation analysis

Keywords : isolation, phantom read, lock gap

 
 
1, between concurrent transactions interfere with each other, is conducted isolation between them. This is reflected in the isolation of the transaction.
 
2, four isolation level of the transaction && three kinds of questions:
(1) four isolation levels: read uncommitted, read committed, repeatable read, serialized
(2) three problems: dirty reads, non-repeatable read, phantom read

3, comparative analysis:
(1) && repeatable read unrepeatable reads:
  Repeatable read : refers to a transaction can read updates other affairs, but first read the data, even when the next read another transaction that has this data is updated, the current transaction or to keep the data of the first reading, you can read the abstract thought can repeat the same data. Under this isolation level, only after the current transaction is committed, to be able to read to submit additional transaction. (Clash took place at this time)
 
  Non-repeatable read : refers to a data read can not be repeated, once updated this other transaction data, then the current transaction also need to update this data, the data before can no longer read. In the same transaction, data is read twice inconsistent.
 
Compared:
  ① isolation level repeatable read; non-repeatable read is a phenomenon;
  ② for repeatable read: when the current transaction uncommitted, can not be read to commit other affairs, can only repeat to read the contents of the first reading of the commit;
   For non-repeatable read: when the current transaction uncommitted, can be read to commit other matters, every time to read the contents of other latest committed transaction;
 
(2)Repeatable Read && 幻读:
 
  Achieve four isolation level of the database in different databases are different, in mysql, when implementing the Repeatable Read isolation level, have solved the problem of the phantom reads. (Although the SQL standard does not require phantom reads resolved, but resolved in innodb)
 
How to solve the phantom read?
  ① for the update operation, will add X lock, so other transactions can not update operation, so no phantom read;
  For read operations, but ②: innodb default plus S is not locked, it uses MVCC (equivalent to the read lock) control, while adding a locking gap (gap lock).
   ( "Lock gap" analysis: https://www.cnblogs.com/bestvish/p/10518553.html )
 
(3) Repeatable Read and serialized difference in innodb:
  Prerequisite: Suppose there are two concurrent transactions A, B:
  ①RR isolation level:
    a, A write transaction will add X lock, transaction B can only be read;
    B, A read transaction for reading recording current, controlled by MVCC, plus the current record gap locking gap (equivalent to S lock). At this point the transaction B can not write, can only be read.
  ② serialization level: whether it is read or written, are serialized, read or write in a transaction when the transaction is no other way to read or write.
 

Guess you like

Origin www.cnblogs.com/axing-articles/p/11366890.html