GeocodableBehavior icon indicating copy to clipboard operation
GeocodableBehavior copied to clipboard

Query cannot be optimized using index

Open janfabry opened this issue 13 years ago • 1 comments

The current filterByDistanceFrom can't use an index to speed up the query. Because of the trigonometry functions, every lat-lon pair has to be evaluated to find a possible match.

I think you can help the database by specifying the bounding box too (WHERE (lon > $west_limit AND lon < $east_limit AND lat > $south_limit AND lat < $north_limit) AND ABS([trig stuff here])). A semi-smart database can then use the index to prune out the rows that don't match the first part of the query, and only execute the trig functions for the remaining candidates.

janfabry avatar Aug 13 '12 17:08 janfabry

You're right, thanks for the tip!

willdurand avatar Aug 14 '12 08:08 willdurand