explain
select
*
from
zipcode_distances z
inner join
venues v
on z.zipcode_to=v.zipcode
inner join
events e
on v.id=e.venue_id
where
z.zipcode_from='92108' and
z.distance <= 5
我试图找到所有“在5英里的邮政编码92108以内的场地的活动”,但是,我很难优化此查询。如何避免在此mysql查询上进行全表扫描?
这是什么解释的样子:
id, select_type, table, type, possible_keys, key, key_len, ref, rows, Extra
1, SIMPLE, e, ALL, idx_venue_id, , , , 60024,
1, SIMPLE, v, eq_ref, PRIMARY,idx_zipcode, PRIMARY, 4, comedyworld.e.venue_id, 1,
1, SIMPLE, z, ref, idx_zip_from_distance,idx_zip_to_distance,idx_zip_from_to, idx_zip_from_to, 30, const,comedyworld.v.zipcode, 1, Using where; Using index
我得到的“E”表进行全表扫描,我想不出我需要创建得到它什么指数要快。
任何意见,将不胜感激
谢谢
您是否需要结果集中所有表的所有列? –
我试图避免使用“in”子查询。 – john
我想要做的事情的俗语说明是找到邮政编码驻留在邮政编码中的场所,我发现邮政编码靠近92108.因此,它加入场地,然后加入与该场地相关的活动。 – john