title: Optimize a query (distance between 2 coordinates)
body: <p>I have a big DB of POI its now about 150K but will grow to ~1M</p>
  
  <p>I need to return all points within a certain radius of a point (lat, lon) 
  I have this query which worked great until the number of rows increased.
  also this query uses about 60% cpu and basically super slow</p>
  
  <pre><code>SELECT 
      *,
      (((acos(sin((57.757134*pi()/180)) * 
                      sin((coX*pi()/180))+cos((57.757134*pi()/180)) * 
                      cos((coX*pi()/180)) * cos(((37.616015- coY)* 
                      pi()/180))))*180/pi())*60*1.1515
                      ) as distance 
  FROM 
      places_en
  JOIN (   /* these are the query parameters */
        SELECT  
            57.757134  AS latpoint, 37.616015 AS longpoint,
            200 AS radius, 111.045 AS distance_unit) AS p
  WHERE 
       description != ''
       AND coX BETWEEN p.latpoint  - (p.radius / p.distance_unit)
                   AND p.latpoint  + (p.radius / p.distance_unit)
       AND coY BETWEEN p.longpoint - (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint))))
                   AND p.longpoint + (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint))))
  HAVING 
      distance &lt;= 200  
  ORDER BY 
      distance;
  </code></pre>
  
  <p>How can I make it better?</p>
  
  <p>Thanks</p>