当前位置:网站首页>Database - current read and snapshot read

Database - current read and snapshot read

2022-07-06 06:14:00 Snow peak expensive

The current reading :insert update delete for update

Read the snapshot : Non blocking read without lock ,select. The purpose is to improve concurrency

stay RC Under isolation level , The current read and snapshot read results are the same .

stay RR Under isolation level , The current read and snapshot read results may be different

for example

 Business 1  And business 2  Read a piece of data .
select * from user where id =1;
id     money
1       200

 Business 2  Modifying data 
update user set money = 1000 where id = 1;
commit;
 Business 1  read ( Read the snapshot ):
select * from user where id  = 1;
id     money
1       200
 And in the execution ( The current reading ) 	select * from user where id  = 1 for update;
id     money
1       1000

RR Implementation principle of non blocking read at level :

There are actually 3 The fields are :
DB_TRX_ID : Transactions that modify this data ID
DB_ROLL_PRT: rollback pointer
DB_ROW_ID: Hidden lines ID
blog.csdnimg.cn/1c765e2b49574608a15de231483a4974.png)

Business id=1, The data from 12 Change it to 32.

  1. The bank adds an exclusive lock
  2. Copy the data before modification , To undo log Inside
  3. Modify the data of the current line , Fill in transactions id, rollback pointer
     Insert picture description here
    Business id=2, Again on this trip Field3 Make changes .
  4. Add an exclusive lock
  5. Copy the data before modification , To undo
  6. Modify the data of the current line , Fill in transactions id, rollback pointer

Every time you make a modification , Will generate one UNDO log data . When the transaction snapshot reads data, it will pass readView Algorithm , Use the current transaction id And log Of DB_TRX_ID Compare to determine which version of data is taken .

原网站

版权声明
本文为[Snow peak expensive]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060607583583.html