Why does the SqlServer optimizer get so confused with parameters?

后端 未结 9 2510
猫巷女王i
猫巷女王i 2020-12-15 12:59

I know this has something to do with parameter sniffing, but I\'m just perplexed at how something like the following example is even possible with a piece of technology that

9条回答
  •  暖寄归人
    2020-12-15 13:34

    As indicated it be a compilation issue. Does this issue still occur if you revert the procedure? One thing you can try if this occurs again to force a recompilation is to use:

    sp_recompile [ @objname = ] 'object'

    Right from BOL in regards to @objname parameter:

    Is the qualified or unqualified name of a stored procedure, trigger, table, or view in the current database. object is nvarchar(776), with no default. If object is the name of a stored procedure or trigger, the stored procedure or trigger will be recompiled the next time that it is run. If object is the name of a table or view, all the stored procedures that reference the table or view will be recompiled the next time they are run.

    If you drop and recreate the procedure you could cause clients to fail if they try and execute the procedure. You will also need to reapply security settings.

提交回复
热议问题