Explain analysis query

Source: Internet
Author: User
Tags mysql query

Briefly:

You can use the EXPLAIN or DESC keyword to simulate the optimizer executing SQL query statements to know how MySQL handles your SQL statements. This can help you analyze the performance bottlenecks of your query statement or table structure.

With the explain command you get:

1. Reading Order of Table

2. Operation type of table read operation

3. Which indexes can be used

4. Which indexes are actually used

5. References between tables

6. How many rows per table are queried by the optimizer

Why to use explain:

Explain can help us analyze SELECT statements and let us know why queries are inefficient, thus improving our queries and enabling the query optimizer to work better.

How the MySQL query optimizer works:

The MySQL query optimizer has several goals, but the primary goal is to use the index as much as possible, and use the most restrictive indexes to eliminate as many rows of data as possible.

The final goal is to commit the SELECT statement to find the data row, rather than excluding the data row.

The reason the optimizer tries to exclude rows of data is that the faster it excludes rows of data, the faster it is to find rows that match the criteria.

If you are able to perform the most rigorous tests first, queries can be executed faster.

Explain limitations:

1. Explain will not tell you about triggers, stored procedure information, or user-defined functions that affect the query.

2, explain will not consider the cache.

Explain analysis query

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.