In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The mysql explain command is used to show how mysql uses indexes to process select statements and join tables. Through this command, we can analyze the performance bottleneck of the query statement or table structure, so as to write a better SQL statement. Through the expalin command, we can get:
1. The reading order of the table 2. The operation type of the read operation of the table 3. Which indexes can use 4. Which indexes are actually used 5. 5. References between tables 6. How many rows per table are queried by the optimizer
To use explain, you can add explain before the select statement, such as:
Explain select * form codetc
A result will be obtained as follows:
Here are some simple explanations for the explain result column:
Id: identification of the order in which statements are executed.
Select_type:SELECT type, which can be any of the following. Simple-- means no subquery and unionsubquery-- subquery derived-- temporary table union-- federated union result-- union of results
In actual development, subqueries should be used as little as possible and joins should be used to complete them.
Table: shows which table the data in this row is about, that is, the table name.
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. Without losing accuracy, the shorter the length, the better.
Ref: shows which column of the index is used and, if possible, a constant.
The number of rows that rows:MYSQL thinks must be checked to return the request data.
Extra: additional information about how MYSQL parses queries. It will be discussed in Table 4.3.But the bad examples you can see here are Using temporary and Using filesort, meaning that MYSQL cannot use indexes at all, and the result is that retrieval will be slow
The meaning of the description returned by the 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 a row that matches 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.
Using temporary: when you see 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: the WHERE clause is used 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)
System: the 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 all of the index as the primary key or 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
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.