Explain keywords required for mysql Optimization

Source: Internet
Author: User

I. Syntax

EXPLAIN select sid,filename,filetype from (SELECT * from by_disk_file where uid=830814) a

Result:

Id: indicates the SQL Execution sequence. The SQL statements are executed from large to small.

Select_type: Query type, which can be:

1. SIMPLE

Simple SELECT (do not use UNION or subquery)

For example:

explain SELECT * from by_disk_file where uid=830814

2. PRIMARY

Query operations on the outermost layer

For example:

explain select * from (SELECT * from by_disk_file where uid=830814 )

3. UNION

The second or subsequent SELECT statement in UNION

For example:

explain select * from by_disk_file where uid=830814 union all select * from by_disk_file

4. DEPENDENT UNION

The second or subsequent SELECT statement in UNION depends on the external query.

For example:

explain select * from by_disk_file where uid in(select id from by_common_member where username='mm' union all select id from by_common_member where username='gg')

5. UNION RESULT

UNION result

For example:

explain select * from by_disk_file where uid=830814 union all select * from by_disk_file UNION ALL select * from by_disk_file where uid=830814

The UNION query procedure (based on the above content ):

Define a UNION result set-> UNION statement (from right to left)-> the first statement-> get all results

6. SUBQUERY

The first query in the subquery

explain select * from by_disk_file where uid=(select uid from by_common_member where username='mm')

7. DEPENDENT SUBQUERY

A query in a subquery depends on the external query.

explain select * from by_disk_file where sid in (select sid from by_disk_file where uid=830814)

 

explain select * from by_disk_file where sid =(select sid from by_disk_file where uid=830814 LIMIT 1)

 

Note: If the external query is not a range query, it will only be found once, it is SUBQUERY

If a range query similar to in is used, the value is dependent subquery.

8. DERIVED

Query of the derived table (subquery of the from clause)

explain select sid,filename,filetype from (SELECT * from by_disk_file where uid=830814) a

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.