有个视图,查询全部的查询时间是1分钟左右
但是加上WHERE条件。视图反而需要3分钟
什么原因呢? 
WHERE 条件字段有加上INDEX

解决方案 »

  1.   

    select * from vw_table  
    查询全部 时间需要1分钟
    select * from vw_talbe where date>='2008/07/01'
    查询时间需要3分钟
    date字段有做index
      

  2.   

    date是日期型的吗?
    select * from vw_talbe where datediff(d,'2008-07-01',date)>=0 试试
      

  3.   

    有时候是很怪,估计是和数据的比例有关系,我写between '' and '' 就特慢
    写成下面这样就快很多,很邪!select * from  
    where datediff(d,creatdate,'2008-01-01')<=0
    and datediff(d,creatdate,'2008-02-01')>=0
      

  4.   

    贴出vw_table的内容,确认下字段date的数据类型
      

  5.   

    查询速度当然与where条件有关,where后面的字段如果有索引速度会快好多,还有与表的结构有关,表的数据量有关,where后面是否有函数有关等
      

  6.   

    木瓜老弟,
    你的语句select * from vw_talbe where date>='2008/07/01' where条件里面是时间和时间进行比较嘛,不是,是字符串类型和字符串类型比较,这是我觉得他变慢的原因,你在这儿还用到了index,起到了相反的作用。这是我的观点,欢迎板砖。
      

  7.   

    declare @t table(A nvarchar(40),createtime datetime)
    insert into @t select 'aaaa',getdate()
    insert into @t select 'aaaa',getdate()
    insert into @t select 'aaaa',getdate()
    insert into @t select 'aaaa',getdate()
    insert into @t select 'aaaa',getdate()
    insert into @t select 'aaaa',getdate()
    insert into @t select 'aaaa',getdate()
    insert into @t select 'aaaa',getdate()
    select *
    from @tselect cast(createtime as nvarchar(40)) as sum
    from @t
    where createtime>='2008/06/32' 
    消息 242,级别 16,状态 3,第 15 行
    从 char 数据类型到 datetime 数据类型的转换导致 datetime 值越界。同事小强友情赞助。说明一个问题,不是像我预想的向字符串类型转化,是字符串向时间类型转化,看来我说的是有问题的。
      

  8.   

    经过你这段语句我,我测试了一下字段DATE用DATATIME类型效率高很多。。
    YOUR RIGHT,
    THS