Explain MySQL database performance analysis of

A, Explain foundation

I believe we explain about the command is no stranger to the specific usage and meaning of the fields can refer to the official website to explain-output, needs to be emphasized here is the core index rows, the vast majority of small rows statement execution must quickly (there are exceptions, will be mentioned below). So basically in a statement optimization optimize rows.

Implementation plan: let mysql estimated perform actions (usually correct) 
All> index> the Range> index_merge> ref_or_null> ref> eq_ref> System / const
the above mentioned id, Email

slow:
the SELECT * from userinfo3 the WHERE name = 'Nick'

EXPLAIN the SELECT * from userinfo3 name = WHERE 'Nick'
type: ALL (full table scan)
SELECT * from userinfo3 limit. 1;
fast:
SELECT * WHERE In Email from userinfo3 = 'Nick'
type: const (index down)

Explain Advanced

Explain command in solving database performance is recommended to use the first command, most of the performance problems can be a simple solution to this command, Explain the effect can be used to view the execution of SQL statements, you can help choose a better index and query optimization , write better optimized statement.

Explain语法:explain select … from … [where …]

For example: explain select * from news;

Output:

+--+-----------+-----+----+-------------+---+-------+---+----+-----+

|id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra|

+--+-----------+-----+----+-------------+---+-------+---+----+-----+

A description of each property to find out about:

1, id: This is the serial number of SELECT queries

2, select_type: select_type is to select the type, you can have the following:

SIMPLE: Simple SELECT (not using UNION or subqueries, etc.) 
a PRIMARY: SELECT outermost
UNION: UNION second or later SELECT statement
DEPENDENT UNION: UNION second or later SELECT statement, depending on the outside query
UNION rESULT: the results of UNION.
SUBQUERY: the first sub-query SELECT
DEPENDENT SUBQUERY: first SELECT subquery depends on the outer query
DERIVED: export table SELECT (FROM clause subquery)

3, table: to display data on this line is what tables of

4, type: This is among the most important, the use of which shows the connection category, with or without the use of the index, is one of the key items using the Explain command analyze performance bottlenecks.

The results from good to bad values followed: 
System <const <eq_ref <ref <FULLTEXT <ref_or_null <index_merge <unique_subquery <index_subquery <range <index <ALL
in general, have to ensure that at least the range query level, preferably to ref, otherwise it may performance problems.

5, possible_keys: column indicates which indexes MySQL could use to find the rows in the table

6, key: display key (index) MySQL actually decided to use. If you do not select an index, the key is NULL

7, key_len: MySQL decided to use the display key length. If the key is NULL, the length is NULL. Length of the index used. Without loss of accuracy, a length as short as possible

8, ref: shows which columns or constants are selected together with a key from a table using the row.

9, rows: show the number of rows MySQL believes it must examine the query execution.

10, Extra: contains detailed information on how MySQL resolves the query, but also one of the key reference items.

Distinct 
Once MYSQL found from row to row with the United match, no longer searched
Not EXISTS
MYSQL optimized LEFT JOIN, once it finds a match LEFT JOIN standard line,
no longer searched
the Range for the each the checked
the Record (index the Map : #)
over the index is not found, so for each combination of a row from the front table, which index is used MYSQL Based check, and use it to return rows from the table. This is an index of one of the slowest connection
Using filesort
see this when you need to optimize the query. MYSQL need for additional steps to find out how to sort the rows returned. It is to sort all the lines according to a row and all rows connection type pointer store and sort key matching condition
Using index
column using only data from the information in the index table is read without returning the actual action, which occurs all requests for table columns are part of the same index when
Using temporary
see this when the need to optimize the query. Here, MYSQL need to create a temporary table to store the results, which usually occurs in the ORDER BY be set for different columns, rather than on the GROUP BY
the Using the WHERE
use the WHERE clause to restrict which rows match with the next table or return to the user. If you do not want to return all the rows in the table, and the connection type ALL or index, this will happen, or is the query in question

Other Tip: When type is displayed as "index", and Extra appear as "Using Index", that the use of a covering index.

 

Guess you like

Origin www.cnblogs.com/xuxiaoming8/p/11628808.html