【发布时间】:2021-05-21 09:19:05
【问题描述】:
我的表有 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
乍一看,这很好,但成本范围非常大。 这是正常现象还是应该优化?
【问题讨论】:
标签: postgresql optimization indexing