Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Range explained in detail by MYSQL explain

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Explain shows how MySQL uses indexes to process DML statements and join tables. The information displayed by explain can help select better indexes and write more optimized query statements.

Interpretation of the 2.EXPLAIN column:

Table: shows which table the data in this row is about

Type: this is an important column that shows what type of connection is used. The best to worst connection types are const, eq_reg, ref, range, indexhe, and ALL

Possible_keys: displays the indexes that may be applied to this table. If empty, there is no possible index. You can select an appropriate statement from the WHERE statement for the relevant domain

Key: the index actually used. If NULL, the index is not used. In rare cases, MYSQL chooses indexes that are not sufficiently optimized. In this case, you can use USE INDEX (indexname) in the SELECT statement to force the use of an index or IGNORE INDEX (indexname) to force MYSQL to ignore the index

Key_len: the length of the index used. The shorter the length, the better without losing accuracy.

Ref: shows which column of the index is used and, if possible, a constant

The number of rows that rows:MYSQL believes must be checked to return the request data

Extra: additional information about how MYSQL parses queries. The bad examples are Using temporary and Using filesort, which means that MYSQL cannot use indexes at all, and the result is that the retrieval will be very slow.

The meaning of the description returned by the 3.Extra column:

Distinct: once MYSQL finds a row that matches the row union, it no longer searches

Not exists: MYSQL optimizes LEFT JOIN so that once it finds rows that match the LEFT JOIN standard, it no longer searches

Range checked for each Record (index map:#): no ideal index was found, so for each combination of rows from the previous table, MYSQL checks which index to use and uses it to return rows from the table. This is one of the slowest connections to use an index

Using filesort: when you see this, the query needs to be optimized. MYSQL needs to take additional steps to discover how to sort the returned rows. It sorts all rows according to the connection type and the row pointer to all rows that store the sort key values and matching criteria.

Using index: column data is returned from a table that only uses the information in the index and does not read the actual action, which occurs when all request columns on the table are part of the same index

When Using temporary sees this, the query needs to be optimized. Here, MYSQL needs to create a temporary table to store the results, which usually occurs on the ORDER BY of different sets of columns, not on the GROUP BY

Where used uses the WHERE clause to restrict which rows will match the next table or be returned to the user. This can happen if you do not want to return all the rows in the table and the join type is ALL or index, or the query has a problem with the interpretation of different join types (sorted in order of efficiency)

The system table has only one row: the system table. This is a special case of the const connection type

Const: the maximum value of a record in a table can match this query (the index can be a primary key or unique index). Because there is only one line, this value is actually a constant, because MYSQL reads the value first and then treats it as a constant.

Eq_ref: in a join, when MYSQL queries, the union of each record from the previous table reads a record from the table, which is used when the query uses the index as the primary key or all of the unique key.

Ref: this join type occurs only when the query uses keys that are not unique or primary keys or parts of these types (for example, using the leftmost prefix). For each row join of the previous table, all records are read out from the table. This type depends heavily on how many records are matched by the index-the fewer the better

Range: this connection type uses an index to return rows in a range, such as using > or 1

Id select_type table type possible_keys key key_len ref rows Extra

1 SIMPLE account range PRIMARY PRIMARY 8 2808936 Using where

Looks like it's gone, RANGE.

EXPLAIN SELECT * FROM account WHERE user_id > 1

Id select_type table type possible_keys key key_len ref rows Extra

1 SIMPLE account ALL uid_index 5617872 Using where

There must be a problem here.

EXPLAIN SELECT * FROM account WHERE user_id > 1 AND user_idDATE_FORMAT ("2017-01-26",'% YMY% MMI% d') AND create_timeDATE ("2017-01-26") AND create_time STR_TO_DATE ("2017-01-26",'% YMY% mMel% d') AND create_time

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report