mysql - mariadb explain filter=100 即使选择了正确的索引
问题描述
我试图弄清楚为什么我在一个非常简单的查询中得到了可怕的性能:
解释从“2019-03-10 02:15:00”到“2019-03-10 02:20:00”之间的call_details_raw
选择计数(*)PNBLSTimeOn
+------+-------------+------------------+-------+---------------+-------------+---------+------+---------+----------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+------------------+-------+---------------+-------------+---------+------+---------+----------+--------------------------+
| 1 | SIMPLE | call_details_raw | index | PNBLSTimeOn | PNBLSTimeOn | 5 | NULL | 7566362 | 100.00 | Using where; Using index |
+------+-------------+------------------+-------+---------------+-------------+---------+------+---------+----------+--------------------------+
mysql花了很长时间才告诉我结果为0:
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (4.68 sec)
它说它使用了正确的索引,但是 filter=100 这意味着它无论如何都在分析表中的每一行。
如果有帮助,这是完整的表定义:
CREATE TABLE `call_details_raw` (
`call_id` int(11) NOT NULL AUTO_INCREMENT,
`PNBLSPrimaryCSN` char(16) COLLATE utf8_bin DEFAULT NULL,
`PNBLSBillingAccount` char(16) COLLATE utf8_bin DEFAULT NULL,
`PNBLSMainAccount` char(16) COLLATE utf8_bin DEFAULT NULL,
`PNBLSXferAccount` char(16) COLLATE utf8_bin DEFAULT NULL,
`PNBLSTimeOn` timestamp NULL DEFAULT NULL,
`PNBLSTimeOff` timestamp NULL DEFAULT NULL,
`PNBLSNumberDialed` char(20) COLLATE utf8_bin DEFAULT NULL,
`PNBLSANI` char(20) COLLATE utf8_bin DEFAULT NULL,
`PNBLSTotalTime` int(11) DEFAULT NULL,
`PNBLSRingTime` decimal(11,1) DEFAULT NULL,
`PNBLSHoldTime` int(11) DEFAULT NULL,
`PNBLSQueueTime` int(11) DEFAULT NULL,
`PNBLSInboundTime` int(11) DEFAULT NULL,
`PNBLSInboundCall` int(11) DEFAULT NULL,
`PNBLSOutboundTime` int(11) DEFAULT NULL,
`PNBLSOutboundCall` int(11) DEFAULT NULL,
`PNBLSCheckinTime` int(11) DEFAULT NULL,
`PNBLSCheckinCall` int(11) DEFAULT NULL,
`PNBLSVMTime` int(11) DEFAULT NULL,
`PNBLSVMCall` int(11) DEFAULT NULL,
`PNBLSPagerTime` int(11) DEFAULT NULL,
`PNBLSPagercall` int(11) DEFAULT NULL,
`PNBLSConfTime` int(11) DEFAULT NULL,
`PNBLSConfCall` int(11) DEFAULT NULL,
`PNBLSConfParties` int(11) DEFAULT NULL,
`PNBLSConfSetupTime` int(11) DEFAULT NULL,
`PNBLSAppDialouts` int(11) DEFAULT NULL,
`PNBLSAlphaPages` int(11) DEFAULT NULL,
`PNBLSFaxes` int(11) DEFAULT NULL,
`PNBLSEmails` int(11) DEFAULT NULL,
`PNBLSMsgsSaved` int(11) DEFAULT NULL,
`PNBLSNoMsgs` int(11) DEFAULT NULL,
`PNBLSWorkTime` int(11) DEFAULT NULL,
`PNBLSMLTime` int(11) DEFAULT NULL,
`PNBLSLiveRecTime` int(11) DEFAULT NULL,
`PNBLSLiveRecCall` int(11) DEFAULT NULL,
`PNBLSSATime` int(11) DEFAULT NULL,
`PNBLSInEmails` int(11) DEFAULT NULL,
`PNBLSConfSetups` int(11) DEFAULT NULL,
`PNBLSAgentConfTime` int(11) DEFAULT NULL,
`PNBLSParkTime` int(11) DEFAULT NULL,
`PNBLSFlashOverTrunk` int(11) DEFAULT NULL,
`PNBLSAutoDigCalls` int(11) DEFAULT NULL,
`PNBLSAutoDigTime` int(11) DEFAULT NULL,
`PNBLSMsgTime` int(11) DEFAULT NULL,
`PNBLSMsgEditTime` int(11) DEFAULT NULL,
`PNBLSMsgTimeSusp` int(11) DEFAULT NULL,
`PNBLSMsgEditTimeSusp` int(11) DEFAULT NULL,
`PNBLSWorkTimeSusp` int(11) DEFAULT NULL,
`PNBLSMsgListSusp` int(11) DEFAULT NULL,
`PNBLSSATimeSusp` int(11) DEFAULT NULL,
`PNBLSPreAnnounceCall` int(11) DEFAULT NULL,
`PNBLSPreAnnounceTime` int(11) DEFAULT NULL,
`PNBLSAbandonedCall` int(11) DEFAULT NULL,
`PNBLSWrapTime` int(11) DEFAULT NULL,
`PNBLSLastAgent` char(16) COLLATE utf8_bin DEFAULT NULL,
`PNBLSLastAgentName` varchar(30) COLLATE utf8_bin DEFAULT NULL,
`PNBLSLocates` int(11) DEFAULT NULL,
`PNBLSLocateTime` int(11) DEFAULT NULL,
`PNBLSSMSIn` int(11) DEFAULT NULL,
`PNBLSSMSOut` int(11) DEFAULT NULL,
`PNBLSPF2Fax` int(11) DEFAULT NULL,
`PNBLSPF2FaxTime` int(11) DEFAULT NULL,
`PNBLSPF2FaxPages` int(11) DEFAULT NULL,
`PNBLSPPSPage` int(11) DEFAULT NULL,
`PNBLSPPSPageTime` int(11) DEFAULT NULL,
`PNBLSQueueDrop` int(11) DEFAULT NULL,
`PNBLSPreAnnDrop` int(11) DEFAULT NULL,
`PNBLSMsgInsAPI` int(11) DEFAULT NULL,
`PNBLSOrderNum` char(16) COLLATE utf8_bin DEFAULT NULL,
`PNBLSSecMsgIn` int(11) DEFAULT NULL,
`PNBLSSecMsgOut` int(11) DEFAULT NULL,
`PNBLSSecMsgRead` int(11) DEFAULT NULL,
PRIMARY KEY (`call_id`),
KEY `PNBLSTimeOn` (`PNBLSTimeOn`),
KEY `PNBLSTimeOff` (`PNBLSTimeOff`),
KEY `PNBLSInboundCall` (`PNBLSInboundCall`),
KEY `PNBLSLastAgent` (`PNBLSLastAgent`)
) ENGINE=InnoDB AUTO_INCREMENT=7994796 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
select @@version;
10.1.30-MariaDB
解决方案
我不知道这些是否相关;它们来自变更日志:
----- 2017-05-23 MariaDB 10.2.6 -- -- -----
错误 #23046302 计数(*)在 5.7 上比 5.6 慢得多
----- 2017-04-10 5.7.18 通用可用性 -- 已修复的错误 -- InnoDB -----
由于 MySQL 5.7.2 中引入的修改导致 InnoDB 通过遍历聚集索引而不是较小的二级索引来计算行数,SELECT COUNT(*) 性能在某些情况下会下降。修改已恢复。(错误 #23046302、错误 #80580)
----- 2017-04-10 5.7.18 通用可用性 -- 已修复的错误 -- -----
由于 MySQL 5.7.2 中引入的修改导致 InnoDB 通过遍历聚集索引而不是较小的二级索引来计算行数,EXPLAIN SELECT COUNT(*) FROM tbl_name 可能会错误地报告 Select tables 优化后的额外值。额外值现在显示计数行。(错误 #24337385,错误 #82313)
推荐阅读
- c++ - C++动态拆分线程工作的例程
- python - Pandas 层次索引:基于二级索引值合并/连接行
- java - Java 8 编码标准和在运行时检测激活的编码
- http - HTTP 200 响应是否意味着必须有响应主体?
- flutter - Flutter - 将行的大小减小到必要的空间
- android - Recyclerview 数据在未指定的情况下被更改
- java - 媒体播放器 - Android Studio
- python - 我不可能用 GeForce GTX 770 获得 tensorflow 2 gpu
- charts - 多个承包商在 CI/CD 管道中使用伞形图
- excel - Excel - 组合工作表以形成数据透视表