全栈开发
数据库
【Q345】postgres 中 Index Scan 与 Index Only Scan 有何区别

postgres 中 Index Scan 与 Index Only Scan 有何区别

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 348 (opens in a new tab)

Author 回答者: shfshanyue (opens in a new tab)

假设在 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