最近正在整理数据库中的索引,发现有两张表结构一样,所建立的索引都是
对于排序字段建立,但是一个索引被引用上了,另外一个却不能举例来说:
表a
(
a_id bigint primary key,
title varchar(50) not null
ref_time datetime
)
表b
(
b_id bigint primary key,
title varchar(50) not null
ref_time datetime
)现在对表a,b字段ref_time建立索引
create index IX_a_ref_time on a(ref_time desc)
create index IX_b_ref_time on b(ref_time desc)查询并且查看执行计划
select * from a order by ref_time desc
select * from b order by ref_time desc
执行计划结果:表a引用了索引,表b引用了索引进一步分析
对于表b进行强制索引引用
select * from b with(index(IX_b_ref_time)) order by ref_time desc
执行计划结果:
索引是引用上了,但是执行计划中却多了一个嵌套循环(Inner Join)开销真的是想不通,是不是因为加上触发器或者设置了默认值等原因,不知道对于
order by 字段加索引有什么条件之类的,望高人指教