假设表tableX 有 id(primary key) name ,age, phone, 都有索引
如果这样查询: select phone from tableX where name='Dennis' order by age
这个过程应该是
- 使用
nameindex 找到所有符合 Dennis 的 id ,记为集合 Set - 用
ageindex 给集合 Set 排序 - 用排序完的 id 去聚簇索引找到
phone
但第二步是怎么实现的呢?
我觉得有一种可能是直接在 age 的索引 b+树里面顺序扫描,看扫描到的 id 是不是在 Set 里面,如果是就加入到一个列表。那么这个列表里面就是按照 age 排序号的 id
但这样和顺序扫描有什么区别吗?为什么要用索引呢?