[MDEV-30416] Can't redefine constraint in a single ALTER TABLE Created: 2023-01-16 Updated: 2023-11-28 |
|
| Status: | Confirmed |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Alter Table, Storage Engine - InnoDB |
| Affects Version/s: | 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10 |
| Fix Version/s: | 10.4, 10.5, 10.6 |
| Type: | Bug | Priority: | Major |
| Reporter: | Remy Fox | Assignee: | Vladislav Lesin |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | foreign-keys | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
It is possible to use one ALTER TABLE to drop and create a new column or index. This is not possible with a constraint; there will an error. See below
|
| Comments |
| Comment by Alice Sherepa [ 2023-01-16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for the report!
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Brent Van Sickle [ 2023-06-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
This is affecting me too. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2023-06-07 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
The problem is that in the InnoDB internal table SYS_FOREIGN there is a unique index on constraint name, which must be unique across all tables in the same database. When no constraint name is specified, it will be generated like databasename/tablename_ibfk_1, but it still has to be unique. Ultimately, this bug would be fixed by changing the metadata format (MDEV-16417). In the test case that user2180613 posted, the duplicate key error is being reported at the time ALTER TABLE internally invokes ha_innobase::create() on a table with a temporary name, in my case it is #sql-alter-825f-4. Normally, the contents of the table def would be copied into that table, the original table def renamed to an intermediate name, the new table renamed to def, and the old table dropped. Because all this is internally done in several independent transactions (there is no API to start and commit DDL transactions), this bug cannot be fixed easily. What could be fixed easily is a failure when SET foreign_key_checks=0; is being used and the foreign key constraint could be added by native ALTER TABLE:
Here is a start of a fix; the first hunk needs to ignore names of "duplicate" constraints that are being dropped at the same time.
This partial fix would benefit everyone when MDEV-16356 is implemented. |