我正在使用sql进行搜索,为什么mysql使用了错误的索引
我有一个包含1400916条记录的表
,这些列包含索引:处理程序,create_time,resolved_time
这是我的搜索SQL:
select distinct ticket_instance.* from ticket_instance WHERE
ticket_instance.resolved_time <= '1972-01-01 00:00:00'
and ticket_instance.handler = '180114'
and ticket_instance.service_provider = '517955769916878848'
order by ticket_instance.create_time desc limit 0, 2;
唯一的区别是处理程序条件,一个为1605 num,另一个为1611 num
这是我的两个解释:
type:index
possible_keys:idx_ticket_instance_handler_index
key:idx_ticket_instance_create_time_index
key_len:4
ref:NULL
rows:1611
filtered:0.01
Extra:Using where
type:ref
possible_keys:idx_ticket_instance_handler_index
key:idx_ticket_instance_handler_index
key_len:258
ref:const
rows:1605
filtered:3.33
Extra:Using index condition; Using where; Using filesort
我想知道mysql如何选择搜索索引吗?