Description of the read and consistent read in the Current Mode

Source: Internet
Author: User

In the previous article "differences between read in the current mode and consistent read", I used two special examples to describe the differences between read in the current mode and consistent read, it also mentions that "if the corresponding data block changes during the period from when the transaction is started to when the data block is read, unexpected things may happen ". However, such unexpected results may be accepted by us, but they may be unacceptable.

Let's take a look at the following two UPDATE statements:

 
 
  1. 1:    
  2. update t_test1 set lio=0 where object_id in (101,102);    
  3. 2:    
  4. update t_test1 set lio=(select lio from t_test1 where object_id = 101) where object_id = 102 and (select count(*) from t_test2 t1, t_test2 t2) > 0;   

Logically, whether the statement is run, we want the lio of the two records object_id = 101 and object_id = 102) to be the same.

However, since the UPDATE statement will introduce both consistent read and current mode read, and there is a time difference between the two types of read, we may get unexpected results.

Here is an example.

 
 
  1. 13:27:23 HELLODBA.COM>update t_test1 set lio=1 where object_id in (101,102);    
  2.     
  3. 2 rows updated.    
  4.     
  5. 13:29:06 HELLODBA.COM>commit;    
  6.     
  7. Commit complete.    
  8.     
  9. Session 1:    
  10. 13:29:06 HELLODBA.COM>alter system flush buffer_cache;    
  11.     
  12. System altered.    
  13.    
  14. 13:29:11 HELLODBA.COM>-- Transaction 1 begin ---    
  15. 13:29:11 HELLODBA.COM>update t_test1 set lio=(select lio from t_test1 where object_id = 101) where object_id = 102 and (select count(*) from t_test2 t1, t_test2 t2) > 0;    
  16.     
  17. 1 row updated.    
  18.     
  19. 13:29:25 HELLODBA.COM>commit;    
  20.     
  21. Commit complete.    
  22.     
  23. 13:29:25 HELLODBA.COM>-- Transaction 1 end ---    
  24. 13:29:25 HELLODBA.COM>select object_id, lio from t_test1 t where object_id in (101,102);    
  25.     
  26. OBJECT_ID        LIO    
  27. ---------- ----------    
  28.        101          0    
  29.        102          1    
  30.     
  31. 13:29:25 HELLODBA.COM>    
  32.     
  33. Session 2:    
  34.     
  35. 13:29:11 HELLODBA.COM>-- Transaction 2 begin ---    
  36. 13:29:16 HELLODBA.COM>update t_test1 set lio=0 where object_id in (101,102);    
  37.     
  38. 2 rows updated.    
  39.     
  40. 13:29:16 HELLODBA.COM>commit;    
  41.     
  42. Commit complete.    
  43.     
  44. 13:29:16 HELLODBA.COM>-- Transaction 2 end ---   

In this example, we run the preceding two statements concurrently, but finally we get a result that is different from our logical goal.

The SCN of transaction 1 is earlier than the SCN of transaction 2, so it uses a snapshot data to get the old data from consistent read) to update the latest data read by the current mode ).

I cannot say that this is not a defect of MVCC, but it has at least caused logical confusion.


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.