i have a table of resumes – names, resume text, zipcode, firstname, lastname, longitude, latitude, zip … 500,000+ rows
i query it too ways:
by location, example:
1) SELECT * FROM resumes
WHERE ((latitude BETWEEN 44.3523845787 AND 45.6809474213)
AND (longitude BETWEEN -110.873064254 AND -108.993603746))
GROUP BY lastname,longitude
LIMIT 0, 50
by name
2) SELECT * from resumes
(MATCH(resume) AGAINST ('donald')) AS relevance
FROM resumes
WHERE (MATCH(resume) AGAINST ('donald'))
GROUP BY lastname,longitude
ORDER BY relevance DESC
LIMIT 0, 50
queries on this table are very slow at first, but same query afterwards is faster, i think it’s caching it …
how can i speed up these queries? thanks
This one can make little use of btree indexes. At best, it would grab all locations that fit for the latitude, or the longitude, and investigate potential rows along the other dimension. What you want is for it to only investigate rows that fit in a smaller box.
For this, you need a spacial index.
Likewise, this also needs a special kind of index which is not btree — a full text index to be specific.