WEB开发网
开发学院数据库MSSQL Server SQL Server 2005性能排错(5) 阅读

SQL Server 2005性能排错(5)

 2007-05-15 09:28:24 来源:WEB开发网   
核心提示: 下列DMV查询可以被用于获取在所有数据库中所有对象上关于索引使用信息,select object_id, index_id, user_seeks, user_scans, user_lookupsfrom sys.dm_db_index_usage_statsorder by objec

下列DMV查询可以被用于获取在所有数据库中所有对象上关于索引使用信息。

select object_id, index_id, user_seeks, user_scans, user_lookups
from sys.dm_db_index_usage_stats
order by object_id, index_id

你能看到下列结果:

object_id    index_id  user_seeks  user_scans  user_lookups
------------   ------------- -------------- -------------- -----------------
521690298     1         0         251         123
521690298     2        123         0           0

在这种情况有251次查询的执行直接访问数据层表而不使用索引。有123次查询的执行通过使用非集束索引访问表,但是没有覆盖查询选择列表或在WHERE子句指定列,因为我们看到了123次在集束索引的lookup访问。

最有趣的类别着眼于‘user type statement’类型。使用方法指出在‘system category’可以被看作为存在索引的结果。如果索引不存在,它不会更新统计,也不需要检查一致性。因此分析需要着眼于4列显示独立语句的使用或分析用户应用程序。

为了获取从上次SQL Server启动以来,关于指定表没有使用的索引信息,这种查询将在数据库上下文中执行。

select i.name
from sys.indexes i
where i.object_id=object_id('<table_name>') and
i.index_id NOT IN (select s.index_id
from sys.dm_db_index_usage_stats s
where s.object_id=i.object_id and
i.index_id=s.index_id and
database_id = <dbid> )

所有没有被使用的索引仍可以通过下列语句获取信息:

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:SQL Server 性能

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接