原理:当使用适配器进行查询时,如果适配器的表达式中使用了'%字符串',那么他走的是表扫描,而不是用索引扫描,
这样面对大量数据查询的时候会花费很长的时间,因此在面对大数量查询时要尽量避免使用适配器查询;相反,如果适
配器的表达式不以'%'开头,那么扔走索引路。
注意(前提是使用适配器查询的列上建立了索引,否则他们都走表扫描)
注意(前提是使用适配器查询的列上建立了索引,否则他们都走表扫描)
执行如下代码就知道了:
if object_id('TempInput') is not null
drop table TempInput
go
create table TempInput(inputdate_dt datetime,orgid_i int)
create index ix_test on TempInput(inputdate_dt)
declare @i int
set @i=0
while(@i<1000)
begin
insert into TempInput select cast((convert(varchar(10),dateadd(dd,@i,getdate()),120)) as
drop table TempInput
go
create table TempInput(inputdate_dt datetime,orgid_i int)
create index ix_test on TempInput(inputdate_dt)
declare @i int
set @i=0
while(@i<1000)
begin
insert into TempInput select cast((convert(varchar(10),dateadd(dd,@i,getdate()),120)) as
datetime),@i
set @i=@i+1
end
set @i=@i+1
end
declare @d1 datetime
set @d1=getdate()
select inputdate_dt,orgid_i from TempInput where convert(varchar(7),inputdate_dt,120) like '%2008-04%'
select datediff(ms,@d1,getdate())
set @d1=getdate()
select inputdate_dt,orgid_i from TempInput where convert(varchar(7),inputdate_dt,120) like '%2008-04%'
select datediff(ms,@d1,getdate())
declare @d2 datetime
set @d2=getdate()
select inputdate_dt,orgid_i from TempInput where convert(varchar(7),inputdate_dt,120)='2008-04'
select datediff(ms,@d2,g
set @d2=getdate()
select inputdate_dt,orgid_i from TempInput where convert(varchar(7),inputdate_dt,120)='2008-04'
select datediff(ms,@d2,g