Can anyone tell me if MySQL does indexing for its foreign keys automatically or not?
My MySQL is using MyIsam Engine.
MyISAM does not support foreign keys at all. From the manual:
For storage engines other than InnoDB, MySQL Server parses the FOREIGN KEY syntax in CREATE TABLE statements, but does not use or store it. ... At a later stage, foreign key constraints will be implemented for MyISAM tables as well.
This is for MySQL 5.6, the next version, so it is not implemented yet. The text is exactly the same for older versions.
This means that the foreign key construct is not used at all. You can specify it in your CREATE TABLE
command but MySQL will silently ignore it. No index will be made out of it, and it won't be stored (so a SHOW CREATE TABLE
command will not show that you tried to createa a foreign key).
If you need foreign key support, consider using the InnoDB storage engine instead. InnoDB creates indices automatically for foreign keys.