小编yan*_*kee的帖子

当索引扫描会更好时,为什么 PostgreSQL 选择慢速 Seq 扫描?

我在 Postgres 9.6 DB 中有以下表格:

create table baseDimensions(
    id serial not null primary key,
    dimension1 date not null,
    dimension2 int not null,
    dimension3 text not null,
    -- ...
    dimension10 boolean not null,
    unique(dimension1, dimension2, ..., dimension10)
);

create table interestingData(
    baseDimensionId int not null references baseDimensions(id),
    subdimension1 int not null,
    subdimension2 boolean not null,
    -- ...
    value1 int not null,
    value2 bigint not null,
    -- ...
    primary key(baseDimensionId, subdimension1, subdimension2)
)
Run Code Online (Sandbox Code Playgroud)

所以在文本中:我有很多维度(例如,如果表格用于零售店的销售,则维度可以是销售日期、customerId、客户是否是重复客户、客户的夹克颜色穿着等)以及这些尺寸的一些值(例如,保持零售示例:值可以是客户支付的金额)。然而,有多个“interestingData”表共享十个基本维度,因此为了节省一些磁盘空间,我将这些基本维度提取到一个单独的表中。

我特意选择了唯一索引中列的顺序,以便典型的过滤条件在最左边。所以大部分时间我会按维度1过滤数据。

现在我想知道value1特定日期的平均值(dimension1每个dimension3)。这可以通过以下查询来回答: …

postgresql performance optimization postgresql-9.6 query-performance

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