Fast find near users using PostGIS

爱⌒轻易说出口 提交于 2019-12-11 03:19:36

问题


I have 5 tables:

- users - information about user with current location_id (fk to geo_location_data)
- geo_location_data - information about location, with PostGIS geography(POINT, 4326) column
- user_friends - relationships between users.

I want to find near friends for current user, but it takes a lot of time of executing select query to know if user is a friend and after that execute select using ST_DWithin. May be something wrong in domain model or in queries?


回答1:


The first step is to index the geometry column. Something like this:

  CREATE INDEX geo_location_data_the_geom_idx ON geo_location_data USING GIST (the_geom);



回答2:


Try to use a buffer on your points and the the intersects operator.

SELECT ... FROM A, B WHERE Intersects(B.the_geom, ST_Buffer(A,1000))

It should be faster.



来源:https://stackoverflow.com/questions/2712447/fast-find-near-users-using-postgis

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