获得在查询分析器里执行程序的精确时间以及查询效率问题

declare @begintime datetime
declare @endtime datetime
set @begintime=getdate()
select n_mlid from bookmenu where cjurl='http://book.qq.com/s/book/0/20/20851/20.shtml' and menuname='第20节:再见,彭湃(20)'
set @endtime=getdate()
select  cast (DATEDIFF(ms,@begintime,@endtime) as nvarchar)+'毫秒'  as result

通过一个条件可以查询到的记录不要采用多个条件来查询

比如上面:

select n_mlid from bookmenu where cjurl='http://book.qq.com/s/book/0/20/20851/20.shtml'

最低用时:400ms(30W条记录)

select n_mlid from bookmenu where cjurl='http://book.qq.com/s/book/0/20/20851/20.shtml' and menuname='第20节:再见,彭湃(20)'

最低用时:750MS(30W条记录)

原文地址:https://www.cnblogs.com/yzwdli/p/1752124.html