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

fat*_*ode 3 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;
Run Code Online (Sandbox Code Playgroud)

dou*_*arp 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