Home > Common Problem > Does virtual reading mean non-repeatable reading?

Does virtual reading mean non-repeatable reading?

藏色散人
Release: 2020-05-21 11:29:03
Original
3013 people have browsed it

Does virtual reading mean non-repeatable reading?

Is virtual reading non-repeatable reading?

Virtual reading and non-repeatable reading are different.

Dirty reads dirty reads: This event occurs when a transaction reads data that has not yet been committed. For example: Transaction 1 modifies a row of data, and then Transaction 2 reads the modified row before Transaction 1 commits the modification operation. If Transaction 1 rolls back the modification operation, then the data read by Transaction 2 can be regarded as never existing.

Non-repeatable reads: This event occurs when a transaction reads the same row of data twice, but the data obtained each time is different. For example: Transaction 1 reads a row of data, and then Transaction 2 modifies or deletes the row and submits the modification operation. When Transaction 1 tries to reread the row, it gets different data values ​​(if the row was updated) or finds that the row no longer exists (if the row was deleted).

Phantom read phantom read: This event will occur if a row of data that meets the search conditions appears in a subsequent read operation, but the row of data does not belong to the original data. For example: Transaction 1 reads some rows that meet a certain search condition, and then Transaction 2 inserts a new row that matches Transaction 1's search condition. If Transaction 1 re-executes the query that produced the original rows, it will get different rows.

The transaction scenario is as follows:

For the same bank account A has 200 yuan, A withdraws 100 yuan, and B transfers 100 yuan to account B. If the transaction is not isolated, the following problems may occur:

1. The first type of lost update: first, when A withdraws money, there is 200 yuan in the account, and at the same time, B transfers 200 yuan, and then A and B operate at the same time, and A operates If 100 yuan is successfully withdrawn, B's operation fails and is rolled back. The final amount in the account is 200 yuan. In this way, A's operation is overwritten, and the bank loses 100 yuan.

2. Dirty reading: A withdraws 100 yuan but does not submit it. B makes a transfer and finds that there is 100 yuan left in the account. This is A giving up the operation and rolling back. B submits the normal operation, and the final amount in the account is 0 yuan. B reads A's dirty data, and the customer loses 100 yuan.

3. Virtual read: Similar to dirty read, it is aimed at the reading problem during the insertion operation. For example, the deposit C of 100 yuan is not submitted. At this time, the bank makes a report for statistical inquiry and the account is 200 yuan, and then C submitted it. At this time, the bank found that the account balance was 300 yuan. It was unable to determine which one should be used as the basis?

Everyone seems to think that statistics must be updated from time to time, which is normal; but it is not normal if the statistics are in a transaction. For example, one of our statistical applications needs to separate the statistical results. Output to the computer screen and the disk file of a computer on the remote network. In order to

improve performance and user response, we divide it into two threads. At this time, the statistical data completed first and completed later may be inconsistent, so we I don’t know which one should prevail.

4. Non-repeatable reading: A and B both started to check that the account was 200 yuan at the same time. A first started to withdraw 100 yuan and submit it. At this time, B made another query when preparing for the final update and found that the result was 100 yuan, then B will be very confused, not knowing whether to change the account to 100 or 0.

The difference between dirty reading and dirty reading is that dirty reading reads the uncommitted dirty data of the previous transaction, while non-repeatable reading re-reads the data that has been submitted by the previous transaction.

5. The second type of lost update: It is a special case of non-repeatable reading. As above, B does not make a second query but directly completes the operation. The final amount in the account is 100 yuan, and A's operation is overwritten. If it falls, the bank loses 100 yuan. It feels similar to the first type of lost update.

The above is the detailed content of Does virtual reading mean non-repeatable reading?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template