我有5张桌子:
- 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.
我想为当前用户找到附近的朋友,但是执行选择查询需要花费大量时间来了解用户是否是朋友,之后使用ST_DWithin
执行select。在域模型或查询中可能有问题吗?
答案 0 :(得分:1)
第一步是索引几何列。像这样:
CREATE INDEX geo_location_data_the_geom_idx ON geo_location_data USING GIST (the_geom);
答案 1 :(得分:0)
尝试在点和交叉运算符上使用缓冲区。
SELECT ... FROM A, B WHERE Intersects(B.the_geom, ST_Buffer(A,1000))
应该更快。