Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12554

Stored Procedures - parameter sniffing - 'recomplie' doesn't work nor 'optimize for'

$
0
0

Hi all,

i'm trying to optimise a store procedure with 4 paramaters. The query outside the stored procedure takes <1s 
When running the stored procedure it takes >10 min in general...

What improvements have i tried:

  • create sp with recompile option
  • force index usage: WITH (INDEX = <>)
  • use the OPTION (OPTIMIZE FOR UNKNOWN)
  • OPTION (OPTIMIZE FOR (@p0 = 'xx',@p1 = 'yy',@p2='zz',@p3='aa') ) 

None of the changes let the compliler generate the same query plan when running the query outside the stored procedure.
It is still performing an index Scan...

I have checked the compiled and runtime parameter values in the query plan, they are the same.

The estimated number of rows are much higher than the results, because he is performing a scan instead of an index seek?

Can someone advice?



Viewing all articles
Browse latest Browse all 12554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>