为什么postgres选择索引扫描而不是索引寻求通过主键来获取一条记录?

时间:2019-07-19 07:22:06

标签: sql postgresql

我有下表:

create table documents 
(
     id serial not null primary key,
     key varchar(50) not null,
     document jsonb
);

它有超过1亿条记录,当我运行查询以通过主键获得1条记录时:

 select * from documents where id = 20304050

它使用索引扫描来获取它:

Index Scan using documents_pkey on documents (cost=0.57..8.59 rows=1 width=533) (actual time=0.010..0.011 rows=0 loops=1)
  Index Cond: (id = 20304050)
Planning Time: 0.070 ms
Execution Time: 0.024 ms

为什么postgres选择使用索引扫描而不是索引查找?

0 个答案:

没有答案
相关问题