Indexes are essential to any database.
Speaking in “layman” terms, indexes are… well, precisely that. You can think of an index as a second, hidden, table that stores two things: The sorted data and a pointer to its position in the table.
Some thumb rules on creating indexes:
- Create indexes on every field that is (or will be) used in joins.
- Create indexes on every field on which you want to perform frequent
where
conditions. - Avoid creating indexes on everything. Create index on the relevant fields of every table, and use relations to retrieve the desired data.
- Avoid creating indexes on
double
fields, unless it is absolutely necessary. - Avoid creating indexes on
varchar
fields, unless it is absolutely necesary.
I recommend you to read this: http://dev.mysql.com/doc/refman/5.5/en/using-explain.html