标签:
mysql> show variables like ‘slow_query_log‘;
+----------------+-------+
| Variable_name | Value |
+----------------+-------+
| slow_query_log | OFF |
+----------------+-------+
1 row in set (0.00 sec)
mysql> set global slow_query_log=on;
Query OK, 0 rows affected (0.05 sec)
mysql> show variables like ‘%slow_query_log_file%‘;
+---------------------+----------------------------------------------+
| Variable_name | Value |
+---------------------+----------------------------------------------+
| slow_query_log_file | C:\xampp\mysql\data\80CEAE742547827-slow.log |
+---------------------+----------------------------------------------+
2 rows in set (0.00 sec)
mysql> show variables like ‘%log_queries_not_using%‘;
+-------------------------------+-------+
| Variable_name | Value |
+-------------------------------+-------+
| log_queries_not_using_indexes | OFF |
+-------------------------------+-------+
1 row in set (0.00 sec)
mysql> set global log_queries_not_using_indexes=on;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like ‘%long_query%‘;
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row in set (0.00 sec)
mysql> set global long_query_time=1;
Query OK, 0 rows affected (0.00 sec)
优化前
select actor.first_name, actor.last_name, count(*) from sakila.film_actor INNER JOIN sakila.actor USING(actor_id) GROUP BY film_actor.actor_id
使用join子查询的方式优化后,actor表没有在使用文件排序和临时表
优化后
select actor.first_name, actor.last_name, c.cnt from sakila.actor INNER JOIN ( select actor_id, count(*) as cnt from sakila.film_actor GROUP BY actor_id ) as c using(actor_id)
虽然优化后仍然扫描了200行的记录,但是actor表没有使用文件排序和临时表
标签:
原文地址:http://www.cnblogs.com/phpfans/p/4749110.html