title: Better way of finding results within the radius (Geo)
body: <p>I am using a query similar to:</p>
  
  <pre><code>$distance = "st_distance_sphere(Point({$lat}, {$lon}), Point({$lat}, {$lon})) * 0.000621371192";
  
  $query = "SELECT table.*, {$distance} as distance
  WHERE {$distance} &lt; 10 
     AND postcode IN ( 'XX12 3XX', 'XX12 3XX', 'XX12 3XX' )
  ORDER BY distance asc
  LIMIT 100";
  </code></pre>
  
  <p>The problem kicks in when postcodes contain 100k+ records, this is when the query will take considerable time to return results.</p>
  
  <p>Is there a way of speeding this query up?</p>
  
  <p>Some of the things that I was considering are:</p>
  
  <ol>
  <li>turning lat and long into a POINT data type. <a href="https://dev.mysql.com/doc/refman/5.7/en/spatial-type-overview.html" rel="nofollow noreferrer">https://dev.mysql.com/doc/refman/5.7/en/spatial-type-overview.html</a></li>
  <li>just like with point one but using Elastic Search <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-queries.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-queries.html</a></li>
  </ol>