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)