PostgreSQL 简单 select 不在大 table 上使用索引

PostgreSQL simple select not using index on big table

我有一个 table "accounting_line" 大约有 304771383 行

然后运行一个select到return单行:

select integervalue from accounting_line
where accounting_line.accounting_id = 2124651 and accounting_line.type_id = 13;

我在列(accounting_id、type_id)上有一个索引,但未使用索引... 查询非常慢,大约需要 2 分钟。 请任何帮助。 select单行应该很快吧?

这里是select的解释分析:

Gather  (cost=1000.00..3847029.00 rows=38 width=4) (actual time=91410.660..110394.859 rows=1 loops=1)
Workers Planned: 2
Workers Launched: 2
->  Parallel Seq Scan on accounting_line  (cost=0.00..3846025.20 rows=16 width=4) (actual time=104060.824..110387.831 rows=0 loops=3)
    Filter: ((accounting_id = 2124651) AND (type_id = 13))
    Rows Removed by Filter: 101590461
Planning time: 0.124 ms
Execution time: 110394.883 ms

这里是 table DDL:

create table accounting_line
(
    id serial not null constraint accounting_line_pk primary key,
    accounting_id integer constraint fkio32oufjgdbf586bpr58j892d references accounting,
    type_id smallint constraint fknx7ej42yfoxdicpo8yhat8gto references accounting_type,
    doublevalue real,
    integervalue integer,
    percentage boolean default false not null
)
;

alter table accounting_line owner to orgdb
;

create index accounting_line_accounting_id_type_id_index
    on accounting_line (accounting_id, type_id)
;

虽然在 accounting_line 上分析什么也没做,但在清理、分析和重新索引所有内容后,它又开始工作了