sys.dm_db_missing_index_details 不返回任何行

发布于 2024-10-27 23:24:32 字数 276 浏览 4 评论 0原文

我尝试查看 sys.dm_db_missing_index_details 以检查 SQL Server 2005 数据库上是否缺少索引。它不返回任何行。

它有可能应该是空的,但可能性很小,因为我没有在任何表上添加任何索引(除了通过创建主键获得的索引)。我还针对它运行单元测试以及临时开发测试(使用 Linq to SQL),因此存在一些针对它的活动。

我需要打开此数据的捕获吗?

这是否仅在 SQL Server 2005 的某些版本上受支持?

预先感谢您提供的任何帮助。

I have tried to look at sys.dm_db_missing_index_details to check for missing indexes on my SQL Server 2005 database. It is returning no rows.

It is possible that it should be empty but highly unlikely as I have not added ANY indices on any table (except the ones you get by creating primary keys). I am also running unit tests as well as adhoc development tests (using Linq to SQL) against it so there is some activity against it.

Do I need to turn on the capturing of this data?

Is this only supported on certain editions of SQL Server 2005?

Thanks in advance for any efforts to help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无声静候 2024-11-03 23:24:33

另一种选择是直接查询计划缓存——这还有一个好处,就是它可以为您提供需要索引的查询。有一个相关的问题这里 -- BankZ 的答案有一个完整的 SQL 脚本来完成这项工作。

但它可能运行缓慢 - 计划采用 XML 格式,因此通过此查询,我们要求 SQL Server 执行大量 XML 工作而不是表工作。但它确实有效:-)

与主缺失索引表一样,如果 SQL Server 重新启动,计划缓存将被清除。

Another option is to query the plan cache directly -- this also has the benefit that it can get you the query that wants the index. There's a related question here on SO -- the answer from BankZ has a complete SQL script that does the job.

It may run slowly though - the plans are in XML format, so with this query, we're asking SQL Server to do lots of XML work rather than table work. But it does work :-)

And as with the main missing index table, the plan cache is cleared down if SQL Server is restarted.

怀里藏娇 2024-11-03 23:24:32

似乎默认情况下它是打开的 - 尽管检查您用于启动的任何快捷方式并确保它不是使用

来自 http://msdn.microsoft.com/en-us/library/ms345524(v=SQL.90).aspx< /a>

仅当通过 sqlservr 命令提示符实用程序使用 -x 参数启动 SQL Server 实例时,才能禁用此功能。

此外,您还想知道,如果 SQL Server 使用查询优化器,则在运行查询时会填充该表 - 该表在您重新启动 SQL Server 时会被清除

来自 http://msdn.microsoft.com/en -us/library/ms345434(v=SQL.90).aspx

sys.dm_db_missing_index_details 返回的信息会在查询优化器优化查询时更新,并且不会保留。丢失的索引信息仅保留到 SQL Server 重新启动为止。如果数据库管理员希望在服务器回收后保留丢失的索引信息,则应定期对丢失的索引信息进行备份。

最后,有一篇文章讨论了您可能知道或不知道的限制,但我会发布以防其他人遇到这篇文章并需要:http://msdn.microsoft.com/en-us/library/ms345485(v=SQL.90).aspx

我没有看到某些版本中缺少该功能的任何信息,但您将需要某些权限:

用户必须被授予 VIEW SERVER STATE 权限或任何暗示 VIEW SERVER STATE 权限的权限才能查询此动态管理视图。

It appears that it's on by default - although check any shortcut you are using to launch and make sure it's not launching with a -x

From http://msdn.microsoft.com/en-us/library/ms345524(v=SQL.90).aspx

This feature can only be disabled if an instance of SQL Server is started by using the -x argument with the sqlservr command-prompt utility.

Also you'll want to know that the table is populated as queries are run if SQL Server uses the query optimizer - this table is cleared when you restart SQL Server.

From http://msdn.microsoft.com/en-us/library/ms345434(v=SQL.90).aspx

Information returned by sys.dm_db_missing_index_details is updated when a query is optimized by the query optimizer, and is not persisted. Missing index information is kept only until SQL Server is restarted. Database administrators should periodically make backup copies of the missing index information if they want to keep it after server recycling.

Lastly there is an article that goes into the limitations here that you may or may not know about, but I'll post in case someone else happens across this post and needs: http://msdn.microsoft.com/en-us/library/ms345485(v=SQL.90).aspx

I didn't see anything about the feature being missing in some versions but you WILL need certain permissions:

Users must be granted the VIEW SERVER STATE permission or any permission that implies the VIEW SERVER STATE permission to query this dynamic management view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文