[MDEV-18320] Foreign key implicit index inconsistency Created: 2019-01-21 Updated: 2023-04-27 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Alter Table |
| Affects Version/s: | 10.3.12 |
| Fix Version/s: | 10.4 |
| Type: | Bug | Priority: | Major |
| Reporter: | Remy Fox | Assignee: | Marko Mäkelä |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
MariaDB and MySQL create an 'implicit index', for a foreign key whose columns are not part of an index. That implicit index is removed once the client adds an actual index on the columns involved. However, when the reverse is carried out, i.e. the client removes his actual index again, no implicit index is put back and this causes an error message: Cannot drop index: needed in a foreign key constraint. This is inconvenient for scripts that attempt to reverse actions automatically and there does not seem to be a reason that justifies the inconsistency. Test script:
Now try to reverse these actions:
|
| Comments |
| Comment by Elena Stepanova [ 2019-01-21 ] |
|
I'll leave it to marko to comment on it. |
| Comment by Marko Mäkelä [ 2019-02-18 ] |
|
I think that MariaDB should implement foreign keys in the SQL layer, above storage engines. That would also remove the requirement for implicit indexes to exist. Sure, in that case, FOREIGN KEY constraints would be slower to enforce and locking conflicts could become more common, because table or index scans could be needed. MDEV-12483 already suggests that cross-engine foreign keys should be implemented. |