我有一个查询在两个不同的mysql服务器实例中有不同的性能,两者都有明显相同的表和索引。这是查询:
select t.id, t.artist, t.title, count(*) from `raw_detection` r, tracks t where t.id = r.`track_id`
and r.duplicated = false
and (t.title = '' or t.title is null or t.artist = '' or t.artist is null)
group by 1,2,3
order by count(*) desc;
当我使用此查询执行explain
时,快速服务器会响应:
id s_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t index_merge PRIMARY,index_tracks_on_title,index_tracks_on_artist index_tracks_on_title,index_tracks_on_artist 602,602 NULL 11812 Using sort_union(index_tracks_on_title,index_tracks_on_artist); Using where; Using temporary; Using filesort
1 SIMPLE r ref index_raw_detection_on_duplicated_and_created_at,index_raw_detection_on_track_id index_raw_detection_on_track_id 4 playax.t.id 84 Using where
慢速服务器不同:
id s_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t ALL PRIMARY,index_tracks_on_title,index_tracks_on_artist NULL NULL NULL 177313 Using where; Using temporary; Using filesort
1 SIMPLE r ref index_raw_detection_on_duplicated_and_created_at,index_raw_detection_on_track_id index_raw_detection_on_track_id 4 playax.t.id 20 Using where
为什么会这样?