18
When query plans go wrong

When query plans go wrong

  • Upload
    frieda

  • View
    31

  • Download
    0

Embed Size (px)

DESCRIPTION

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: [email protected] Blog: http://Sqlblogcasts.com/blogs/simons - PowerPoint PPT Presentation

Citation preview

Page 1: When query plans go wrong

When query plans go wrong

Page 2: When query plans go wrong

SQL

Page 3: When query plans go wrong

Simon Sabin

• Independent SQL Server Consultant and Trainer• Database design and development, Business

Intelligence, Performance tuning and troubleshooting

• SQL Server since 6.5• Email: [email protected]• Blog: http://Sqlblogcasts.com/blogs/simons• Twitter: simon_sabin

Page 4: When query plans go wrong

Car crash

Page 5: When query plans go wrong

Works on my computer

Page 6: When query plans go wrong

Parameter Sniffing

@

Page 7: When query plans go wrong

SQL tries to be clever

Page 8: When query plans go wrong

A bit like

Page 9: When query plans go wrong

Statistics

Page 10: When query plans go wrong

So what are the root causes

Page 11: When query plans go wrong

Out of date statistics

Best Before: 1/4/1999

Page 12: When query plans go wrong

Skewed data

Page 13: When query plans go wrong

Multi purpose queries

Page 14: When query plans go wrong

Solutions

• Selective code paths– Careful as SP is compiled as one batch

• WITH RECOMPILE– Compilation hit, plan cache bloat

• OPTIMIZE FOR– Results in a consistent plan

• PLAN guides– Results in a consistent plan

Page 15: When query plans go wrong

Update Statistics

• Update Statistics– Can be a performance hit

• Trace flag 2388, 2389 and 2390

Page 16: When query plans go wrong

OverviewOut of date statistics

Compilation

Best Query

Skewed Data

Supportable

Multiple Code paths Update statistics OPTIMZE FOR WITH RECOMPILE Trace Flags

Page 17: When query plans go wrong

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

Page 18: When query plans go wrong

Q&A

• Now - Just ask• Afterwards – I’ll be around• Much Later– [email protected]– @simon_sabin– http://sqlblogcasts.com/blogs/simonsabin

Please fill in feedback forms