Select a.Circuit_Id,a.State_Name ,a.Status from tCircuit a
where a.Spec_Id = 3 and a.Service_Number is null---这句会使用Service_Number 上的索引
Select a.Circuit_Id,a.State_Name ,a.Status from tCircuit a
where a.Spec_Id = 3 and a.Service_Number is not null ----这句不会使用Service_Number上的索引,会使用表扫描
Select a.Circuit_Id,a.State_Name ,a.Status from tCircuit a
where a.Spec_Id = 3 and a.Service_Number is not null and a.Service_Number like 'LDC%' --这句会使用Service_Number 上的索引
以下例子中,C1列有索引,c2列无索引:
select t1.c1 from t1 where t1.c1 is null使用了c1的索引
select t1.c1,c2 from t1 where t1.c1 is null 使用了c1的索引
select t1.c1,c2 from t1 where t1.c1 is not null,使用表扫描
select t1.c1 from t1 where t1.c1 is not null 使用索引