- 17
- 0
1、索引建立的字段date_point,corp_code,process_code
2、date_point 在 '2018-09-01' and '2018-10-17',走索引,在'2018-09-01' and '2018-10-18' 却没有走索引
针对第一条评论,补充统计的数据量(统计是否正确)
explain select `corp_code`, `process_code`, count(distinct business_code) as total from `tra_aging_distributions`
where `process_code` = 'BAO_DAN_SHOU_LI' and `org_code` in ('JIAO_Y I_ZU_ZHI')
and `corp_code` in ('FYGS8888', 'TJBK8888', 'LFBK8888', 'DLBK8888', 'NJBK8888', 'WXBK8888', 'HZBK8888', 'HNFD0001', 'WHABK8888', 'GZBK8888', 'XABK8888')
and (`product_type_code` = '10001')
and `date_point` between '2018-09-01' and '2018-10-17'
and `cost_days` > '2' and `cost_days` <= '3'
group by `corp_code`, `process_code`;
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|---|---|---|---|---|---|---|---|---|---|
| 1 | SIMPLE | tra_aging_distributions | range | idx_date_corp_process | idx_date_corp_process | 587 | NULL | 1852870 | Using index condition; Using where; Using filesort |
1 row in set (0.01 sec)
explain select `corp_code`, `process_code`, count(distinct business_code) as total from `tra_aging_distributions`
where `process_code` = 'BAO_DAN_SHOU_LI'
and `org_code` in ('JIAO_YI_ZU_ZHI')
and `corp_code` in ('FYGS8888', 'TJBK8888', 'LFBK8888', 'DLBK8888', 'NJBK8888', 'WXBK8888', 'HZBK8888', 'HNFD0001', 'WHABK8888', 'GZBK8888', 'XABK8888')
and (`product_type_code` = '10001')
and `date_point` between '2018-09-01' and '2018-10-18'
and `cost_days` > '2' and `cost_days` <= '3'
group by `corp_code`, `process_code`;
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|---|---|---|---|---|---|---|---|---|---|
| 1 | SIMPLE | tra_aging_distributions | ALL | idx_date_corp_process | NULL | NULL | NULL | 10540764 | Using where; Using filesort |
explain select `corp_code`, `process_code`, count(distinct business_code) as total from `tra_aging_distributions`
where `process_code` = 'BAO_DAN_SHOU_LI' and `org_code` in ('JIAO_Y I_ZU_ZHI')
and `corp_code` in ('FYGS8888', 'TJBK8888', 'LFBK8888', 'DLBK8888', 'NJBK8888', 'WXBK8888', 'HZBK8888', 'HNFD0001', 'WHABK8888', 'GZBK8888', 'XABK8888')
and (`product_type_code` = '10001')
and `date_point` between '2018-10-18' and '2018-10-18'
and `cost_days` > '2' and `cost_days` <= '3'
group by `corp_code`, `process_code`;
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|---|---|---|---|---|---|---|---|---|---|
| 1 | SIMPLE | tra_aging_distributions | range | idx_date_corp_process | idx_date_corp_process | 587 | NULL | 605 | Using index condition; Using where |
1 row in set (0.00 sec)
select (1852870+605)/10540764;
| (1852870+605)/10540764 |
|---|
| 0.1758 |
1 row in set (0.00 sec)
0
打赏
收藏
点击回答
- 共 0 条
- 全部回答
-
`兲倀地疚╮ 普通会员 1楼
在MySQL中,当你创建一个联合索引后,它会自动覆盖旧的索引,但是这个过程可能需要一段时间,取决于索引的大小和你的查询速度。
如果你的时间范围多出一天后,不在走索引,那么可能是因为你的查询速度比索引扫描的速度快。这意味着你的查询可能使用了索引,但索引可能还没有完全建立,或者索引被用于其他查询,而不是你现在的查询。
为了避免这种情况,你可以尝试以下几种方法:
-
如果你对查询速度有特定的需求,你可以尝试优化你的查询,例如减少你的查询次数,或者使用其他查询方法。
-
如果你的时间范围多出一天后,但是仍然不走索引,你可能需要重新考虑你的查询策略。例如,你可能需要考虑使用其他查询方法,或者在索引未建立之前就开始你的查询。
-
如果你的时间范围多出一天后,但是仍然不走索引,你可能需要考虑使用其他的存储引擎,例如InnoDB,它支持在未建立索引的情况下运行。
请注意,每个数据库系统都有其特定的特性,你可能需要根据你的具体情况进行调整。
-
更多回答
网站公告
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
