I have a query like this :
SELECT *, (
6371 * acos (
cos ( radians(33.577718) )
* cos( radians( `Latitude` ) )
* cos( radians( `Longitude` ) - radians(115.846524) )
+ sin ( radians(33.577718) )
* sin( radians( `Latitude` ) )
)
) AS `distance`
FROM `geopc_cn_places_grouped`
WHERE `Latitude`!=33.577718 AND `Longitude`!=115.846524
HAVING `distance` < 200
ORDER BY `distance` ASC
LIMIT 30;
The query execution is always somewhere between 3.5 and 4 seconds.
I have applied a composite index to Latitude
and Longitude
by running ALTER TABLE geopc_cn_places_grouped ADD INDEX index_Longitude_Latitude(Longitude, Latitude);
, but it doesn't reduce the execution time.
I want to know why it's running slow and what possible optimizations can be done.
The slow query log message shows this
and this is the EXPLAIN SELECT
query
Table Structure...
and lastly, here is the table index list