SQL Server-缺少索引-索引将使用什么? [英] SQL Server - Missing Indexes - What would use the index?
本文介绍了SQL Server-缺少索引-索引将使用什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用SQL Server 2008,并且正在使用DMV查找丢失的索引.但是,在创建新索引之前,我试图找出想要该索引的proc/query.我希望获得尽可能多的信息,以便可以对索引做出明智的决定.有时候,SQL Server想要的索引对我来说没有意义.有谁知道我能找出想要的东西吗?
I am using SQL Server 2008 and we are using the DMV's to find missing indexes. However, before I create the new index I am trying to figure out what proc/query is wanting that index. I want the most information I can get so I can make informed decision on my indexes. Sometimes the indexes SQL Server wants does not make sense to me. Does anyone know how I can figure out what wants it?
推荐答案
这是最终有效的方法:
with xmlnamespaces(default 'http://schemas.microsoft.com/sqlserver/2004/07/showplan') , CachedPlans as (
select
query_plan,
n.value('../../../@StatementText' ,'varchar(1000)') as [Statement],
n.value('../../../@StatementSubTreeCost' ,'varchar(1000)') as [Cost],
n.value('../../../@StatementEstRows' ,'varchar(1000)') as [Rows],
n.value('@Impact' ,'float') as Impact,
n.value('MissingIndex[1]/@Database' ,'varchar(128)') as [Database],
n.value('MissingIndex[1]/@Table' ,'varchar(128)') as [TableName],
(
select dbo.concat(c.value('@Name' ,'varchar(128)'))
from n.nodes('MissingIndex/ColumnGroup[@Usage="EQUALITY"][1]') as t(cg)
cross apply cg.nodes('Column') as r(c)
) as equality_columns,
(
select dbo.concat(c.value('@Name' ,'varchar(128)'))
from n.nodes('MissingIndex/ColumnGroup[@Usage="INEQUALITY"][1]') as t(cg)
cross apply cg.nodes('Column') as r(c)
) as inequality_columns,
(
select dbo.concat(c.value('@Name' ,'varchar(128)'))
from n.nodes('MissingIndex/ColumnGroup[@Usage="INCLUDE"][1]') as t(cg)
cross apply cg.nodes('Column') as r(c)
) as include_columns
from (
select query_plan
from sys.dm_exec_cached_plans p
outer apply sys.dm_exec_query_plan(p.plan_handle) tp
) as tab(query_plan)
cross apply query_plan.nodes('//MissingIndexGroup') as q(n)
)
select *
from CachedPlans
这篇关于SQL Server-缺少索引-索引将使用什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文