May 2019
Intermediate to advanced
484 pages
11h 23m
English
One of the quickest ways to tune a query is to add a covering index. As we discussed in Chapter 4, Exploring Query Execution Plans, the presence of a lookup in a query execution plan indicates that a query is not covered. We can leverage this same XQuery method to find query execution plans that contain a lookup anywhere in the plan.
The following query will find query execution plans that have a lookup:
WITH XMLNAMESPACES(DEFAULT'http://schemas.microsoft.com/sqlserver/2004/07/showplan'), Lookupsearch AS (SELECT qp.query_plan, cp.usecounts, ls.query('.') AS StmtSimple, cp.plan_handle FROM sys.dm_exec_cached_plans cp (NOLOCK) CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) qp CROSS APPLY qp.query_plan.nodes('//StmtSimple') ...Read now
Unlock full access