Also, when is it appropriate to use one?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
An index is used to speed up searching in the database. MySQL has some good documentation on the subject (which is relevant for other SQL servers as well):
http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
An index can be used to efficiently find all rows matching some column in your query and then walk through only that subset of the table to find exact matches. If you don’t have indexes on any column in the
WHEREclause, theSQLserver has to walk through the whole table and check every row to see if it matches, which may be a slow operation on big tables.The index can also be a
UNIQUEindex, which means that you cannot have duplicate values in that column, or aPRIMARY KEYwhich in some storage engines defines where in the database file the value is stored.In MySQL you can use
EXPLAINin front of yourSELECTstatement to see if your query will make use of any index. This is a good start for troubleshooting performance problems. Read more here:http://dev.mysql.com/doc/refman/5.0/en/explain.html