
I’m also available for consulting if you just don’t have time for that and need to solve performance problems quickly. I’m offering a 75% discount on to my blog readers if you click from here. If this is the kind of SQL Server stuff you love learning about, you’ll love my training. There are some other potential issues, like plan compilation overhead, and there have been bugs around it in the past. I don’t usually advocate for jumping right to recompile, mostly because it wipes the forensic trail from the plan cache. You can only do that by adding OPTION(RECOMPILE) to the query, like this: SET = + N'Ĭhalk this one up to “maybe it wasn’t parameter sniffing” in the first place. That doesn’t recompile the query that sp_executesql runs. WHERE v.CreationDate >= sys.sp_executesql = RECOMPILE To us, that just means that the execution plan might be better than a normal execution plan compiled for the current statement. There’s some benefits, like something called constant folding. Recently, I saw someone use it like this: DECLARE DATETIME = '20101230' What happens when a statement has OPTION (RECOMPILE) SQL Server will compile an execution plan specifically for the statement that the query hint is on. One common “solution” to parameter sniffing is to tack a recompile hint somewhere. Like, if I passed in , we probably wouldn’t like a lookup too much. That’s an example of how parameters are sniffed. If I re-run the query and use the date, we’ll re-use the key lookup plan. WHERE v.CreationDate >= sys.sp_executesql = give us the key lookup plan you see above. Let’s paramaterize that! DECLARE DATETIME = '20101231'


Well, if there is just one 'select' statement then you.If I am recompiling the stored procedure then everything is fine. After a nearly a month my report which is using this stored procedure become very slow.

What a difference a day makes to a query plan! Curse the head Hard To Digest Hi, I have stored procedure which is based on tables that one of them has nearly 4M records and is being updated constantly. CREATE INDEX ix_fraud ON dbo.Votes ( CreationDate ) Let’s take this index, and these queries.
