- Use Explain + SQL
Analysis of the implementation plan:
-
id: This table represents the implementation of the priority
-
The same id, sequence table are sequentially performed from the top down;
-
-
-
Different id, and increments, id value is larger the higher execution priority, the first to be executed;
-
-
select_type: a table reading operation of type
-
SIMPLE: Simple SELECT query, and the entire statement in the query does not contain <subquery> and <joint inquiry UNION>
-
PRIMARY: The most complex queries in the outer query, that is, PRIMARY
-
SUBQUERY: `` subquery
-
DERIVED: derived, with the rear FROM subqueries; SELECT * from ( SELECT * from T1 WHERE ID = . 1 ) D1
-
UNION: joint inquiry
-
UNION RESULT: UNION combined result set;
-
-
table: This line represents the operation, which is a table of
-
type : this entry representing the search query mode (7 species are the following descending order according to the Efficiency)
-
system: less than basic, it represents a table, only one record;
-
const: the WHERE the above mentioned id = 1 specified constant inquiry;
-
eq_ref: unique index scan; an index key for the table, only one matching record; (such as id primary key index)
-
ref: non-unique index scan; the WHERE name = ' ZhangSan ' , if ZhangSan more than one person, and the name field has an index, then the ref is retrieved;
-
Range: WHERE ID BETWEEN 30 and 60 , or the like WHERE ID in ( . 1 , . 3 , . 5 )
-
index: SELECT id from User where id is the primary key index;
-
ALL: to indicate a full table scan search method; ALL a genre search, needs to be optimized.
-
-
possible_keys: possible use of the index
-
Key : the index of actual use
-
The number of bytes used in the index: key_len
-
ref: MySQL used to compare the value of the index value. Const single representation is constant comparison, if the name of a column, then compare apples to apples column.
-
rows: a rough estimate of the number of rows per table is queried
-
Extra : Additional information
-
Using filesort: Sort files, without being able to sort through the index, it will default file sorting; If this message appears, expressed the need for optimization;
-
Using temporary: the use of temporary tables, said in ordering, use the temporary table; also reminds us that this statement needs to be optimized;
-
Using index: indicates that the corresponding query using a covering index ;
If accompanied by Using where: indicates that the index is used to perform a lookup index key values;
-
If without Using where: indicates that the index is used to read the data, rather than seek operation;
-
-
impossible where: indicating an error where, for example WHERE name = ' Lisi ' and name = ' zhangsan '
-
distinct: automatic optimization distinct keywords, stops when it finds the first match
-
Explain examples
Execution order table:
-
【select name, id from t2】
-
【select id, name from t1 where other_column = ' '】子查询
-
[Select id, from t3] derived inquiry
-
[Select d1.name ...] outermost query
-
UNION operation