简体   繁体   中英

Does MySQL Workbench automatically create indexes for foreign keys?

When I create a foreign key in MySQL workbench, a new entry appears on the "Indexes" tab with the exact same same as the foreign key that I just created.

Is this actually the foreign key, showing up on the "Indexes" tab for some reason? Or does MySQL Workbench try to be helpful and create an index for me, knowing that I'm likely to be selecting against that column, and give it (confusingly) the same name as the foreign key?

It's MySQL doing that, not workbench.
And yes, it is being helpful to create an index when you create a foreign key constraint.

Foreign keys in innodb require an index or a prefix of an index with the same fields as the constraint in the same order. It seems MySQL Workbench automatically creates these since they appear in the SQL script exported from MySQL Workbench. This is helpful but the problem is that it does not recognize the prefix from other indexes so it always creates an index even when it is unnecessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM