【问题标题】:Understanding MySQL log_queries_not_using_indexes behavior了解 MySQL log_queries_not_using_indexes 行为
【发布时间】:2016-11-25 04:50:56
【问题描述】:

我想检查我的服务器的查询是否正确使用了索引。所以我启用了log_queries_not_using_indexes,并运行了测试用例。

我发现下面的查询写在mysql.slow_log表上。

SELECT * FROM user_rel 
WHERE (f = '5837be9dc34f747dbd7ba6c7' AND t = '5837be9dc34f747dbd7ba6ca') 
OR (f = '5837be9dc34f747dbd7ba6ca' AND t = '5837be9dc34f747dbd7ba6c7') 
LIMIT 2;

但我的EXPLAIN EXTENDED 结果似乎还可以。

# id, select_type, table, type, possible_keys, key, key_len, ref, rows, filtered, Extra
'1', 'SIMPLE', 'user_rel', 'range', 'f-t-UNIQUE,t_uid_idx', 'f-t-UNIQUE', '208', NULL, '2', '100.00', 'Using index condition'

请谁能解释一下为什么这个查询写成slow_log


编辑 1

这里是关于慢查询日志记录的 mysql 选项。

log_output  TABLE
log_queries_not_using_indexes   ON
long_query_time 2.000000
min_examined_row_limit  0
slow_query_log  ON
sql_log_off OFF

编辑 2

在我将min_examined_row_limit 更新为10 后,查询不再显示。但是为什么这会影响log_queries_not_using_indexes 结果呢?

【问题讨论】:

    标签: mysql performance mysql-slow-query-log


    【解决方案1】:

    嗯...闻起来像是另一个避免log_queries_not_using_indexes的理由。

    如果ft 是对称的:

    如果您在存储两列之前对它们进行“排序”,则查询该表的效率会更高。你不需要做OR,它可以更有效地使用明显的索引。

    【讨论】:

    • 所以你建议只为唯一的ft 对保留一行。我会按照你的建议尝试重构。谢谢。
    猜你喜欢
    • 2010-11-12
    • 1970-01-01
    • 2016-09-28
    • 2019-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-08
    相关资源
    最近更新 更多