explain analysis sql

mysql command can be used to explain the performance of the query parsing, only you need to add before the query explain keywords.

Next, the results were in each field is parsed.

1) Type select_type select query

SIMPLE indicates that this query is a simple query that does not contain union and sub-queries.

PRIMARY indicating a query is the outermost query

UNION indicating a query is the union of the second or subsequent queries

The first sub-query select SUBQUERY

2) table query which table

3)type 

This field is important to determine whether the query efficient basis. By type type, you can learn the query is a full table scan or index scan.

Common type of type

system is only one table of data, this is a special type const type.

const for the equivalent query scans a primary key or unique index, the most returns only one row of data. const query speed is very fast, because it is only read once.

eq_ref this type typically occurs in a multi-table join query, indicates for each of the results of the previous table, the results can only be matched to one row of the table, and the comparison operation is generally = query, the query higher efficiency.

ref This type usually occurs join queries, or for non-unique primary key index, or use the query leftmost prefix rule index.

range indication index range query, the data acquisition section record table by index field range. This type is usually found in =,> =, <=, between, in other operations.

index represents the full index scan, just scan all of the index can get results, without the scan data. When such a case, extra fields are displayed using index.

ALL represents a full table scan, this type of query query performance is one of the worst. Generally speaking, we should not be there ALL query types, such as in the case of a large amount of data, the performance of the database is a huge disaster.

4) possible_keys the query may choose index

5) key the query to the exact use of the index

6) ref which field or constant is used together with key

7) rows Show this query scans the total number of lines, which is an estimate

8) filtered query expressed as a percentage of this filtered data

9) extra extra information

Guess you like

Origin www.cnblogs.com/mydesky2012/p/11493801.html