Topic awaiting preservation: improving speed of mysql distance filter (Page 1 of 1) |
|
---|---|
Nervous Wreck (II) Inmate From: Careywood, Idaho, USA |
posted 05-18-2006 20:39
Hello! code: SELECT {fields}, SQRT( (69.1 * ('48.055621' - a.lat)) * (69.1 * ('48.055621' - a.lat)) + (53.0 *('-116.585400' - a.lon)) * (53.0 *('-116.585400' - a.lon))) as distance FROM {tables} WHERE {criteria} HAVING distance < '{distance}' ORDER BY distance ASC
code: WHERE a.lat > a.lat - '{X}' AND a.lat < a.lat + '{X}' a.lon > a.lon - '{X}' AND a.lon < a.lon + '{X}' {criteria}
|
Maniac (V) Inmate From: Sthlm, Sweden |
posted 05-18-2006 21:42
check the FAQ: http://www.ozoneasylum.com/21781 |
Nervous Wreck (II) Inmate From: Careywood, Idaho, USA |
posted 05-18-2006 23:14
DmS: |
Maniac (V) Inmate From: Sthlm, Sweden |
posted 05-19-2006 22:31
Well, not being an sql-guru myself I can't really judge the query. |
Nervous Wreck (II) Inmate From: Careywood, Idaho, USA |
posted 05-20-2006 00:44
Thanks! |
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 05-20-2006 17:56
also, I suggest you read up on mysql->explain and then do an explain your_query, to see if there's something that mysql itself suggests to speed your query up. |
Nervous Wreck (II) Inmate From: Careywood, Idaho, USA |
posted 05-25-2006 02:42
Still no replies to my thread at http://forums.mysql.com/read.php?115,91048. |
Paranoid (IV) Inmate From: Madison, Indiana, USA |
posted 05-25-2006 18:01
I would store the results of each request in a column of the record. That way you can check the result column to see if it is empty and then do the calculation. If the calculation has already been done once, return the result. This means the request will be slow only the first time you make a request for a given zip-code. |