[MDEV-26294] Duplicate entries in unique index not detected when changing collation with INPLACE / NOCOPY algoritm Created: 2021-08-02 Updated: 2022-08-31 Resolved: 2022-07-04 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Alter Table, Storage Engine - InnoDB |
| Affects Version/s: | 10.6.0, 10.4.20, 10.5.11 |
| Fix Version/s: | 10.4.26, 10.5.17, 10.6.9, 10.7.5, 10.8.4, 10.9.2, 10.10.0 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Hartmut Holzgraefe | Assignee: | Marko Mäkelä |
| Resolution: | Fixed | Votes: | 2 |
| Labels: | corruption, regression-10.4 | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
When creating a table with a case sensitive collation on a column with unique constraint, then trying to alter the collation to a case insensitive one, entries that only differ in case lead to a duplicate entry error, aborting the ALTER TABLE, when using the COPY algorithm, as expected:
This gives
as expected. When trying the same with ALGORITHM=INPLACE or NOCOPY it works without detecting that we now have a duplicate entry though, so the new table version may now contain data violating the UNIQUE constraint. |
| Comments |
| Comment by Thirunarayanan Balathandayuthapani [ 2021-08-09 ] | |||||||||||||||||||
|
Looks like this issue is caused the following patch:
| |||||||||||||||||||
| Comment by Alexander Barkov [ 2021-10-19 ] | |||||||||||||||||||
|
This problem is also repeatable when altering between two _ci collations:
The error is correct:
Now I use ALGORITHM=NOCOPY:
Looks wrong. See: | |||||||||||||||||||
| Comment by Thirunarayanan Balathandayuthapani [ 2022-02-10 ] | |||||||||||||||||||
|
I took a look at the given patch(https://github.com/MariaDB/server/commit/ab2414a6ceb376a8c03569a7d63d747ff215afdc). Moreover, column in the index points to old collation precise type Test case is
InnoDB DDL has to have the index which has changed column collation value. Then only we could avoid this assert and re-arrange the record depends on Based on the approach, current patch does create new column in inplace_alter heap and index points to the new column. Correct approach would be that InnoDB DDL has to use newly created column (collation changed one) and | |||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-07-01 ] | |||||||||||||||||||
|
thiru, your fix looked correct to me. I took the liberty to improve some comments and simplify the code. Please check if it looks OK to you. | |||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-07-04 ] | |||||||||||||||||||
|
In MariaDB Server 10.4.26 and 10.5.7, the bug will be fixed by refusing native ALTER TABLE when the collation of a column is changed such that it remains or becomes indexed:
In MariaDB Server 10.6.9, the collation change will remain allowed, while any affected secondary indexes will be correctly (re)built online. |