Bug #114918 | Phantom-read problem in REPEATABLE-READ mode | ||
---|---|---|---|
Submitted: | 8 May 2024 3:58 | Modified: | 9 May 2024 11:57 |
Reporter: | Ryan Bai | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: DML | Severity: | S3 (Non-critical) |
Version: | 8.0 | OS: | CentOS (7.9) |
Assigned to: | CPU Architecture: | x86 | |
Tags: | phantom-readm, REPEATABLE-READ |
[8 May 2024 3:58]
Ryan Bai
[9 May 2024 10:27]
MySQL Verification Team
Hi Mr. Bai, Thank you for your bug report. However, we do not understand what you are trying to report. First of all, if you do not create an index on InnoDB table, the InnoDB storage engine creates an invisible primary key, so that there is an index. Second, you have not provided the info whether you use auto-committing or not. If you are not using auto-committing, then what you report is expected behaviour. This is because InnoDB is MVCC engine and session 1 can not see the changes made by session 2. These are basics of the multi-version-concurrency-control. Not a bug.
[9 May 2024 11:57]
Ryan Bai
Suppose you have a summary table of loan information that includes: Status column (it is rare to create an index on the status column, because of poor filtering) 1: borrowing 2: overdue 3: Finished User primary key column (there is generally an index created to facilitate the quick location of a user's information, return the corresponding result, and the filter is very good) Now let me assume the scenario 1. Step 1: I use the platform for lending operations, and the status is 1 2. Step 2: Since yesterday was the last repayment date, the status 1 will be changed to 2 (overdue) in batches at 0:00 today. This is a batch processing, and all the status of unpaid money will be changed to overdue 3. Step 3: A user suddenly thinks of the need to pay back the money, slightly later than the above operation to execute, go to the user id (with index). When the money is paid back, the 1 should be changed to the 3. Logically, there should be a lock at this time, telling me that the background is processing data, and I will operate later. But it turns out that because this data is not locked (Because the state is changed using a full table scan, the data is locked one by one), Some data is too late to lock. End result: I just finished the payment, the state did not become 3 but became 2 (phantom reading), and because of the overdue, the overdue interest was stacked up, and the money was gone
[9 May 2024 12:22]
MySQL Verification Team
Hi, What you describe is exactly how repeatable-read should work. These are not phantom reads. This is how this isolation level is defined by SQL Standard. Hence, what you need is some of the other 3 (three) available isolation levels. Besides that, you can use transactional locking statements. All of this is described in many chapters in our Reference Manual. It is you who is designing your application, not MySQL Verification Team.