相关疑难解决方法(0)

Postgres结合多个索引

我有以下表/索引 -

CREATE TABLE test
(
   coords geography(Point,4326), 
   user_id varchar(50), 
   created_at timestamp
);
CREATE INDEX ix_coords ON test USING GIST (coords);
CREATE INDEX ix_user_id ON test (user_id);
CREATE INDEX ix_created_at ON test (created_at DESC);
Run Code Online (Sandbox Code Playgroud)

这是我想要执行的查询:

select * 
from updates 
where ST_DWithin(coords, ST_MakePoint(-126.4, 45.32)::geography, 30000) 
and user_id='3212312' 
order by created_at desc
limit 60
Run Code Online (Sandbox Code Playgroud)

当我运行查询时,它只使用ix_coords索引.如何确保Postgres 对查询使用ix_user_id和ix_created_at索引?

这是一个新表,我在其中批量插入生产数据.在总排test表:15069489

我正在使用(effective_cache_size = 2GB)运行PostgreSQL 9.2.1(使用Postgis).这是我的本地OSX,具有16GB RAM,Core i7/2.5 GHz,非SSD磁盘.

添加EXPLAIN ANALYZE输出 -

Limit  (cost=71.64..71.65 rows=1 width=280) …
Run Code Online (Sandbox Code Playgroud)

postgresql postgis

5
推荐指数
1
解决办法
5562
查看次数

标签 统计

postgis ×1

postgresql ×1