mysql - 如何将此类查询排除在 mysql_slow.log 之外?

标签 mysql mysql-management mysqldumpslow

我有以下查询需要帮助。

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

查询中的所有字段都已建立索引,但是当我运行解释时,我得到以下结果:

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)

我需要在 my.cnf 中启用 log-queries-not-using-indexes

任何人都可以建议我如何重写此查询以使其远离慢速日志吗?

最佳答案

你可以尝试这样的事情:

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

关于mysql - 如何将此类查询排除在 mysql_slow.log 之外?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4764191/

相关文章:

mysql - SQL 查询从一个表中选择不在另一表中的行

python - 在 mysql 中存储倒排索引

mysql - 如何分析MySQL Slow Query Log或MySQL General Query Log?

Mysqldump 花费太多时间

mysql - 限制密码的字符数?

mysql - 用于 Mysql 的 Ole 数据库连接器

macos - 使用 phpMyAdmin 的替代方法有哪些?

mysql - 如何在mysql中快速读取数据和写入数据?

MYSQL 临时表 - 如何查看事件表