Anthony Ward wrote:

SELECT userid FROM place WHERE acos( cos($longitude) * cos($latitude) *
cos(place.latitude) *cos(place.longitude) +cos($longitude) * sin($latitude)
* cos(place.latitude) * sin(place.longitude) +sin($longitude) *
sin($latitude) ) * 3963 <= 1000);

Would you consider this HORRIBLY inefficient or GOOD.
if it is horrible how can i make it efficient?


If it runs quickly enough for your purposes (I can't tell without
knowing what your speed requirement, or at least the number of rows in
your place table is), then it's good.  If it's way too slow, then it's
horribly inefficient.

In your query, the mysql optimizer has no way of using any indexes you
may have on longitude and latitude.  So, if you have a large number of
rows to sift through, it will not run quickly.  To help it out, work out
maximum bounding conditions on latitude and longitude in terms of
$latitude and $longitude separately, and AND them into your WHERE.  My
trig is too rusty to do this, unfortunately.  Anyway, if latitude and
longitude are indexed (or at least one or the other), doing so ought to
allow the optimizer to narrow down the places which must be scanned
dramatically.

Bruce Feist





--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to