I am a Mysql novice.
After deploying the PHP/Mysql code on my host, Site5, a strange pattern emerged.
When I'm using my web service, all queries are fast. But then, if no users have been using it for a few hours (I guess), the first query after that period is extremely slow - so slow it ends in a timeout.
The database is rather large. Here's the table in question.
Table B (madsted)
Format fixed
Collation utf8_general_ci
Rows 49,393
Row length ø 4,518
Row size ø 4,565 B
And the sql query:
$sql="SELECT navn1, lat, lon, postnr, virksomhedstype, branchekode, adresse1,
degrees(acos(
sin( radians(madsted.lat) )
* sin( radians(".$lat."))
+ cos( radians(madsted.lat))
* cos( radians(".$lat."))
* cos( radians(madsted.lon - ".$lon.") )
) ) * 69.09 * 1.609344 * 1000 as meterdistance
FROM madsted
WHERE degrees(acos(
sin( radians(madsted.lat) )
* sin( radians(".$lat."))
+ cos( radians(madsted.lat))
* cos( radians(".$lat."))
* cos( radians(madsted.lon - ".$lon.") )
) ) * 69.09 < (10 * 1.609344)
AND (
virksomhedstype = 'Detail'
)
AND (
branchekode <> '5552B'
and branchekode <> '5551A'
)
order by meterdistance limit 20;";