Sunday, February 21, 2016

MySQL Ignore Index

I had to use something in a MySQL query last week that I haven't needed before.  IGNORE INDEX  I was aware that you could do this sort of thing, but I don't recall ever using it or seeing it in use before.  I have a query that joins a couple tables and looks for records with a particular foreign key value.  For some values of that column it was using an index that I added specifically for this query.  This was taking 1-2 seconds to run.  For other values it would use a different index and take 25-30 seconds to run.  I added an IGNORE INDEX for the one that I didn't want.  Then it started using a different index that had the same problem, so I had to ignore that one too.  Now it seems to be working quickly for all values and using the index that I want.  In most cases I have found that the database is pretty good and finding indexes that work best, but I guess not in this case.

No comments:

Post a Comment

Coding

  I'm not sure where I heard this, and it wasn't worded this way, but it helps to think about coding this way. Basically, any progra...