First of all, understand MVCC,MVCC It's called multi version concurrency control , It's actually Save a snapshot of the data at a certain time node .
We actually hide two columns per row , Create version number , Be overdue ( Delete ) Version number , Every time you start a new business , The version number will increase automatically .
take user For example , Suppose we insert two pieces of data , They should actually look like this , The creation version number is incremented .
At this time, let's assume that Xiao Ming performs the query , At this time, too A transaction will be opened by default The current version is current_version=3
select * from user where id<=3;
meanwhile , At this time, Xiaohong opens the transaction to modify id=1 The record of , Xiaohong transaction version is current_version=4
update user set name=' Zhang Sansan ' where id=1;
The result of Xiaohong's successful execution is like this
meanwhile , And black is deleting id=2 The data of , Xiaohei's version is current_version=5, This is the result of Xiaohei's execution .