Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the difference between unrepeatable reading and phantom reading?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

In this article, I want you to know the difference between non-repeatable reading and illusion reading. There is a certain reference value, there are friends in need can refer to, I hope to help you.

The difference between non-repeatable reading and phantom reading: the focus of non-repeatable reading is modification; under the same conditions, the values of the first and second readings are different. The focus of fantasy reading is on adding or deleting; under the same conditions, the number of records read the first time and the second time is different. From the control point of view, non-repeatable reading only needs to lock records that meet the conditions, while phantom reading needs to lock records that meet the conditions and their close proximity.

Refined explanation:

The point of non-repeatable reading is to modify:

The same conditions, the data you read, you read it again and it's different.

The point of illusion reading is to add or delete

Under the same conditions, the number of records read the first time and the second time is different.

Of course, looking at the overall results, it seems that both appear to be inconsistent between the two readings.

But if you look at it from a control point of view, it's quite different.

For the former, only records that satisfy the condition need to be locked

For the latter, the records satisfying the condition and its proximity must be locked.

Details:

1)"Non-repeatable reading" refers to reading the same data multiple times within a transaction. Before the transaction ends, another transaction accesses the same data. Then, between the two reads in the first transaction, the data read in the first transaction may not be the same due to the modification of the second transaction. This happens because the data read twice in a transaction is different, and is therefore called non-repeatable. For example, an editor reads the same document twice, but in between reads, the author rewrites the document. When the editor reads the document a second time, the document has changed. Original reads are not repeatable. This problem can be avoided if editors can read documents only after the author has written them all

To avoid this situation, you can usually set the isolation level with set tran isolation level repeatable read, so that when transaction A reads the data in table T twice, transaction B will be blocked if it attempts to change the data in table T (details to transaction A reading data), until transaction A commits! This ensures consistency of data read twice by transaction A.

2) Illusion read refers to a phenomenon that occurs when transactions are not executed independently, for example, the first transaction modifies the data in a table, and this modification involves all the data rows in the table. At the same time, the second transaction modifies the data in this table by inserting a new row into the table. Then, later on, the user operating on the first transaction discovers that there are still unmodified rows in the table, as if an illusion had occurred. For example, an editor changes a document submitted by an author, but when the production department merges its changes into the master copy of the document, it finds that the author has added unedited new material to the document. This problem can be avoided if no one can add new material to the document until the editors and production department have finished working on the original document.

The above is a brief introduction to the difference between non-repeatable reading and fantasy reading. Of course, the detailed use of the above differences must be understood by everyone themselves. If you want to know more, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report