Select * from table_name where col1='a' and col2<10
Select * from table_name where col2<10 and col1='a'
col1和col2两个字段都没有索引,以上两个语句会不会有效率差别?
也就是说,条件语句中两个条件先执行哪个?
Select * from table_name where col1='a' and col2<10 and col3 in(11,14,21,24,26,31,34,36) order by col4
col3字段有“聚合索引”,in语句是不是会使“聚合索引”失效?
这个语句如何改动,或者建存储过程,会使效率更高?
Select * from table_name where datediff(day,col1,'2010-11-1')<=0 and datediff(day,col1,'2010-11-8')>=0 and col2=1 order by col3 desc
col1字段有“非聚合索引”,这个日期函数会不会使索引失效呢?
这个语句如何改动,或者建存储过程,会使效率更高?谢谢各位大侠~

解决方案 »

  1.   

    把这语句ctrl+L执行一下就明白了
    1 没什么差别
    2 会使用索引
    3 这么写挺好。
      

  2.   

    Select * from table_name where col1=1 and col2=21.col1和col2分别建立非聚集索引
    2.col1和col2建立联合索引以上两种索引方式,对查询语句的效率有影响么?哪种索引更好?
      

  3.   

    3.
    Select * from table_name where datediff(day,col1,'2010-11-1')<=0 and datediff(day,col1,'2010-11-8')>=0 and col2=1 order by col3 desc改为Select * from table_name where col1 between '2010-11-1' and '2010-11-8' and col2=1 order by col3 desc这样才有可能会用到col1字段上的“非聚合索引”,不过你又order by col3 ,看具体计划吧。