SQL 中自动索引建议的最佳实践是什么

What are the best practices for auto index recommendations in SQL

我正在审查具有 30 多个数据库的 SQL Server 2008 R2 实例,目标是迁移到 SQL Server 2014。在审查这个过程中,我发现了一份 SQL 工作以前的员工实施。该作业利用本文 https://www.sqlservercentral.com/forums/topic/indexing-views-1 中的一组脚本,每半小时 24/7 自动创建和删除所有推荐的索引。实施时,数据库大约为 40GB,但由于我们是一家高度事务化的公司,因此已增长到超过 1TB。使用其中一个数据库 运行 我们的主要 ERP/ordering 系统。从我对索引的理解来看,这似乎是一个糟糕的主意,因为它可能会在非常大的表上创建和删除索引。这是一个好习惯吗,我是不是漏掉了什么?

在相关 post

中找到这个

"How to use it? Run AutoIndex.sql to install the SPs and sql agent job. Upon every 30 minutes, the sql agent job will run the auto create index and auto drop index scripts to make recommendations. Same recommendation will not be stored multiple times, instead we just bump up the count and change the latest recommendation time. You can view the recommendations using the simple commands in the viewrecommendations.sql. Look for the recommendations in the recommendation table that have high counts, which means they have been repetitively recommended thus are more valuable. You can also look at the initial recommendation time and the last recommendation time to get a sense of the freshness and the time range this recommendation is valid for. After you made a decision to implement a recommendation, simply run execute_recommendation with the recommendation id and the recommendation will be implemented automatically." Thank U Snehal

Link Here

根据该用户的说法,您在系统中执行的脚本应该只是随着时间的推移汇总索引建议,并允许您也看到不断推荐哪些索引。

我认为这里的重要区别是 SQL 不会记录它建议特定索引的次数,因此您可能会根据一次性查询获得建议的索引,这可能不是您想要的想要实施。相反,您 运行 这样做一段时间,然后查看经常被命中的内容并创建这些索引。