日期:2014-05-17  浏览次数:20631 次

请教高手 哪个语句的效率会高一些

--语句1
select e.em_id, i.ID,i.mbno,i.Msg,i.ArriveTime,i.Readed,i.username,i.comport 
from InBox i 
  left join employee e
on RIGHT( i.mbno,11) =  e.em_mobile
where i.Readed=2

--语句2
select e.em_id, i.ID,i.mbno,i.Msg,i.ArriveTime,i.Readed,i.username,i.comport 
from (select ID,mbno,Msg,ArriveTime,Readed,username,comport 
from InBox  where Readed=2 )  i
  left join employee e
on RIGHT( i.mbno,11) =  e.em_mobile




请教高手哈,这两个查询语句哪个效率高呢? 为什么?
sql join

------解决方案--------------------
语句1会比2效率好一些.
语句2带有子查询.
------解决方案--------------------
第一条 第一条语句 比第二条少个子查询 多个where语句 子查询效率必然比where语句效率低
------解决方案--------------------
把两个语句放到同一个界面,开启执行计划,然后一起执行,看百分比就知道了。把执行计划贴出来看看。
------解决方案--------------------
Ctrl +L 看执行计划。
索引做好,应该是2快.
------解决方案--------------------
那就是一样咯
------解决方案--------------------
set stistics time on 
go
set stistics io om
go
--sql语句

set stistics time off
go
set stistics io off
go


这个可以看到cpu编译和执行,读取的次数。楼主可以试试。


------解决方案--------------------
如果数据多的话就不一样了
------解决方案--------------------
这两个语句,优化器会生成相同的执行计划,速度是一样的