简体   繁体   English

Indexaphobia:高值缺失索引,但已经有双非聚集键

[英]Indexaphobia: High Value Missing Index but has dual nonclustered key already

[dbo].[sp_BlitzIndex] is showing a Indexaphobia: High Value Missing Index for this table but the table has a non clustered index on both columns. [dbo].[sp_BlitzIndex]显示Indexaphobia: High Value Missing Index for this table,但该表在两列上都有非聚集索引。 Is this still needed?这还需要吗?

INEQUALITY:  [TeamId]  {int} INCLUDE:  [PlayerId]  {int} 

This is a suggestion based on the info provided - but to confirm这是基于提供的信息的建议 - 但要确认

  • You have one index on TeamID您在TeamID上有一个索引
  • You have another index on PlayerId您在PlayerId上有另一个索引

If this is the case, I think the suggested index wants both fields in the one index.如果是这种情况,我认为建议的索引需要一个索引中的两个字段。

If it's in two indexes, the query would need to do a lot of reads to 'join' both indexes.如果它在两个索引中,则查询需要进行大量读取才能“加入”两个索引。 Instead, if it's in one index (eg, index on TeamID, including PlayerID) then it won't need to go through that matching process.相反,如果它在一个索引中(例如,TeamID 上的索引,包括 PlayerID),那么它不需要通过该匹配过程来 go。

I suggest modifying your index on TeamID to also include PlayerID.我建议修改您在 TeamID 上的索引以包括 PlayerID。 It's only an int so it won't add much to the size.它只是一个 int,所以它不会增加太多的大小。

It could also be useful trying to find the query that looks at those fields so you can test before-and-after (potentially a query joining Teams with Players).尝试查找查看这些字段的查询也可能很有用,这样您就可以在前后进行测试(可能是加入 Teams with Players 的查询)。

Edit: To understand how this works, the developer of sp_Blitz (Brent Ozar) has a fantastic video called How to think like the SQL Server Engine .编辑:为了了解这是如何工作的,sp_Blitz (Brent Ozar) 的开发人员有一个精彩的视频,名为How to think like the SQL Server Engine I highly recommend it - it took my understanding of indexes to a much higher level.我强烈推荐它——它使我对索引的理解更上一层楼。

Edit2: I suggest trying having it not just as an 'include' but as the second field in the index - so it would be sorted by PlayerID as well. Edit2:我建议尝试不仅将其作为“包含”,而且将其作为索引中的第二个字段-因此它也将按 PlayerID 排序。 Also note that your question, on re-reading, suggests the query that could use the index is likely one where you are looking for players not in a given team.另请注意,在重新阅读时,您的问题表明可以使用索引的查询很可能是您正在寻找不在给定球队中的球员的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM