Use and Analysis of EXPLAIN for query optimization

Source: Internet
Author: User
Tags mysql manual mysql query optimization

Different SQL statement writing methods often bring about great performance differences. How can we know the overhead of SQL query execution? MySQL provides the EXPLAIN keyword for us. When you add the EXPLAIN keyword before your select statement, MySQL will EXPLAIN how it processes the SELECT query and provide the order of how the table is joined and joined, the number of scanned records and other related information can be used to optimize your SQL query.
EXPLAIN select id, username from userinfo where username like '% peng % ';
The EXPLAIN keyword is added before the query statement, so we can get the following report.
Copy codeThe Code is as follows:
Id: 1
Select_type: SIMPLE
Table: userinfo
Type: ALL
Possible_keys: NULL
Key: NULL
Key_len: NULL
Rel: NULL
Rows: 6
Extra: Using where

Explain the meaning of each data item:
Id:
SELECT identifier, the serial number of the SELECT query;
Select_type:SELECT type, which can be SIMPLE (SIMPLE query) and PRIMARY (outermost select;
Table:Tables Used
Type:Join type
Possible_keys:Available index Columns
Key:Actually used index Column
Key_len:Key Length
Rel:Which column or constant is used together with the key to select rows from the table?
Rows:Number of checked rows
Extra:This column contains detailed information about MySQL queries.

For more detailed explanations, refer to the MySQL manual. It doesn't make sense to copy the manual content here. When you have the reference data, mySQL query optimization can be completed more accurately.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.