惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AWS News Blog
AWS News Blog
Schneier on Security
Schneier on Security
P
Palo Alto Networks Blog
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
S
Secure Thoughts
L
LINUX DO - 最新话题
S
Securelist
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
Recent Announcements
Recent Announcements
S
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cyberwarzone
Cyberwarzone
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Vulnerabilities – Threatpost
T
Tor Project blog
GbyAI
GbyAI
B
Blog
博客园 - 司徒正美
博客园 - 叶小钗
Recorded Future
Recorded Future
F
Fortinet All Blogs
Spread Privacy
Spread Privacy
IT之家
IT之家
Forbes - Security
Forbes - Security
L
Lohrmann on Cybersecurity
有赞技术团队
有赞技术团队
博客园 - 聂微东
A
Arctic Wolf
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
The Blog of Author Tim Ferriss
N
News and Events Feed by Topic
O
OpenAI News
Apple Machine Learning Research
Apple Machine Learning Research
Help Net Security
Help Net Security
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
TaoSecurity Blog
TaoSecurity Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - 迷途

Axure教程 | 轻量级的后台原型框架 Axure:侧导航收缩与展开 SQLSERVER数据库调优 MySQL用GROUP BY分组取字段最大值或最新一条 Mysql索引总结 Sqlserver 创建表角本 在SQLSERVER中处理特殊字符以及空格。 索引优化--汇总 游标简单使用 SQL Server 索引优化-----数据库引擎优化顾问 SQL Server 索引优化 ——索引缺失 SQL Server 索引优化——无用索引 win7远程服务器发生身份验证错误,要求的函数不受支持 库龄分析-先进先出法 sql server 数据库创建链接服务器 SQL Server 2008 R2中配置作业失败后邮件发送通知 sqlserver 使用脚本创建作业 SQL分组取每组前一(或几)条记录(排名) SQL SERVER 中如何用脚本管理作业
sqlserver2008 查看数据库自带的索引建议
迷途 · 2017-07-04 · via 博客园 - 迷途
SELECT 

        [Total Cost]  = ROUND(avg_total_user_cost * avg_user_impact * (user_seeks + user_scans),0) 

        , avg_user_impact

        , TableName = statement

        , [EqualityUsage] = equality_columns 

        , [InequalityUsage] = inequality_columns

        , [Include Cloumns] = included_columns

FROM        sys.dm_db_missing_index_groups g 

INNER JOIN    sys.dm_db_missing_index_group_stats s 

       ON s.group_handle = g.index_group_handle 

INNER JOIN    sys.dm_db_missing_index_details d 

       ON d.index_handle = g.index_handle

ORDER BY [Total Cost] DESC;
SELECT

    c.name AS databasename,

    c.equality_columns,

    c.inequality_columns,

    c.included_columns,

    c.statement AS tablename,

    c.avg_total_user_cost AS ReducingTheAverageCost,

    c.avg_user_impact AS PercentageOfRevenue,

    c.last_user_seek AS TheLastTimeTheEffectAfterUse,

    c.unique_compiles

FROM (SELECT

    a.name,

    b.*

FROM   (SELECT

           d.*,

           s.avg_total_user_cost,

           s.avg_user_impact,

           s.last_user_seek,

           s.unique_compiles

       FROM   sys.dm_db_missing_index_group_stats s,

              sys.dm_db_missing_index_groups g,

              sys.dm_db_missing_index_details d

       WHERE s.group_handle = g.index_group_handle

       AND d.index_handle = g.index_handle

       AND s.avg_user_impact > 90

       --AND s.unique_compiles > 10

       --order by s.avg_user_impact desc

       ) b,

       sys.databases a

WHERE a.database_id = b.database_id) c

WHERE c.name = 'xxxxx'

ORDER BY PercentageOfRevenue DESC, unique_compiles DESC

当然,按照上面的规则建立索引,不过还是要建立尽量少的索引,因为索引建多了,会导致insert、update等操作的开销增大,降低性能。

还有,在建立了索引后,可以通过如下的查询,来查询索引的使用的情况:

select *
from sys.dm_db_index_usage_stats

如果,对index_seek的次数,很小,那么可以考虑删除这个索引,再尝试建立其他的索引,如此多次,就能建立真正让查询使用的索引,让这些索引都能发挥作用,同时尽量减少索引的数量

查看未被使用过的索引

select object_name(object_id), i.name
from sys.indexes i
where 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> )
order by object_name(object_id) asc