SQL Server性能调优杂记(四)
2008-12-08 10:15:13 来源:WEB开发网执行速度飞快。毫秒级别。
那么为什么客户端程序,速度很慢呢(差10个数量级)?
我第一反应,2个的SQL文一定不一样。因为客户端代码采用的是SQLCommand的动态参数写法。在这种情况下,SQL Server会在数据库后台用一个动态执行的存储过程来执行(应该是为了重用执行计划)。
我们来看看SQL Server的执行方法
exec sp_executesql N'
SELECT a.AWB_NO,
a.BWB_NO,
a.CWB_NO,
a.ORIGIN,
a.DEST,
a.MODIFY_ON,
a.CREATED_ON,
a.CONSIGNOR_CUSTOMER_CODE,
a.CONSIGNOR_CODE,
a.CONSIGNOR_NAME,
a.CONSIGNEE_NAME,
a.CWB_STATUS,
a.CWB_TYPE,
ISNULL(a.PCS, 0) AS PCS,
a.BWBLIST,
b.PWEIGHT
FROM TB_CWB AS a
LEFT JOIN TB_CWBWEIGHT AS b
ON a.CWB_NO = b.CWB_NO
AND b.AVAILABLE = ''Y''
WHERE a.AVAILABLE = ''Y''
AND (a.CWB_NO = @CWB_NO OR
(( @CWB_NO IS NULL)
AND (a.AWB_NO = @AWB_NO OR @AWB_NO IS NULL)
AND (a.BWB_NO = @BWB_NO OR @BWB_NO IS NULL)
AND (a.IE_TYPE = @IE_TYPE OR @IE_TYPE IS NULL)
AND (a.CREATED_ON >= @DateFrom OR @DateFrom IS NULL)
AND (a.CREATED_ON <= @DateTo OR @DateTo IS NULL)
AND (a.PAYMENT = @PAYMENT OR @PAYMENT IS NULL)
AND (a.ORIGIN = @ORIGIN OR @ORIGIN IS NULL)
AND (a.DEST = @DEST OR @DEST IS NULL)
AND (a.CONSIGNOR_CUSTOMER_CODE = @CONSIGNOR_CUSTOMER_CODE OR @CONSIGNOR_CUSTOMER_CODE IS NULL)
AND (a.CONSIGNOR_NAME LIKE ''%'' + @CONSIGNOR_NAME + ''%'' OR @CONSIGNOR_NAME IS NULL)
AND (a.CONSIGNEE_NAME LIKE ''%'' + @CONSIGNEE_NAME + ''%'' OR @CONSIGNEE_NAME IS NULL)
AND (a.CWB_TYPE = @CWB_TYPE OR @CWB_TYPE IS NULL)))',N'@CWB_NO nvarchar(11),@AWB_NO nvarchar(4000),@BWB_NO nvarchar(4000),@IE_TYPE
nvarchar(4000),@DateFrom nvarchar(4000),@DateTo nvarchar(4000),@CWB_TYPE nvarchar(4000),@PAYMENT nvarchar(4000),@ORIGIN nvarchar(4000),@DEST
nvarchar(4000),@CONSIGNOR_CUSTOMER_CODE nvarchar(4000),@CONSIGNOR_NAME nvarchar(4000),@CONSIGNEE_NAME
nvarchar(4000)',@CWB_NO=N'31017768390',@AWB_NO=NULL,@BWB_NO=NULL,@IE_TYPE=NULL,@DateFrom=NULL,@DateTo=NULL,@CWB_TYPE=NULL,@PAYMENT=NULL,@ORIGIN=NULL,@DEST=NULL,@CONSIGNOR_CUSTOMER_CODE=NULL,@CONSIGNOR_NAME=NULL,@CONSIGNEE_NAME=NULL
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
- ››SQL SERVER无法安装成功,sqlstp.log文件提示[未发...
- ››Sql Server中通过父记录查找出所有关联的子记录
- ››SqlServer触发器、存储过程和函数
- ››SQL Server 中的事务(含义,属性,管理)
- ››Sqlite数据库插入和读取图片数据
- ››Sql server 2005拒绝了对对象 'xx表' (数...
- ››Sql server 2005拒绝了对对象 'xx表' (数...
更多精彩
赞助商链接