Dissecting SQL Server Execution Plans - SQLServerCentral.com
Recommend Documents
Right from the basics of capturing plans, through to their interpretation, and then
on to how to use them to understand how you might optimize your SQL queries ...
Bring your SQL Server installations to a new level of excellence! ... Statement.
Normalize. Execution. Tree. Optimize. SQL. Query. Cache. Execution. Plan.
May affect performance for top or fast N queries. â Defines ... Great for automated tools ..... Inside SQL Server 2005
M10774: Queryng Microsoft SQL Server. 2012. 670 KM ... М50439: Basics of
Transact SQL with SQL. Server 2008 R2 ... Web/Windows programiranje.
LANACO ...
Oct 17, 2009 - A parent is placed before its children (ID of the parent < ID of the children) ... Since this is the l
You may also like to visit How to interview someone for a job. Contents: ... SSAS
Interview questions and answers (coming soon) - SQL Server Analysis Services.
Summary: Learn how to manage SQL Server 2005 Express Edition by using the
free graphical management tool, SQL Server 2005 Management Studio Express
Edition. (SSMSE). Developers and ..... presentation. The order of columns in the ...
This guide has been updated to reflect the T-SQL improvements contained within
... SMP to the Microsoft® SQL Server® Parallel Data Warehouse (PDW).
Use, copying, and distribution of any EMC software described in this publication requires an applicable .... These appli
First4 Database Partners Inc. September 20, 2012 ... Obtaining the Software. •
Publically available download from otn.oracle.com ... whether RAC is used .... .
pdf ...
10. Passing the requested page(s) back to the AM. 11. Passing the results set to
the. Relational Engine credit: SQL Server 2008 Internals and Troubleshooting.
Solutions–Navision®, Microsoft SQL Server 2005™ makes it easier for your
employees to ... configure OLAP cubes easily using a set of forms within Microsoft
... Microsoft SQL Server database and the Microsoft® Windows® operating
system.
3.0 – SQL Server 2005 Mobile Edition. ▻ 3.1 – SQL Server 2005 Compact
Edition. ▻ 3.5 – SQL Server Compact 3.5. + Local transaction scope. + LINQ to
SQL.
Sample query: Obtain information about certain ordered line- items that are
filtered by suppliers and parts. SQL Server Query Optimizer. ▫ Based on
Cascades ...
Keywords: Query, Optimization, SQL Server. Introduction. There are many
situations in which effi- ciency and performance are the last criteria considered
when ...
Εντολές. ▫ Καθορισµός σχήµατος. ○ CREATE object_type object_name. ○
ALTER object_type object_name. ○ DROP object_type object_name. ▫
Χειρισµός ...
What's changed since Microsoft® SQL Server® 2005? • Why should I use SQL
Server Audit? • What is the performance impact? • Can I protect the audit log from
...
SQL Server 2005. Replication. A comprehensive guide to developing,
administering, and mastering the complexities of replication with SQL Server
2005 ilable.
SQL Server Audit Checklist. By K. Brian Kelley, MCSE, CISA, Security+, MVP-
SQL Server. Administrative rights over the Domain where SQL Server is installed.
INTRODUCCIÓN. INFORMATICA 64, S.L.. INFORMATICA 64 SL. 1. Qué es SQL
Server____________________________________________________ 10.
purposes only and Microsoft makes no representations and warranties, either
expressed ... Graeme Malcolm is a Microsoft SQL Server subject matter expert
and.
Feb 15, 2011 ... Back in April 2010 I had the idea to do a DBA-Myth-A-Day series on my blog. (
www. ... document, and I've worked it up into this PDF, which I present to you now
. Please feel free to re-distribute, reference, or print-out this do
NIMBLE STORAGE BEST PRACTICES GUIDE: MICROSOFT SQL SERVER. 2.
Summary. Microsoft SQL Server databases provide the data storage back end for
...
murach's. SQL Server. 2008 for developers. (Chapter 3). Thanks for reviewing
this ... 8 shows you how to work with the various types of data that SQL Server.
Dissecting SQL Server Execution Plans - SQLServerCentral.com
The Art of High Performance. SQL Code, Volume 1: Dissecting SQL Server
Execution Plans by Grant Fritchey. First published 2008 by Simple-Talk
Publishing ...
The Art of High Performance SQL Code, Volume 1:
Dissecting SQL Server Execution Plans
by Grant Fritchey First published 2008 by Simple-Talk Publishing
iii
CONTENTS Contents .................................................................................................................................................... 3 About the author...................................................................................................................................... 7 acknowledgements................................................................................................................................... 8 Introduction.............................................................................................................................................. 9 Foreword .................................................................................................................................................11 Chapter 1: Execution Plan Basics .......................................................................................................12 What Happens When a Query is Submitted? .........................................................................12 Query Parsing...........................................................................................................................12 The Query Optimizer .............................................................................................................13 Query Execution......................................................................................................................14 Estimated and Actual Execution Plans................................................................................14 Execution Plan Reuse .............................................................................................................14 Why the Actual and Estimated Execution Plans Might Differ........................................16 Execution Plan Formats .........................................................................................................17 Graphical Plans ........................................................................................................................17 Text Plans..................................................................................................................................17 XML Plans................................................................................................................................17 Getting Started .............................................................................................................................17 Sample Code.............................................................................................................................18 Permissions Required to View Execution Plans.................................................................18 Working with Graphical Execution Plans................................................................................18 Getting the Estimated Plan....................................................................................................19 Getting the Actual Plan ..........................................................................................................19 Interpreting Graphical Execution Plans ..............................................................................20 Working with Text Execution Plans .........................................................................................23 Getting the Estimated Text Plan...........................................................................................24 Getting the Actual Text Plan .................................................................................................24 Interpreting Text Plans ...........................................................................................................24 Working with XML Execution Plans........................................................................................25 Getting the Actual and Estimated XML Plans...................................................................25 Interpreting XML Plans..............................................................................................................26 Saving XML Plans as Graphical Plans .................................................................................28 Automating Plan Capture Using SQL Server Profiler...........................................................28 Execution Plan events.............................................................................................................29 Capturing a Showplan XML Trace .......................................................................................29
iv Summary........................................................................................................................................32 Chapter 2: Reading Graphical Execution Plans for Basic Queries ................................................33 The Language of Graphical Execution Plans .........................................................................33 Some Single table Queries ..........................................................................................................34 Clustered Index Scan...............................................................................................................34 Clustered Index Seek...............................................................................................................35 Non-clustered Index Seek ......................................................................................................37 Key LookUp .............................................................................................................................38 Table Scan .................................................................................................................................42 RID LookUp ............................................................................................................................44 Table Joins.....................................................................................................................................46 Hash Match (Join)....................................................................................................................48 Clustered Index Seek...............................................................................................................50 Nested Loops Join...................................................................................................................51 Compute Scalar ........................................................................................................................51 Merge Join.................................................................................................................................52 Adding a WHERE Clause ..........................................................................................................54 Execution Plans with GROUP BY and ORDER BY ...........................................................56 Sort.............................................................................................................................................56 Hash Match (Aggregate).........................................................................................................58 Filter...........................................................................................................................................59 Rebinds and Rewinds Explained ...............................................................................................60 Insert, Update and Delete Execution Plans.............................................................................62 Insert Statements .....................................................................................................................62 Update Statements...................................................................................................................63 Delete Statements ....................................................................................................................64 Summary........................................................................................................................................66 Chapter 3: Text and XML Execution Plans for Basic Queries.......................................................67 Text Execution Plans...................................................................................................................67 A Text Plan for a Simple Query ............................................................................................67 A Slightly more Complex Query...........................................................................................69 XML Execution Plans .................................................................................................................73 An Estimated XML Plan ........................................................................................................74 An Actual XML Plan ..............................................................................................................77 Summary........................................................................................................................................77 Chapter 4: Understanding More Complex Query Plans..................................................................79 Stored Procedures........................................................................................................................79 Derived Tables..............................................................................................................................80
v A Subselect without a Derived Table ...................................................................................80 A Derived Table using APPLY .............................................................................................83 Common Table Expressions......................................................................................................86 Views..............................................................................................................................................88 Standard Views ........................................................................................................................88 Indexed Views..........................................................................................................................89 Indexes...........................................................................................................................................91 Included Indexes: Avoiding Bookmark Lookups...............................................................91 Index Selectivity.......................................................................................................................94 Statistics and Indexes ..............................................................................................................96 Summary .......................................................................................................................................97 Chapter 5: Controlling Execution Plans with Hints.........................................................................99 Query Hints ..................................................................................................................................99 HASH|ORDER GROUP.....................................................................................................99 MERGE |HASH |CONCAT UNION ...........................................................................101 LOOP|MERGE|HASH JOIN .........................................................................................102 FAST n ....................................................................................................................................105 FORCE ORDER ..................................................................................................................106 MAXDOP ..............................................................................................................................107 OPTIMIZE FOR..................................................................................................................109 PARAMETERIZATION SIMPLE|FORCED ..............................................................112 RECOMPILE ........................................................................................................................112 ROBUST PLAN....................................................................................................................114 KEEP PLAN .........................................................................................................................114 KEEPFIXED PLAN ...........................................................................................................114 EXPAND VIEWS ................................................................................................................114 MAXRECURSION ..............................................................................................................115 USE PLAN.............................................................................................................................115 Join Hints ....................................................................................................................................116 Table Hints..................................................................................................................................118 Table Hint Syntax ..................................................................................................................119 NOEXPAND ........................................................................................................................119 INDEX().................................................................................................................................120 FASTFIRSTROW .................................................................................................................121 Summary .....................................................................................................................................123 Chapter 6: Cursor Operations ...........................................................................................................124 Simple Cursors ...........................................................................................................................124
vi Logical Operators ..................................................................................................................125 Physical Operators.................................................................................................................130 More Cursor Operations...........................................................................................................130 STATIC Cursor......................................................................................................................130 KEYSET Cursor....................................................................................................................133 READ_ONLY Cursor..........................................................................................................135 Cursors and Performance.........................................................................................................135 Summary......................................................................................................................................140 Chapter 7: XML in Execution Plans.................................................................................................141 FOR XML...................................................................................................................................141 OPENXML ................................................................................................................................146 XQuery ........................................................................................................................................149 Using the exist method .........................................................................................................149 Using the query method .......................................................................................................151 Summary......................................................................................................................................152 Chapter 8: Advanced Topics ..............................................................................................................154 Reading Large Scale Execution Plans .....................................................................................154 Parallelism in Execution Plans .................................................................................................158 Max Degree of Parallelism...................................................................................................158 Cost Threshold for Parallelism............................................................................................159 Are Parallel Plans Good or Bad?.........................................................................................160 Examining a Parallel Execution Plan..................................................................................160 How Forced Parameterization affects Execution Plans.......................................................163 Using Plan Guides to Modify Execution Plans.....................................................................166 Object Plan Guides ...............................................................................................................166 SQL Plan Guides ...................................................................................................................167 Template Plan Guides ...........................................................................................................168 Plan Guide Administration ..................................................................................................169 Summary .................................................................................................................................169 Using Plan Forcing to Modify Execution Plans....................................................................169 Summary......................................................................................................................................171 Index ......................................................................................................................................................172