使用EXPLAIN命令查看慢查询时发现,有个int列在查询时未命中索引, 如图:
name = 0


Postgresql未使用索引问题
2019-10-07 at 1.47 PM.png

而如果查询改为 name = 1:


Postgresql未使用索引问题
2019-10-07 at 1.46 PM.png

这是因为
该表中name为0的行数大于70%(或某个具体数值),索引查询会比seq scan顺序扫描要慢,PostgreSQL优化器选择使用顺序扫描的方式。
数据分布较小(比如 1.7%),则用 bitmap index scan。数据更少的时候,用的是 index scan。

参考: http://mysql.taobao.org/monthly/2018/11/06/

相关文章:

  • 2022-02-22
  • 2021-08-10
  • 2021-09-02
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2021-06-27
猜你喜欢
  • 2021-08-31
  • 2022-12-23
  • 2021-11-14
  • 2022-02-16
  • 2022-12-23
相关资源
相似解决方案