小编gaq*_*qzi的帖子

当涉及 OR 时,Postgres 选择过滤器而不是索引 cond

我有一个表,每天都会添加大约 2000 万条记录,我试图对其进行分页,以便人们可以访问其中的所有数据,但查询时间必须“合适”(在我的例子中)定义为少于 30 秒/查询)。

为此,我过去一直使用键集分页,但对于这个特定的查询和表,我的查询时间非常慢,这似乎是因为查询规划器决定过滤掉一天的数据,然后对其运行过滤器而不是索引条件扫描。

该表如下所示:

create table mmsi_positions_archive
(
    id bigserial not null
        constraint mmsi_positions_archive_pkey
            primary key,
    position_id uuid,
    previous_id uuid,
    mmsi bigint not null,
    collection_type varchar not null,
    accuracy numeric,
    maneuver numeric,
    rate_of_turn numeric,
    status integer,
    speed numeric,
    course numeric,
    heading numeric,
    position geometry(Point,4326),
    timestamp timestamp with time zone not null,
    updated_at timestamp with time zone default now(),
    created_at timestamp with time zone default now()
);

create index ix_mmsi_positions_archive_mmsi
    on mmsi_positions_archive (mmsi);

create index ix_mmsi_positions_archive_position_id
    on mmsi_positions_archive …
Run Code Online (Sandbox Code Playgroud)

postgresql performance postgresql-9.6 postgresql-performance

7
推荐指数
1
解决办法
4270
查看次数