Why are there performance differences when a SQL function is called from .Net app vs when the same call is made in Management Studio

后端 未结 3 1570
难免孤独
难免孤独 2021-01-12 05:10

We are having a problem in our test and dev environments with a function that runs quite slowly at times when called from an .Net Application. When we call this function di

3条回答
  •  无人共我
    2021-01-12 06:01

    A likely cause is out of date statistics and/or parameter sniffing causing a cached query plan to be re-used that is sub-optimal.

    SSMS emits pre-amble statements that you don't see, that cause the submitted query to be re-compiled each time, thus eliminating the possibility of using an incorrect cached plan.

    This will update all statistics and refresh views and stored procs (but be careful about running on a Production machine):

    EXEC sp_updatestats
    
    EXEC sp_refreshview 
    
    EXEC sp_msForEachTable 'EXEC sp_recompile ''?'''
    

提交回复
热议问题