问题
I've setup mysql slow query log on my database server and set the long query time to 5. Just checked the log and its logging queries that take only milliseconds. Anyone know why that would be?, here's some of the log.
The last query isn't exactly the most optimised. It says it examined 450000 rows so I wouldn't be surprised seeing it in the log. However the query time said it only took 0.2secs. Is there more to the slow query log then just query execution time?
# 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:
Given the large number of rows being examined in some of your queries, you probably have the log_queries_not_using_indexes
option set as well - any queries that do not use an index will also be written to the slow query log. You can check for this option in your my.cnf
file.
http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_log-queries-not-using-indexes
More info on the types of queries written to the log here http://dev.mysql.com/doc/refman/5.5/en/slow-query-log.html
来源:https://stackoverflow.com/questions/12737885/mysql-slow-query-log-is-logging-faster-queries