2010-04-26 22 views
2

我有5個表:快速找到附近的用戶使用的PostGIS

- 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. 

我要查找當前用戶附近的朋友,但它需要大量的執行SELECT查詢的時間知道用戶是朋友,之後執行選擇使用ST_DWithin。在域模型或查詢中可能有問題?

+1

請問你現在正在使用的查詢嗎? – Quassnoi 2010-04-26 09:58:42

回答

1

第一步是索引幾何列。類似這樣的:

CREATE INDEX geo_location_data_the_geom_idx ON geo_location_data USING GIST (the_geom); 
0

嘗試在你的點和相交運算符上使用一個緩衝區。

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

它應該更快。