SQL poor stored procedure execution plan performance - parameter sniffing

后端 未结 3 1007
花落未央
花落未央 2020-11-29 07:17

I have a stored procedure that accepts a date input that is later set to the current date if no value is passed in:

CREATE PROCEDURE MyProc
    @MyDate DATET         


        
3条回答
  •  难免孤独
    2020-11-29 07:36

    One way I was able to get around this problem in (SQL Server 2005) instead of just masking the parameters by redeclaring local parameters was to add query optimizer hints.

    Here is a good blog post that talks more about it: Parameter Sniffing in SqlServer 2005

    I used: OPTION (optimize for (@p = '-1'))

提交回复
热议问题