How to use SQL Profiler Performance Analyzer

Source: Internet
Author: User
Tags how to use sql


How to use SQL Profiler Performance Analyzer mysql's SQL Performance Analyzer is mainly used to display the usage of various resources during SQL Execution.
Analyzer can better demonstrate the performance problems of poor SQL statements. The following is an example of how to use MySQL SQL Profiler: www.2cto.com. First, enable MySQL SQL Profiler mysql> SELECT @ profiling; + ------------- + | @ profiling | + ------------- + | 0 | + ------------- + 1 row in set (0.00 sec) mysql> SET profiling = 1; Query OK, 0 rows affected (0.00 sec) mysql> SELECT @ profiling; + ------------- + | @ profiling | + ------------- + | 1 | + ------------- + 1 row in set (0.00 sec) by default, the value of profiling is 0 indicates that MySQL SQL Profiler is OFF. After enabling SQL Performance Analyzer, the value of profiling is 1. through the SQL Performance Analyzer, www.2cto.com compares the two execution processes before and after the following statements. It is very helpful for us to understand the detailed execution process of SQL. Mysql> create table t_engines select * from t_engines1; Query OK, 57344 rows affected (0.10 sec) Records: 57344 Duplicates: 0 Warnings: 0 mysql> select count (*) from t_engines; + ---------- + | count (*) | + ---------- + | 57344 | + ---------- + 1 row in set (0.00 sec) mysql> select count (*) from t_engines; + ---------- + | count (*) | + ---------- + | 57344 | + ---------- + 1 row in set (0.00 sec) mysql> SHOW PROFILES; + ---------- + ------------ + bytes + | Query_ID | Duration | Query | + ---------- + ------------ + Duration + | 26 | 0.10213775 | create table t_engines select * from t_engines1 | 27 | 0.00032775 | select count (*) from t_engines | 28 | 0.00003850 | select count (*) from t_engines | + ---------- + ----- Tables + 15 rows in set (0.01 sec) mysql> show profile for query 27; + tables + ------------ + | Status | Duration | + ------------------------------ + ------------ + | (initialization) | 0.00000425 | checking query cache for query | 0.00004050 | checking permissions | 0.00001050 | Opening tables | 0.00018250 | System lock | 0.0000045 0 | Table lock | 0.00001775 | init | 0.00001075 | optimizing | 0.00000550 | executing | 0.00002775 | end | 0.00000450 | query end | 0.00000325 | storing result in query cache | 0.00000400 | freeing items | 0.00000400 | closing tables | 0.00000500 | logging slow query | 0.00000300 | + -------------------------------- + ---------- + 15 rows in set (0.00 sec) mysql> SHOW PROFILE QUERY 28; + ----------------------------------- + ------------ + | Status | Duration | + ------------------------------------- + ------------ + | (initialization) | 0.00000350 | checking query cache for query | 0.00000750 | checking privileges on cached query | 0.00000500 | checking permissions | 0.00000525 | sending cached result to client | 0.00001275 | logging slow query | 0.00000450 | + -- --------------------------------- + ------------ + 6 rows in set (0.00 sec) mysql> SELECT sum (FORMAT (DURATION, 6) as duration from INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID = 27 order by seq; + ---------- + | DURATION | + ---------- + | 0.000326 | + ---------- + 1 row in set (0.00 sec) mysql> SELECT sum (FORMAT (DURATION, 6 )) as duration from INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID = 28 order by seq; + ---------- + | DURATION | + ---------- + | 0.000039 | + ---------- + 1 row in set (0.00 sec) mysql> www.2cto.com from the above example, we can clearly see the difference between two count statements, show profile for query 27 shows the first count statistics execution process, including Opening tables and Table lock. Show profile for query 28 shows the execution process of the second count statistics. The second count directly returns the count statistical result from the QUERY cache. It is found by comparing the total execution time of the two statistics, the cache read speed is 10 times faster than the physical read speed. Using SQL Performance Analyzer can help us diagnose SQL statements that are difficult to identify performance problems and find out the root cause of the problem.

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.