how to optimize a geolocation database in mysql for euclidean distance search/query

ⅰ亾dé卋堺 提交于 2019-12-11 03:49:20

问题


i am using mysql to store geolocation data. i would like to know how to optimize the table holding the (x,y) coordinates so that queries will be optimized against it. (the x,y will be lat/long).

for example, i have a table with the following fields: id, x, y, notes.

at sometime later, i will perform a query: select * from geoloc where sqrt( (x-@x)^2 + (y-@y)^2 ) < delta

please note, i have no idea how the actual SQL statement will work right now, so the above is just a very rough idea of what i want.

so what do i have to do to optimize this table for this type of query? any pointers are greatly appreciated.


回答1:


You'll have a hard time optimizing for that kind of query. A better option would be to compute a bounding box from the (x,y) coordinates and delta passed in. Then query for any locations where the coordinates fall in that box. That query would be much simpler and would be able to use any indexes you might have on the x and y fields.

Of course the results from that query aren't as exact since it's a bounding box rather than a circle. If you want better results, you can take the results from the bounding box query, then use the slower euclidean method to filter out the ones that don't fall into the circle.




回答2:


Maybe you could try Voronoi diagrams. Take a look here http://www.cs.sunysb.edu/~algorith/files/nearest-neighbor.shtml



来源:https://stackoverflow.com/questions/5749209/how-to-optimize-a-geolocation-database-in-mysql-for-euclidean-distance-search-qu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!