问题
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?
回答1:
It's MySQL doing that, not workbench.
And yes, it is being helpful to create an index when you create a foreign key constraint.
回答2:
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.
来源:https://stackoverflow.com/questions/5957353/does-mysql-workbench-automatically-create-indexes-for-foreign-keys