Hi All
Just a really weird issue here, we have 2 identical stored procedures. Thesame parameters were also passed onto the stored procedures.
They both use assigned local variables to get around parameter sniffing, now out of all the params passed we have only one param which doesnt use local varaibles,and what I found is that that version of the proc which doesnt use local variable for the single param gneerates a parallel plan, whereas the plan which uses local assigned variables for all parameters including the parameter that was excluded before is generating a serial plan. The serial plan is 3 times slower than the parallel plan.
Another difference that I can see is that in most cases, the estimated number of rows is thesame, as its thesame params passed to the 2 procs, but in a small number of cases the estimation is somewhat different, I can also see that the version which uses the good parallel plan has a compiled value for the param which isnt a local one in the execution plan.
The serial plan doesnt have any compiled value as I believe its using stats to do an estimate. Would I be correct in saying that because the version which uses local variable all the way, is using estimated stats hence the reason for the serial plan which may not be optimal atimes but is an average good plan.
Is this the correct explanation for why we are seeing a discrepancy between the 2 calls despite passing same param, and on same DB ? IS it just a case of updating stats and running it again ?