EXPLAIN for query optimization

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

EXPLAIN for query optimization different SQL statement writing methods often lead to great performance differences. How can we know the SQL query execution overhead? 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 %'; we added the EXPLAIN keyword before the query statement, then we can get the following report. Id: 1select_type: SIMPLEtable: userinfotype: ALLpossible_keys: NULLkey: NULLkey_len: NULLrel: NULLrows: 6 Extra: Using where describes the meaning of each data item: id: SELECT identifier, SELECT query serial number; select_type: SELECT type, which can be SIMPLE (SIMPLE query), PRIMARY (outermost select), etc.; table: used table type: Join type possible_keys: available index column key: actually used index column key_len: key Length rel: Which column or constant is used together with the key to select the row rows from the table: the number of checked rows Extra: this column contains MySQL solution query details. For more detailed explanations, please refer to the MySQL manual. Here, it is meaningless to copy the manual content again, when you have these reference numbers MySQL query optimization can be completed more accurately.

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.