How can I avoid a full table scan on this mysql query?

后端 未结 4 2153
忘掉有多难
忘掉有多难 2021-02-15 13:00
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.z         


        
4条回答
  •  时光取名叫无心
    2021-02-15 13:46

    You could use a subquery:

    select * from zipcode_distances z, venues v, events e
    where
        z.id in (select id from zipcode z where z.zipcode_from='92108' and z.distance <= 5)
        and z.zipcode_to=v.zipcode
        and v.id=e.venue_id
    

提交回复
热议问题