When query plans go wrong
SQL
Simon Sabin Independent SQL Server Consultant and Trainer Database design and development, Business Intelligence, Performance tuning and troubleshooting SQL Server since 6.5 Email: Simon@onarc.com Blog: http://Sqlblogcasts.com/blogs/simons Twitter: simon_sabin
Car crash
Works on my computer
Parameter Sniffing @
SQL tries to be clever
A bit like
Statistics
So what are the root causes
Out of date statistics Best Before: 1/4/1999
Skewed data
Multi purpose queries
Solutions Selective code paths WITH RECOMPILE OPTIMIZE FOR PLAN guides Careful as SP is compiled as one batch WITH RECOMPILE Compilation hit, plan cache bloat OPTIMIZE FOR Results in a consistent plan PLAN guides
Update Statistics Update Statistics Trace flag 2388, 2389 and 2390 Can be a performance hit Trace flag 2388, 2389 and 2390
Overview Out of date statistics Compilation Best Query Skewed Data Supportable Multiple Code paths Update statistics OPTIMZE FOR WITH RECOMPILE Trace Flags
Summary You will only know if you monitor Baseline your system Identify changes in read, writes and cpu Not duration Consider the options for your situation You can win this battle
Please fill in feedback forms Q&A Now - Just ask Afterwards – I’ll be around Much Later Simon@SQLKnowHow.com @simon_sabin http://sqlblogcasts.com/blogs/simonsabin Please fill in feedback forms