Hi, I would really like any suggestions on the following concerning performance…:
I have 1.000.000 locations with:
a name
a latitude
a longitude
a score
I want to:
select all locations on a particular (google)map. So a latitude BETWEEN (… AND …) AND longitude BETWEEN (… AND …)
fulltext match name. So name MATCHES (…)
ORDER BY score
How would I get the best performance? What indexes should I create? Should I split the data in two tables and then JOIN? Or should I put everything together in one table?
1Million is not too much, depending on your traffic of course, you might simply be able to use MySQL Full Text Search plus extra filtering by distance.
If there are a lot of matches and they are filtered by distance match you’re stuck however.
Sphinx could be patched to do what you need to do really fast.
I did not know of Sphynx… it seems as a good (extra) solution to my problem.
I want to do something similar to the search on yelp.com or as is specified here.
At this time I’m using MySQL 4.1 and the following query:
SELECT SQL_CALC_FOUND_ROWS entries.*
FROM entries
JOIN geolocations ON (entries.id = geolocations.entry_id)
WHERE
( geolocations.wgs84_lat BETWEEN 55.9920055076675 AND 57.0005291105997 ) AND
( geolocations.wgs84_lon BETWEEN 3.55064105987549 AND 3.57124042510986 ) AND
MATCH (name) AGAINST (‘+name*’ IN BOOLEAN MODE)
ORDER BY score DESC
LIMIT 0, 8;
I also tried putting lat and lng in the entries table…but that was not helping very much…
Great forum BTW! Seems to be much more active than the original MySQL forum…