我有一个应用程序用户需要搜索的位置表。“保存”位于x英里范围内的位置“如何创建包含经度/纬度(使用GIST)的PostgreSQL索引,同时也是常规字段
我使用这样的查询:
select * from job_locations
where earth_box(ll_to_earth(51.5, -0.085), 5000) @> ll_to_earth(latitude, longitude)
and earth_distance(ll_to_earth(51.5, -0.085), ll_to_earth(latitude, longitude)) < 5000;
和索引这样的:
CREATE INDEX job_locations_lat_lng on job_locations USING gist(ll_to_earth(latitude, longitude));
然而,这是一个多租户系统,在这里所有的表有一个” tenant_id“字段,和我们总是过滤器也是如此。所以理想情况下,我可以在索引中同时拥有tenant_id和ll_to_earth(lat,lng),这应该可以使搜索速度更快。
这可能吗?我如何创建该索引?
谢谢!
丹尼尔
快速的问题,是'要点(ll_to_earth()'空间索引或者Postgres的一个通用指标? –