I have been busy changing some SQL queries around so that they look more readable to the human eye, i was also told that they would be maybe 5-10% faster.
The previous SQL statements would look like this.
SELECT * FROM teams WHERE Team1='Joe Bloggs' OR Team2='Joe Bloggs' OR Team3='Joe Bloggs'
I changed it to
SELECT * FROM teams WHERE 'Joe Bloggs' IN (Team1,Team2,Team3)
The new query is approx 10 times slower, after checking what could be the cause i found that it was not using any indexes and even if i tried to force an index it still wouldn't use it.
The table has approx 120,000 rows and i cannot change the table format as other applications i dont have access to, use it. The Team1,Team2,Team3 columns are all VARCHAR(45)
Could anybody explain why the indexes are used for the original query but not the new one? I've read a ton of pages but cannot find the answer, i've read that its possible that mysql is determining that its faster not to use the index, however that shouldnt be the case here as the IN query is almost 10x slower.
Multiple ORs SELECT (run 1000 times with no Cache) - 12.863906860352 elapsed IN SELECT (run 1000 times with no Cache) - 122.73787903786 elapsed
Thank you for your time.