Explain and profiling parsing query SQL time

Source: Internet
Author: User

MySQL can use the profiling command to see how long it takes to execute query SQL.

By default, MySQL is turned off by the profiling command:

[SQL]View PlainCopy
    1. SELECT @ @profiling;
+-------------------+

| @ @profiling |

+-------------------+

| 0 |

+-------------------+

Description

0: Indicates that the profiling function is off;

1: Indicates open.

The profiling function can be turned on/off by command.

Open command:

[SQL]View PlainCopy
    1. Set profiling=1;
Close command: [SQL]View PlainCopy
    1. Set profiling=0;
such as query command:

SELECT * FROM Employee limit 1, 10;

You can use the profiling command to see how long it takes to execute this sql:

[SQL]View PlainCopy
    1. Show Profiles;
Query Result:

+----------------+-----------------+-------------------------------------------------------------+

| query_id | Duration | Query |

+----------------+-----------------+--------------------------------------------------------------+

| 1 | 0.00083225 | SELECT * FROM Employee limit 1,10 |

+----------------+-----------------+--------------------------------------------------------------+

1 row in Set (0.00 sec)

Use explain to analyze whether a hit index

[SQL]View PlainCopy
  1. mysql> explain select * from user where username = ' a ';
  2. +----+-------------+-------+------+---------------+------------+---------+-------+------+-------------+  
  3. | ID | Select_type | Table | type | possible_keys | Key | key_len | ref | Rows |  Extra |
  4. +----+-------------+-------+------+---------------+------------+---------+-------+------+-------------+  
  5. | 1 | Simple |    user | ref | user_index | user_index | 1 |  Using where |
  6. +----+-------------+-------+------+---------------+------------+---------+-------+------+-------------+  
  7. 1 row in Set (0.00 sec)

You can see that you have hit index User_index

Explain and profiling parsing query SQL time

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.