确定索引是否已用作提示
在 SQL Server 中,可以选择使用查询提示。 例如,
SELECT c.ContactID
FROM Person.Contact c
WITH (INDEX(AK_Contact_rowguid))
我正在摆脱未使用的索引,并且想知道如何确定索引是否用作查询提示。有人对我如何做到这一点有建议吗?
干杯, 乔
In SQL Server, there is the option to use query hints.
eg
SELECT c.ContactID
FROM Person.Contact c
WITH (INDEX(AK_Contact_rowguid))
I am in the process of getting rid of unused indexes and was wondering how I could go about determining if an index was used as a query hint. Does anyone have suggestions on how I could do this?
Cheers,
Joe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只能运行客户端 SQL 的探查器或搜索 sys.sql_modules,否则。
要查找未使用的索引,您通常会使用基于 dmvs 的内容< /a>.这将向您显示哪些索引正在使用并且需要保留。
You can only run profiler for client SQL or search
sys.sql_modules
otherwise.To find unused indexes you'd normally use something based on dmvs. This would show you what indexes are in use and need to be kept.
这是一个很好的问题,我想我无法给你一个简单的答案。如果是我,我会在 Management Studio 中编写整个数据库的脚本,并对索引名称进行文本搜索。为了确定起见,我也会在我的所有报告和源代码中这样做。
我不认为提示会到达 procs 函数的 sys.dependency ,但即使有,您也可能需要处理一些临时 SQL,所以这就是我使用文本搜索路径的原因。
That's a great question, and I don't think I can give you an easy answer. If it were me, I would script th entire database in Management Studio and do a Text search for the index name. I would also do that in all of my reports and source code, just to be sure, too.
I don't think that hints make their way to sys.dependencies for procs an functions, but even if they did, you'd have some ad-hoc SQL to potentially deal with, so that's why I'd use the text searching route.