Mysql慢查询日志记录更快的查询

时间:2012-10-05 00:26:00

标签: mysql mysql-slow-query-log

我在我的数据库服务器上设置了mysql慢查询日志,并将长查询时间设置为5。 只需检查日志及其日志记录查询,只需几毫秒。任何人都知道为什么会这样?,这里有一些日志。

最后一个查询并不是最优化的。它说它检查了450000行,所以我不会惊讶地看到它在日志中。然而查询时间表示只花了0.2秒。慢查询日志还有更多信息,只需查询执行时间吗?

# Query_time: 0.000525  Lock_time: 0.000151 Rows_sent: 1  Rows_examined: 115
SET timestamp=1349393722;
SELECT `we_members`.*, `we_referrals`.`code` as referral_code
FROM (`we_members`)
LEFT JOIN `we_referrals` ON `we_referrals`.`m_id` = `we_members`.`id`
WHERE `we_members`.`facebook_id` = '100'
LIMIT 1;

# Query_time: 0.000748  Lock_time: 0.000104 Rows_sent: 3  Rows_examined: 691
SET timestamp=1349393722;
select distinct(m_id), m.first_name, m.facebook_id, m.photo_url from
            we_connections f
            left join we_members m on m.id = f.m_id
            where ( (f.friend_id = 75 or f.m_id = 75 and m.id != 75))
            and m.id >0
            and m.id != 75
            order by m_id;

# Query_time: 0.259535  Lock_time: 0.000098 Rows_sent: 16  Rows_examined: 455919
SET timestamp=1349393722;
select distinct(m_id), m.first_name, m.facebook_id, m.photo_url from
            we_connections f
            left join we_members m on m.id = f.m_id
            where (f.friend_id IN (select friend_id from we_connections f where f.m_id = 75) or (f.friend_id = 75 or f.m_id = 75 and m.id != 75))
            and m.id >0
            and m.id != 75
            order by m_id;

1 个答案:

答案 0 :(得分:5)

鉴于在某些查询中检查了大量行,您可能也设置了log_queries_not_using_indexes选项 - 任何不使用索引的查询也将写入慢查询日志。您可以在my.cnf文件中检查此选项。

http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_log-queries-not-using-indexes

有关写入日志http://dev.mysql.com/doc/refman/5.5/en/slow-query-log.html

的查询类型的详细信息