Make sure your indexes are being used

When using EXPLAIN, MySQL will tell you what indexes were available to help it perform its query. As mentioned at the start of this chapter, optimisation is the process of improving your code, and may well not be perfect - the MySQL query optimiser tries its best to get the most optimised version of your query, but sometimes it does slip up and fail to use an index.

If this happens, you can provide a hint to MySQL by using the USE INDEX clause - you can specify which fields you would like MySQL to use, and it will honour that.

For example:

SELECT * FROM mytable USE INDEX (Name) WHERE Name = 'Joe' ;

Naturally MySQL would not fail to optimise that query properly as it is so simple, but you get the idea.


Next chapter: Normalisation >>

Previous chapter: Index your data

Jump to:


Home: Table of Contents

Follow us on or Twitter

Username:   Password:
Create Account | About TuxRadar