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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
AWS News Blog
AWS News Blog
V
Vulnerabilities – Threatpost
D
Darknet – Hacking Tools, Hacker News & Cyber Security
量子位
博客园 - 叶小钗
AI
AI
T
Tor Project blog
Forbes - Security
Forbes - Security
W
WeLiveSecurity
博客园_首页
爱范儿
爱范儿
J
Java Code Geeks
B
Blog
G
GRAHAM CLULEY
aimingoo的专栏
aimingoo的专栏
Cloudbric
Cloudbric
C
CXSECURITY Database RSS Feed - CXSecurity.com
TaoSecurity Blog
TaoSecurity Blog
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
有赞技术团队
有赞技术团队
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
H
Help Net Security
博客园 - 三生石上(FineUI控件)
C
Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Palo Alto Networks Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园 - 司徒正美
The Last Watchdog
The Last Watchdog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
S
Secure Thoughts
Spread Privacy
Spread Privacy
F
Fortinet All Blogs
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
Security Latest
Security Latest
Webroot Blog
Webroot Blog
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog

博客园 - 迷途

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