Implementation of MySQL multi-version concurrency control MVCC

Implementation of MySQL multi-version concurrency control MVCC

Transaction isolation level settings

set global transaction isolation level read committed; //global set session transaction isolation level read committed; //current session

Modify the transaction submission method (whether to submit automatically, MySQL automatically submits by default)

SET AUTOCOMMIT = 1; //Automatically commit, 0 manually commit

Different database engines have different MVCC modes, typically optimistic and pessimistic concurrency control.

innodb

illustrate:

InnoDB's MVCC is implemented by saving two hidden columns after each row of records. These two columns, one stores the creation time of the row, and the other stores the expiration time (or deletion time) of the row. Of course, what is stored is not the actual time value, but the system version number. Every time a new transaction is started, the system version number will be automatically incremented. The system version number at the start of the transaction will be used as the transaction version number to compare with the queried

SELECT

InnoDB checks each row against the following two conditions:

a. InnoDB only searches for data rows whose versions are earlier than the current transaction version (that is, the system version number of the row is less than or equal to the system version number of the transaction). This ensures that the rows read by the transaction either existed before the transaction started or were inserted or modified by the transaction itself.

b. The deleted version of the row is either undefined or greater than the current transaction version number. This ensures that rows read by a transaction were not deleted before the transaction began.

Only records that meet the above two conditions can be returned as query results.

INSERT

InnoDB saves the current system version number as the row version number for each newly inserted row.

DELETE

InnoDB saves the current system version number as a row deletion identifier for each deleted row.

UPDATE

InnoDB saves the current system version number as the row version number when inserting a new row, and saves the current system version number to the original row as a row deletion marker.

Notice:

MVCC only works at REPEATABLE READ and READ COMMITED isolation levels. The other two isolation levels are incompatible with MVCC because READ UNCOMITTED always reads the latest data row, not the data row that conforms to the current transaction version. SERIALIZABLE will lock all read rows.

Check the status of the table

show table status like 'task'\G;

Dirty reads, non-repeatable reads, and phantom reads

Dirty read: The current transaction reads the uncommitted state of another transaction, and the transaction is not isolated.

Non-repeatable read: Transaction isolation is achieved, but data inconsistency is found when the same data is read twice.

Phantom read: When querying the same batch of data twice, new data is found to have been inserted. This is mainly because other transactions inserted data into the data set in the middle. (Adding a gap lock solves this problem)

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Implementation of MySQL's MVCC multi-version concurrency control
  • Detailed explanation of MySQL multi-version concurrency control mechanism (MVCC) source code
  • In-depth study of MySQL multi-version concurrency control MVCC
  • Analysis of the underlying principle of MySQL multi-version concurrency control MVCC
  • Implementation of MySQL Multi-version Concurrency Control MVCC
  • Mysql MVCC multi-version concurrency control details

<<:  Analysis of the solution to Nginx Session sharing problem

>>:  mysql group_concat method example to write group fields into one row

Recommend

Set IE8 to use IE7 style code

<meta http-equiv="x-ua-compatible" co...

Using Zabbix to monitor the operation process of Oracle table space

0. Overview Zabbix is ​​an extremely powerful ope...

Graphic tutorial on configuring log server in Linux

Preface This article mainly introduces the releva...

Code to enable IE8 in IE7 compatibility mode

The most popular tag is IE8 Browser vendors are sc...

win2008 server security settings deployment document (recommended)

I had been working on the project before the New ...

How to get the real path of the current script in Linux

1. Get the real path of the current script: #!/bi...

How to install Linux flash

How to install flash in Linux 1. Visit the flash ...

How to use Nginx to solve front-end cross-domain problems

Preface When developing static pages, such as Vue...

How to write the parent and child directories of HTML relative paths

How to indicate the parent directory ../ represent...

Understanding and using React useEffect

Table of contents Avoid repetitive rendering loop...

Open the app on the h5 side in vue (determine whether it is Android or Apple)

1. Development environment vue+vant 2. Computer s...

How to use map to allow multiple domain names to cross domains in Nginx

Common Nginx configuration allows cross-domain se...

Use of Linux relative and absolute paths

01. Overview Absolute paths and relative paths ar...

React Hooks Detailed Explanation

Table of contents What are hooks? Class Component...