mysql - 为什么额外的是 "using where;using index"而不是 "using index"

标签 mysql query-optimization

为什么额外的是“使用where;使用索引”而不是“使用索引”。

       CREATE TABLE `pre_count` (                
         `count_id` varchar(38) NOT NULL,        
         `cam_id` varchar(38) NOT NULL,       
         `count_time` datetime NOT NULL,         
         PRIMARY KEY (`cam_id`,`count_time`)  
       ) ENGINE=InnoDB DEFAULT CHARSET=utf8      

解释从 pre_count 中选择 count_time,其中 cam_id = '56849645645645646'

结果:

1   SIMPLE  pre_count   ref PRIMARY PRIMARY 116 const   1   Using where; Using index

最佳答案

这只是意味着 WHERE 子句中的条件将用于限制查询返回的行。如果您的 EXPLAIN extra 中没有“Using where”,那么查询将不会限制行。

手册上的意思是:https://dev.mysql.com/doc/refman/8.0/en/explain-output.html#explain-extra-information

A WHERE clause is used to restrict which rows to match against the next table or send to the client. Unless you specifically intend to fetch or examine all rows from the table, you may have something wrong in your query if the Extra value is not Using where and the table join type is ALL or index.

我可以发誓,我见过 EXPLAIN 报告中缺少“Using where”的情况,即使查询确实使用了索引并限制了返回的行。

我被迫得出结论,对于所有类型的行限制,“Using where”都没有可靠地报告。

其他人注意到“Using where”的含义令人困惑或不一致:https://bugs.mysql.com/bug.php?id=30733

关于mysql - 为什么额外的是 "using where;using index"而不是 "using index",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56615824/

相关文章:

mysql - 404 if record not found - 如何检查记录是否存在?

mysql - 考虑到某些数据可以重叠,计算受限于某些数据的范围内的天数

php - mysql 距离查询在 laravel 下不起作用

sql - 优化长时间运行的 SQL Server 查询

mysql - 使用内部子查询优化此 MySQL 查询

php - 按成本对数据库记录进行排序,但好像成本每天增加 1p?

MYSQL使用外键对现有表进行分区

SQL ROW_NUMBER() 性能问题

mysql - MYSQL中的LIMIT使用全索引扫描而不是范围扫描

Mysql - 解释键为空