简体   繁体   English

如何将这样的查询保留在mysql_slow.log中?

[英]How can I keep queries like this out of mysql_slow.log?

I have the following query I need help with. 我有以下查询需要帮助。

SELECT a.artist, a.facepic
FROM artists_vs AS v, artists AS a 
WHERE v.genreid =0 
AND (v.artistid1 = a.artistid OR v.artistid2 = a.artistid)
ORDER BY v.bid DESC 
LIMIT 20

All the fields in the query are indexed, but when I run an explain I get the following: 查询中的所有字段都已建立索引,但是当我运行解释时,会得到以下信息:

1   SIMPLE  v   ref genreid,artistid1,artistid2 genreid 4   const   15  Using temporary; Using filesort
1   SIMPLE  a   ALL PRIMARY NULL    NULL    NULL    18165   Range checked for each record (index map: 0x1)

I need to have log-queries-not-using-indexes enabled in my.cnf 我需要在my.cnf中启用log-queries-not-using-indexes

Can anyone suggest how I could rewrite this query to keep it out of the slow log? 谁能建议我如何重写此查询以使其脱离慢日志?

you can try something like this: 您可以尝试这样的事情:

SELECT 
    a.artist, 
    a.facepic,
    V.bid
FROM artists_vs AS v
inner join artists as a on v.artistid1 = a.artistid
WHERE v.genreid = 0 
union
SELECT 
    a.artist, 
    a.facepic,
    v.bid
FROM artists_vs AS v
inner join artists as a on v.artistid2 = a.artistid
WHERE v.genreid = 0 
ORDER BY bid DESC 
LIMIT 20

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM