Postgresql 博士后覆盖指数12

Postgresql 博士后覆盖指数12,postgresql,optimization,indexing,Postgresql,Optimization,Indexing,我的表格有5500000条考试记录(Postgres 12)。 我有一个不确定性,因为当我在我的表上使用覆盖指数时,成本很大 因此,我创建索引: create index concurrently idx_log_type on logs (log_type) include (log_body); 执行请求后: explain (analyze) select log_body from logs where log_type = 1 limit 100; 我得到一个结果:

我的表格有5500000条考试记录(Postgres 12)。 我有一个不确定性,因为当我在我的表上使用覆盖指数时,成本很大

因此,我创建索引:

create index concurrently idx_log_type
    on logs (log_type)
    include (log_body);
执行请求后:

explain (analyze)
select log_body
from logs where log_type = 1
limit 100;
我得到一个结果:

Limit  (cost=0.43..5.05 rows=100 width=33) (actual time=0.118..0.138 rows=100 loops=1)
    - ->  Index Only Scan using idx_log_type on logs  (cost=0.43..125736.10 rows=2720667 width=33) (actual time=0.107..0.118 rows=100 loops=1)
        Index Cond: (log_type = 1)
        Heap Fetches: 0
Planning Time: 0.558 ms
Execution Time: 0.228 ms
乍一看,这是这么好,但成本范围非常大。
这是正常的还是应该优化?

这是
解释的产物:它显示了完整索引扫描的成本,就像没有
限制一样。但整个计划的定价是正确的


因此,您可以忽略索引扫描的高成本上限。

感谢您的澄清。我以前看过,不确定成本的上限。@laurenz albe,谢谢你的解释性评论