Sunday, August 17, 2014

Assistance to Optimize a Stored Procedure which as LEFT OUTER JOIN

It's not everyday you get the full database to play with, so I downloaded and restored it. Unfortunately, you failed to include a statement you have problem with. I tried


EXEC PNGudp_Reports_GuardInvoicingBreakUp '20140401', '20140501', 'B', 1


But this completed with a wink of the eye.


One thing you can try is to replace the table variables with temp tables. Table variables does not have statistics, why SQL Server typically estimates them to have a single row. This can lead to inferior plans. Table variables also tend to preclue parallelism.


Temp tables have statistics, why they can trigger recompilation and the optimizer can produce a better plan. And there are no restrictions with parallelism.





Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

No comments:

Post a Comment