A covered index formed by a composite index or index with included columns

三世轮回 提交于 2019-12-23 03:24:21

问题


Are there any differences between these two covered indexes?

  1. A composite index with both FriendID and UserID
  2. A index with FriendID and UserID as an included column

Separate MS SQL Server related point. If the answer to the above question is 'No difference', is it me or does the Database Engine Tuning Advisor (DTA) always go crazy on included columns?


回答1:


Yes, they are different.

  • An index on (A, B) will contain the A,B combination as the index key, meaning it shows up on every non-leaf page.
  • An index on (A) include (B) will contain only A as the index key, so B will be present only on leaf pages, while non-leaf pages will contain only A.

The difference implies that indexes on (A,B) are wider that indexes on (A) include (B) so they contain more non-leaf pages, generating a bigger index (more pages), more IO and hence less efficient.

However, an index (A,B) will always cover an index (A) include (B). So if you already have indexes on (A,B) and the Tunning Advisor recommends a new index on (A) include (B), somehting is fishy. Either with the DTA recommendation, either with your analysis of existing indexes. No offense, but on situations like this I tend to trust the DTA over the human analysis, so ensure that your indeed have indexes that already cover the DTA recommendation, including order and filters (for SQL 2008).



来源:https://stackoverflow.com/questions/1589818/a-covered-index-formed-by-a-composite-index-or-index-with-included-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!