Use of MySQL EXPLAIN statements

Source: Internet
Author: User
Tags mysql connection string

The MySQL EXPLAIN statement can obtain information about how MySQL executes the SELECT statement. The following describes how to use this statement for your reference.

EXPLAIN tbl_name
Or: EXPLAIN [EXTENDED] SELECT select_options

The MySQL EXPLAIN statement can be used as a synonym for DESCRIBE, or obtain information about how MySQL executes the SELECT statement:

EXPLAIN tbl_name is a synonym for DESCRIBE tbl_name or show columns from tbl_name. ·
If the keyword "EXPLAIN" is placed before the SELECT statement, MySQL will EXPLAIN how it processes the SELECT statement and provide the order of how the table is joined and joined.

With the help of the MySQL EXPLAIN statement, you can know when to add an index to the table to obtain a faster SELECT statement that uses indexes to search for records. If an incorrect index is used, run analyze table to update the TABLE statistics, such as the keyword set. This will affect the optimizer's selection.

You can also know whether the optimizer joins the table in an optimal order. To force the optimizer to set a SELECT statement to join in the table naming order, the statement should start with STRAIGHT_JOIN, not just SELECT.

The MySQL EXPLAIN statement returns a row of information for each table in the SELECT statement. Tables are listed in the order they are read by MySQL during query processing. MySQL scans the single-sweep multi-join connections multiple times at a time to solve all connections. This means that MySQL reads a row from the first table, finds a matching row in the second table, and then in 3rd tables. After all the tables are processed, It outputs the selected columns and returns the table list until it finds a table with more matching rows. Read the next row from the table and continue processing the next table.

When the EXTENDED keyword is used, EXPLAIN generates additional information, which can be viewed using show warnings. This information shows the optimizer limits the tables and column names in the SELECT statement, what the SELECT statement looks like after rewriting and executing the optimization rule, and may include other annotations of the optimization process.

Insufficient mysql Indexes

MySql connection string description

Three statuses of mysql triggers

Create MySQL trigger syntax

Provides you with an in-depth understanding of MySQL ifnull () Functions

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.