在mssql server中通过查看sql语句执行所用的时间,来衡量sql语句的性能。
通过设置statistics我们可以查看执行sql时的系统情况。选项有profile,io ,time。介绍如下:
set statistics profile on:显示分析、编译和执行查询所需的时间(以毫秒为单位)。
set statistics io on:报告与语句内引用的每个表的扫描数、逻辑读取数(在高速缓存中访问的页数)和物理读取数(访问磁盘的次数)有关的信息。
set statistics time on:显示每个查询执行后的结果集,代表查询执行的配置文件。
语句示例:
set statistics profile on; set statistics io on; set statistics time on; go /*--你的sql脚本开始*/ select [groupby1].[a1] as [c1] from ( select count(1) as [a1] from [dbo].[questions] as [extent1] where ( [extent1].[checkuser] is not null ) and ( not ( ( n'' = [extent1].[checkuser] ) and ( [extent1].[checkuser] is not null ) ) ) and ( [extent1].[source] in ( n'xxx1', n'xxx2', n'xxx3' ) ) and ( [extent1].[source] is not null ) ) as [groupby1]; /*你的sql脚本结束*/ go set statistics profile off; set statistics io off; set statistics time off;
其他参考:
https://www.cnblogs.com/xcsn/p/7773212.html