mysql什么时候使用联合索引,mysql建立联合索引,但是时间范围多出一天后,不在走索引...

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值