gpt4 book ai didi

postgresql - 哪个邻近函数提供最快并利用 postGIS 中的空间索引?

转载 作者:行者123 更新时间:2023-11-29 12:14:27 24 4
gpt4 key购买 nike

我是 PostgreSQL/PostGIS 的新手。我正在评估它以解决一个简单的算法:尝试找到半径(米)内的所有点。这是我的 table :

=> \d+ theuser;
Table "public.theuser"
Column | Type | Modifiers | Storage | Description
----------+------------------------+-----------+----------+-------------
id | bigint | not null | plain |
point | geometry | | main |
Indexes:
"theuser_pkey" PRIMARY KEY, btree (id)
"point_index" gist (point)
Referenced by:
...
Has OIDs: no

我在 point 列中添加了一个 gist 索引,我不知道这样的设计是否正确。插入的所有“点”都带有 SRID=4326

似乎有两种方法可以获取附近的点:

ST_Distance , ST_Distance_Sphere .取2例如:

select * from theuser where
ST_distance_sphere(point , ST_GeomFromText('POINT(120.9982 24.788)',4326)) < 100;

我想知道哪种算法使用了“point_index”?如果有数百万个点,两者都执行得非常快吗?

另一个问题,如何查询一个单元格的SRID(我搜索了没有找到答案)?我所能做的就是通过 hibernate-spatial-postgis 获取 "com.vividsolutions.jts.geom.Point",并从返回的点获取 SRID。我如何在 SQL 中查询它?谢谢。

环境:

=> select version();
version
-----------------------------------------------------------------------------------------------------------
PostgreSQL 8.4.9 on i486-pc-linux-gnu, compiled by GCC gcc-4.4.real (Ubuntu 4.4.3-4ubuntu5) 4.4.3, 32-bit

=> SELECT postgis_lib_version();
postgis_lib_version
---------------------
1.4.0

----更新----

谢谢@filiprem,我试过了:

=> explain select * from theuser where
ST_distance_sphere(point , ST_GeomFromText('POINT(120.9982 24.788)',4326)) < 100;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
Seq Scan on theuser (cost=0.00..1.15 rows=3 width=2644)
Filter: (st_distance_sphere(point, '0101000020E610000080B74082E23F5E407D3F355EBAC93840'::geometry) < 100::double precision)
(2 rows)

我怎么知道它是否使用了 "point_index"gist (point) ?在大数据量搜索下能否生存?

最佳答案

我曾经听说 ST_DWithin 是最快的,实际上在 documentation 中他们说在较新的版本中 ST_DWithin 已被调整。

Prior to 1.3, ST_Expand was commonly used in conjunction with && and ST_Distance to achieve the same effect and in pre-1.3.4 this function was basically short-hand for that construct. From 1.3.4, ST_DWithin uses a more short-circuit distance function which should make it more efficient than prior versions for larger buffer regions.

它还使用边界框比较和索引:

This function call will automatically include a bounding box comparison that will make use of any indexes that are available on the geometries.

关于postgresql - 哪个邻近函数提供最快并利用 postGIS 中的空间索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8428875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com