[MDEV-22775] [HY000][1553] Changing name of primary key column with foreign key constraint fails. Created: 2020-06-02 Updated: 2021-04-08 Resolved: 2021-04-07 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - InnoDB |
| Affects Version/s: | 10.4.13, 10.4, 10.5 |
| Fix Version/s: | 10.4.19, 10.5.10 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Maarten Manders | Assignee: | Alexander Barkov |
| Resolution: | Fixed | Votes: | 6 |
| Labels: | regression | ||
| Environment: |
Debian 10 |
||
| Issue Links: |
|
||||||||
| Description |
|
Changing the name of a primary key column with a foreign key constraint fails with the following error since 10.4.13: [HY000][1553] (conn=17) Cannot drop index 'PRIMARY': needed in a foreign key constraint
|
| Comments |
| Comment by Maarten Manders [ 2020-07-06 ] | ||||||||||||||||||||||||
|
Any idea in what version this will be fixed? | ||||||||||||||||||||||||
| Comment by Anthony Rsl [ 2020-09-04 ] | ||||||||||||||||||||||||
|
Hello, We are also impacted by this issue since we migrated our MariaDB database from 10.4.12 to 10.4.14. Here is an example and minimal SQL script to reproduce our issue with a UNIQUE KEY (columns have been anonymised):
With MariaDB 10.5.1 and 10.4.12, the ALTER TABLE t CHANGE statement was correctly executed:
And as a result, the parent_id column was renamed to parent_id_renamed. Since MariaDB 10.5.2 and 10.4.12, we have now the following error during the ALTER TABLE t CHANGE statement:
| ||||||||||||||||||||||||
| Comment by Rafał Głowacz [ 2020-09-07 ] | ||||||||||||||||||||||||
|
As a workaround you can temporarily disable foreign key checks:
| ||||||||||||||||||||||||
| Comment by Alexander Karlstad [ 2020-10-13 ] | ||||||||||||||||||||||||
|
There also seems to be no problem using the new
command though, if you're just renaming it and not changing anything else. | ||||||||||||||||||||||||
| Comment by Alice Sherepa [ 2020-10-13 ] | ||||||||||||||||||||||||
|
repeatable on 10.4, 10.5 with utf8:
| ||||||||||||||||||||||||
| Comment by Alexander Karlstad [ 2020-10-14 ] | ||||||||||||||||||||||||
|
Are there, by the way, any known bug reports over at MySQL for the same problems? I tested and had the same issue in MySQL 8, but not in 5.7, so I suspect they have the same issue as well | ||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2021-01-03 ] | ||||||||||||||||||||||||
|
By running git-bisect, I founded that the bug is introduced by df07e00a810890f6f6eb1334c76ee22133750777. The following diff is probably the point. old_part.length and new_part.length are equal but old_cs->mbmaxlen and new_cs->mbmaxlen are not in the Alice's test case.
| ||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2021-03-22 ] | ||||||||||||||||||||||||
|
nayuta-yanagisawa, thank you very much. It looks like the CHARACTER SET is wrongly affecting the check of the INT column. bar, can you suggest how we could refine that code to determine the proper length of the column? The intention of the change was to allow an instant conversion from utf8mb3 to utf8mb4. Character sets are not applicable to columns that do not store character data, yet the information appears to be stored for them. How can we detect that old_part and new_part do not store character data, and thus we should ignore any change of character set? | ||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2021-03-24 ] | ||||||||||||||||||||||||
|
sanja, can you please review? The patch for 10.5
The patch for 10.4:
| ||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2021-04-06 ] | ||||||||||||||||||||||||
|
OK to push |