Reputation: 3000
I am working with a fairly old web app that uses MySQL as the database. 90% of the tables are MyISAM, they have no indexes on their foreign keys for the most part.
I was considering porting the whole thing over to InnoDB so I can apply foreign key constraints and the like. However as the application is old and a bit gangly it's been relying on code to enforce referential integrity and I fear that making this change in the database could result in multiple code failures. I don't have time to go through the whole code base and ensure that everything does what it is supposed to, I have no reason to suspect that it doesn't I'm just aware of the possibility of adding foreign key constraints causing unforeseen issues.
I was thinking another approach could be to simply add indexes on the foreign key fields without creating constraints. I'm thinking this would improve performance without the risk of damaging existing functionality. Could anyone tell me if there is a reason not to do this? Would I receive the same performance boost doing this as I would adding indexes AND foreign key constraints?
Upvotes: 0
Views: 285
Reputation: 102793
Yes, just adding the indices should give you almost the same performance boost. The foreign key constraints are more for referential integrity than performance.
There may be some cases where adding those constraints help the DB engine construct a more efficient execution plan; but that's a minor consideration, compared with the benefit of adding well-targeted indices to an index-less database.
Upvotes: 2