Why does sp_executesql run slower when parameters are passed as arguments

后端 未结 3 1797

Query 1: (lightning fast)

sp_executesql \"select * from tablesView where Id = 1\"

vs.

Query 2: (too slow)

sp_executesql         


        
3条回答
  •  暖寄归人
    2021-02-20 11:18

    This could be a parameter sniffing problem. Try including the line:

    OPTION (RECOMPILE)
    

    at the end of your SQL query.

    There is an article here explaining what parameter sniffing is: http://blogs.technet.com/b/mdegre/archive/2012/03/19/what-is-parameter-sniffing.aspx

提交回复
热议问题