Why does the SqlServer optimizer get so confused with parameters?

后端 未结 9 2506
猫巷女王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:11

    It's probably caused by the fact that SQL Server compiles stored procedures and caches execution plans for them and the cached execution plan is probably unsuitable for this new set of parameters. You can try WITH RECOMPILE option to see if it's the cause.

    EXECUTE MyProcedure [parameters] WITH RECOMPILE
    

    WITH RECOMPILE option will force SQL Server to ignore the cached plan.

提交回复
热议问题