create table #T
(id int identity(1,1) primary key,userid varchar(20))
insert into #T select 'aa'
insert into #T select 'bb'
insert into #T select 'cc'
insert into #T select 'dd'
insert into #T select 'ee'
insert into #T select 'ff'
--set showplan_all on
select * from #T where id not in (3)
从执行计划上看,MSSQL将此句优化成:
select * from #T where id<3 or id>3
这难道不是在使用索引吗?