SQL Server 中的复合索引与 INCLUDE 覆盖索引
我知道复合索引总是从左到右使用(例如,如果索引位于城市、州,WHERE City = "Blah" 或 WHERE City = "Blah" AND State = "AA" 可以正常工作,但 WHERE State = "AA “不会)。
同样的原则也适用于 INCLUDE 索引吗?
提前致谢!
黏土
I understand that Composite Indexes are always used Left to Right (e.g. if an Index was on City, State, WHERE City = "Blah" or WHERE City = "Blah" AND State = "AA" would work fine but WHERE State = "AA" would not).
Does this same principle apply to INCLUDE indexes?
Thanks in advance!
Clay
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
包含列只能用于向查询的 SELECT 部分提供列。它们不能用作过滤索引的一部分。
编辑:为了进一步阐明我的观点,请考虑以下示例:
我创建一个简单的表并填充它:
现在考虑一个简单 SELECT 的这 3 个索引及其相应的执行计划。
情况 1:仅 ID 上的索引会导致表扫描。
情况 2:包含名称的 ID 索引。稍微好一些,因为索引覆盖了查询,但我仍然得到了 SCAN 操作。
情况 3:包含 ID 的 Name 索引。这是最好的。索引是建立在我的 WHERE 子句中的列上的,因此我得到了 SEEK 操作,并且由于包含列,索引覆盖了查询。
Include columns can only be used to supply columns to the
SELECT
portion of the query. They cannot be used as part of the index for filtering.EDIT: To further clarify my point, consider this example:
I create a simple table and populate it:
Now consider these 3 indexes and their corresponding execution plans for a simple SELECT.
Case 1: An index on just ID results in a TABLE SCAN.
Case 2: An index on ID including name. Somewhat better because the index covers the query, but I still get a SCAN operation.
Case 3: An index on Name including ID. This is the best. The index is built on the column in my WHERE clause, so I get a SEEK operation, and the index covers the query because of the included column.
不,包含字段未排序。
以下是一些其他设计注意事项:
http://msdn.microsoft.com/en-我们/library/ms190806.aspx
No, include fields are not ordered.
Here are some additional design considerations:
http://msdn.microsoft.com/en-us/library/ms190806.aspx