title: How to optimize SQL query with calculating distance by longitude and latitude?
body: <p>I have a table with structure like that:</p>
  
  <pre><code>table name: shop
  
  id_shop      int(10)
  name         varchar(200)
  latitude     double
  longitude    double
  </code></pre>
  
  <p>And I'd like to calculate distance between given coordinates and coordinates saved in database.</p>
  
  <p>My current query:</p>
  
  <pre><code>SELECT *
    FROM `shop` AS `s`
   WHERE
        (
          ( 6371
          * ACOS(
              SIN( RADIANS( latitude ) )
            * SIN( RADIANS( 53.5353010379 ) )
            + COS( RADIANS( latitude ) )
            * COS( RADIANS( 53.5353010379 ) )
            * COS( RADIANS( 14.7984442616 ) - RADIANS( longitude ) )
            )
          )
          &lt;= 25
        )
  </code></pre>
  
  <p>plus some <code>JOIN LEFT</code>'s for some data.</p>
  
  <p>Is there any way to optimize that query ?
  With joins it takes about 13msec.</p>
  
  <p>I need to add here also some <code>LIMIT</code> and <code>COUNT(*)</code> for total amount of shops for pagination.</p>