[MDEV-26947] UNIQUE column checks fail in InnoDB resulting in table corruption Created: 2021-10-31 Updated: 2023-08-18 Resolved: 2021-11-01 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - InnoDB |
| Affects Version/s: | 10.7 |
| Fix Version/s: | 10.7.2 |
| Type: | Bug | Priority: | Blocker |
| Reporter: | Roel Van de Paar | Assignee: | Thirunarayanan Balathandayuthapani |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | UNIQUE, not-10.2, not-10.3, not-10.4, not-10.5, not-10.6, regression | ||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Description |
|
Leads to:
Bug confirmed present in: Bug (or feature/syntax) confirmed not present in: |
| Comments |
| Comment by Roel Van de Paar [ 2021-10-31 ] | ||||||||||||
|
Alternative testcase
| ||||||||||||
| Comment by Roel Van de Paar [ 2021-10-31 ] | ||||||||||||
|
Interestingly, this testcase produces no errors in the CLI output:
Yet there is clearly corruption recorded in the log:
Thus, besides fixing the bug, a secondary action item would be to improve the error flow so the CLI output shows a corrupt table message, alike to the examples above. | ||||||||||||
| Comment by Marko Mäkelä [ 2021-11-01 ] | ||||||||||||
|
I think that you got what you asked for, by executing SET unique_checks=0 and then inserting data that violates a UNIQUE constraint. InnoDB started to honor the session parameter unique_checks in MySQL 4.0.18. The parameter had been introduced in MySQL 4.0.3. Even before For compatibility with files generated by mysqldump, serg suggested that we use foreign_key_checks=0,unique_checks=0 for enabling the bulk insert feature. This was implemented in All that said, I agree that the CHECK TABLE output for index c2 looks strange. Why does it say contains 0 entries, instead of 1 or 2? | ||||||||||||
| Comment by Elena Stepanova [ 2021-11-01 ] | ||||||||||||
|
I think the problem here is previous user experience, or a lack thereof. Because at least in recent history hardly anyone could ever make this option work, users might not realize that it's far from innocent and can corrupt a table, and the option description is way too light for this to to expected. MySQL's a bit better as it at least mentions user's responsibility for the input data, but still, no mention of actual damage. Facing the question what effect I myself would expect, I couldn't come up with any sensible answer right away. Indeed, come to think of it, that's the only outcome, but it never occurred to me before. After some thinking, I would say that as a user, I'd expect the table somehow complain about data inconsistency (so errors in CHECK are fine, as long as they are accurate), but then I'd expect to still be able to handle the data – select it and remove the non-unique values or ALTER-IGNORE the table to get rid of them; and currently it's apparently impossible to do either, instead one should fix the structure – dropping the index should fix it, I presume. I guess it needs to be documented somehow now when the option works. | ||||||||||||
| Comment by Marko Mäkelä [ 2021-11-01 ] | ||||||||||||
|
thiru implemented a fix that will trigger ER_ERROR_DURING_COMMIT during the "statement commit" (actually, end of statement) of the INSERT. I think that the error message is misleading because it explicitly says COMMIT while the transaction will remain active:
But, that is a separate bug, outside InnoDB. I find the concept of "statement commit" confusing. I would welcome a better term that would capture the concept of releasing statement-level resources. The only somewhat observable resource would be the auto-increment lock, which I would like to disappear ( | ||||||||||||
| Comment by Roel Van de Paar [ 2021-11-04 ] | ||||||||||||
|
As per discussion with Marko added comment in MDEV-25036 to improve the cryptic error message. | ||||||||||||
| Comment by Marko Mäkelä [ 2023-08-18 ] | ||||||||||||
|
I wrote earlier in this ticket:
Yesterday, mleich produced an rr replay trace while testing |