shfshanyue / Daily-Question

互联网大厂内推及大厂面经整理,并且每天一道面试题推送。每天五分钟,半年大厂中
https://q.shanyue.tech
4.92k stars 510 forks source link

【Q345】postgres 中 Index Scan 与 Index Only Scan 有何区别 #348

Open shfshanyue opened 4 years ago

shfshanyue commented 4 years ago

假设在 user 表简历索引 (name, age)

Index Scan 指查询中除利用索引外还有额外的查询条件,如 (name, age) 是索引,但是 sex 不是

select * from user where name = '张三' and age = 10 and sex = 'MALE'

Index Only Scan 指查询中可以全部利用索引,如 (name, age) 都是索引

select * from user where name = '张三' and age = 10