使用PostGIS快速查找附近的用户

发布于 2024-08-29 22:06:41 字数 364 浏览 3 评论 0原文

我有 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 执行选择。领域模型或查询中可能有问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ双果 2024-09-05 22:06:41

第一步是索引几何列。像这样的东西:

  CREATE INDEX geo_location_data_the_geom_idx ON geo_location_data USING GIST (the_geom);

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);
小猫一只 2024-09-05 22:06:41

尝试在您的点和相交运算符上使用缓冲区。

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

应该会更快。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文