Setting up indexes is essential to keeping your queries nice and quick.
Adding an index is easy – if you’re using phpMyAdmin, just find your table, click “Create an Index” and choose your column or columns.
Adding the right indexes is not easy and can be a bit hit-and-miss. This is where the handy EXPLAIN function comes in. Find your query that you want to optimise and add EXPLAIN to the beginning, as so:
EXPLAIN SELECT * FROM table;
This will give you output similar to:
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE table ALL NULL NULL NULL NULL 67
If your “key” field is NULL, take a look at the table it is against and make sure any JOIN or ORDER BY in your query has an index.
Find more information in the MySQL manual.