We’ve reformatted the output slightly to fit better in the book. You can see that MySQL
reports that the possible_keys
are names(meaning that the index could be used for this query) and that the key that it’s decided to use is names. So, what you expect and what is happening are the same, and that’s good news You’ll
find out more about theEXPLAIN
statement in Chapter The index we’ve created is also useful for queries on only the firstname column. For example, it can be used by the following query:
mysql>
SELECT * FROM customer WHERE -> firstname = "Rose";You can use
EXPLAIN
to check whether the index is being used. The reason it can be used is because the firstname column is the first listed in the index.
In practice, this means that the index
clusters,
or stores together, information about rows for all people with the same first name, and so the index can be used to find anyone with a matching first name.
The index can also be used for searches involving combinations of first name and second name, for exactly the same reasons we’ve just discussed. The index clusters together people with the same first name, and within that it clusters people with identical first names ordered by second name. So, it can be used for this query:
mysql>
SELECT * FROM customer WHEREShare with your friends: