我有下表:
create table documents
(
id serial not null primary key,
key varchar(50) not null,
document jsonb
);
Run Code Online (Sandbox Code Playgroud)
它有超过 1 亿条记录,当我运行查询以通过主键获取 1 条记录时:
select * from documents where id = 20304050
Run Code Online (Sandbox Code Playgroud)
它使用索引扫描来获取它:
create table documents
(
id serial not null primary key,
key varchar(50) not null,
document jsonb
);
Run Code Online (Sandbox Code Playgroud)
为什么 Postgres 选择使用索引扫描而不是索引查找?
编辑:我来自 SQL Server 世界,它是索引扫描和索引查找之间的区别。在 Postgres 中,没有索引查找这样的东西。
小智 12
这个问题已经在评论中得到了解答。postgres 中的 \xe2\x80\x9eIndex scan\xe2\x80\x9c 是查询规划器的正确方法: \xe2\x80\x9eI\xe2\x80\x98m 使用索引查找行\xe2\ x80\x9c。postgres中没有\xe2\x80\x9eindexeek\xe2\x80\x9c的概念。
\n| 归档时间: |
|
| 查看次数: |
980 次 |
| 最近记录: |