I'm trying to get 100 points from my table with a lowest distance to a given point.
I'm using
SELECT *, GLENGTH(
LINESTRINGFROMWKB(
LINESTRING(
ASBINARY(
POINTFROMTEXT("POINT(40.4495 -79.988)")
),
ASBINARY(pt)
)
)
)
AS `distance` FROM `ip_group_city` ORDER BY distance LIMIT 100
(Yeah, that's painful. I've just googled it. I have no idea how to measure distance in MySQL correctly)
It takes very long time for execute. EXPLAIN
says that there are no possible_keys
.
I created a SPATIAL
index on the pt
column:
CREATE SPATIAL INDEX sp_index ON ip_group_city (pt);
Though I don't really know how to use it correctly. Can you please help me?