Transaction isolation level

concept

The isolation of transactions refers to the degree of isolation between concurrent transactions. The higher the degree of isolation, the lower the data visibility and the lower the degree of concurrency that can be supported.

isolation level

  • READ UNCOMMITTED;
  • READ COMMITTED;
  • REPEATABLE READ (default);
  • SERIALIZABLE;

READ UNCOMMITTED

Definition: transaction A can read uncommitted data of transaction B;
problem: dirty read. If transaction B rolls back, the data read by transaction A is wrong or does not exist.

READ COMMITTED

Definition: Transaction A can read the data submitted by transaction B;
Problem: Non-repeatable read. During the execution of transaction A, if other transactions submit write operations, the records of multiple queries in transaction A may be inconsistent.
Implementation principle: lock + MVCC, every time you query data, read the data of the latest transaction version.

Each consistent read, even within the same transaction, sets and reads its own fresh snapshot.

REPEATABLE READ

Definition: During the execution of transaction A, the results of multiple queries are consistent;
problem: phantom reading. During the execution of transaction A, if another transaction has submitted a write operation, then transaction A does not perceive it, for example, transaction B inserts new data.

Suppose that you are running in the default REPEATABLE READ isolation level. When you issue a consistent read (that is, an ordinary SELECT statement), InnoDB gives your transaction a timepoint according to which your query sees the database. If another transaction deletes a row and commits after your timepoint was assigned, you do not see the row as having been deleted. Inserts and updates are treated similarly.

Implementation principle: lock + MVCC, each time you query data, you can only read data less than or equal to the current transaction version.

This is the default isolation level for InnoDB. Consistent reads within the same transaction read the snapshot established by the first read. This means that if you issue several plain (nonlocking) SELECT statements within the same transaction, these SELECT statements are consistent also with respect to each other.

SERIALIZABLE

Definition: Serialized execution of concurrent transactions;
Problem: Low performance, generally not used.

refer to:

  1. https://dev.mysql.com/doc/refman/5.7/en/innodb-transaction-isolation-levels.html
  2. https://dev.mysql.com/doc/refman/5.7/en/innodb-consistent-read.html
  3. https://dev.mysql.com/doc/refman/5.7/en/glossary.html#glos_consistent_read;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324421264&siteId=291194637