MySQL performance analysis and explain usage knowledge is the main content of this article, and then let us through some practical examples to introduce the process, I hope to be able to help you.
1. Use the Explain statement to view the results of the analysis
such as explain select * from Test1 where id=1; appears: ID selecttype table type possible_keys key Key_len ref rows extra columns.
which
Type=const means that it is found by index one time, key=primary words indicate that the primary key is used, Type=all is a full table scan, and key=null is useless to the index. Type=ref, because this is considered to be more than one matching row, in a federated query, it is generally ref.
Combined index in 2.MYSQL
Assuming that the table has Id,key1,key2,key3, the three are formed into a composite index, then
Such as:
where key1=.... where key1=1 and Key2=2 where key1= 3 and Key3=3 and Key2=2
According to the leftmost principle, these are indexed, such as the from test where key1=1 the order by Key3, with explain parsing, only the Normal_key index is used, but only the WHERE clause works, and the subsequent order by needs to be sorted.
Http://database.51cto.com/art/201108/284783.htm
MySQL performance analysis and the use of explain