EXECUTION PLANS Quick Dive
ABOUT ME @shawsql http://www.blogofshaw.blogspot.com/
I OWE EVERYTHING TO…
WHAT WE WON’T TALK ABOUT Execution plan cache Performance tuning DMV’s (maybe a little) XML, parallelism, partitioning, etc. Statistics Politics
KEY CONCEPTS T-SQL is non-procedural This means the language does not tell how to retrieve the data Execution Plans are cost-based This means even a good plan may not necessarily be the best plan and the best plan may never be known Execution Plans are broken up into logical and physical operators Logical operations are expressed by physical operations
EXECUTION PROCESS
EXECUTION PLANS Each step in an execution plan is a physical operator Plans read from left to right Bar thickness represents amount of data Outer tables on top, inner tables on bottom Plans are either “trivial” or “full”
DEMO Trivial Plans Index\Table Scans\Seeks Bookmark Lookups
JOIN TYPES Hash - Build table and probe table - In memory, grace, recursive Nested Loops - Outer table and inner table - Best when outer input is small and inner output is indexed
JOIN TYPES Merge - Each input is sorted - Best for large, pre-sorted tables
DEMO Join Types
TOOL TIP TIME A lot of information but most not necessarily relevant.
Best Practices Locate the step with the highest cost Eliminate table scans Update statistics Avoid bookmark lookups by using clustered indexes or covering indexes