WEB开发网
开发学院数据库MSSQL Server SQL Server性能调优杂记(四) 阅读

SQL Server性能调优杂记(四)

 2008-12-08 10:15:13 来源:WEB开发网   
核心提示: 执行速度飞快,毫秒级别,SQL Server性能调优杂记(四)(3),那么为什么客户端程序,速度很慢呢(差10个数量级)?我第一反应,2个的SQL文一定不一样,因为客户端代码采用的是SQLCommand的动态参数写法

执行速度飞快。毫秒级别。

那么为什么客户端程序,速度很慢呢(差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

上一页  1 2 3 4  下一页

Tags:SQL Server 性能

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接