我目前正在使用 PostgreSQL 14.0 for windows 我的目标表有 900k+ 行,我的查询使用单列过滤器 (status_id)。status_id 列通过 btree 索引(默认)当我执行“explain analyze select * from trip_detail where status_id = 5”时,查询计划器使用顺序扫描
Seq Scan on trip_detail (cost=0.00..69261.82 rows=912875 width=511) (actual time=1.404..457.886 rows=913420 loops=1)
Filter: (status_id = 5)
Rows Removed by Filter: 19320
Planning Time: 0.216 ms
Execution Time: 493.398 ms
如果我使用不同的值,它使用索引扫描
Index Scan using idx_tttdc_status_idh5 on trip_detail (cost=0.42..131.10 rows=1400 width=511) (actual time=106.692..138.531 rows=1515 loops=1)
Index Cond: (status_id = 12)
Planning Time: 0.236 ms
Execution Time: 138.764 ms
我已经清理、重建索引并分析了表和索引,但它仍然对大行组使用顺序扫描。什么可能导致这种问题?