[MDEV-18139] ALTER IGNORE ... ADD FOREIGN KEY ... ALGORITHM=COPY causes bogus ER_TABLE_EXISTS_ERROR and lengthy InnoDB error message Created: 2019-01-04 Updated: 2019-04-23 Resolved: 2019-04-23 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Alter Table, Storage Engine - InnoDB, Storage Engine - XtraDB |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.2.24, 5.5.64, 10.1.39, 10.3.15, 10.4.5 |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Marko Mäkelä |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
Also reproducible on MySQL 5.6. |
| Comments |
| Comment by Marko Mäkelä [ 2019-01-05 ] | |||||||||||||||||||||||||||||||
|
On a related note, I think that the following should be fixed at the same time:
This is unnecessarily being rejected; after all, IGNORE should imply that we do not care whether the constraint holds, and could simply add it without any checking.
This message should not be issued if IGNORE was specified, and the reason should be changed to ‘needs IGNORE or foreign_key_checks=OFF’. | |||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2019-01-13 ] | |||||||||||||||||||||||||||||||
|
See MDEV-18221 for another (non-deterministic) occurrence of the same error messages. The test case there doesn't even involve foreign keys. | |||||||||||||||||||||||||||||||
| Comment by Ryan Southwell [ 2019-01-31 ] | |||||||||||||||||||||||||||||||
|
May be related to https://bugs.mysql.com/bug.php?id=72751 Input:
| |||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2019-04-23 ] | |||||||||||||||||||||||||||||||
|
The error occurs when ALTER IGNORE TABLE invokes ha_innobase::rename_table() to rename the rebuilt table to t1. InnoDB internally reports DB_DUPLICATE_KEY when it is about to rename the FOREIGN KEY constraints in row_rename_table_for_mysql():
At the time of the failure, the table SYS_FOREIGN contains the following records: The bug appears to be that the _ibfk_1 suffix was used for both FOREIGN KEY constraints. The ALTER IGNORE should have assigned the suffix _ibfk_2 instead, and this function should only replace the first part of the name. | |||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2019-04-23 ] | |||||||||||||||||||||||||||||||
|
The bug is in the hacky InnoDB parser for FOREIGN KEY constraints. The following fix appears to work:
This bug should affect MariaDB 5.5 as well; its grammar allows both ONLINE and IGNORE between the words ALTER TABLE: ALTER alter_options TABLE_SYM. If I remove the offending , ALGORITHM=COPY from the test case, indeed I can repeat this on 5.5:
With a port of the fix to 5.5, the operation will succeed. | |||||||||||||||||||||||||||||||
| Comment by Ryan Southwell [ 2019-04-23 ] | |||||||||||||||||||||||||||||||
|
Will this be backported to 10.0? |