对于 SQL 查询,仅使用书签查找选项进行索引查找?

发布于 2024-07-13 23:15:18 字数 404 浏览 5 评论 0原文

我正在努力优化一个针对遗留系统中非常宽的表的 SQL 查询。 由于各种原因,我目前无法缩小表格范围。

我的查询运行缓慢,因为它对我创建的索引执行索引查找,然后使用书签查找来查找索引中不存在的所需其他列。 书签查找占用了 42% 的查询时间(根据查询优化器)。

该表有 38 列,其中一些是 nvarchar,因此我无法创建包含所有列的覆盖索引。 我试图通过创建覆盖所有列的索引来利用索引交集,但是这些“覆盖”索引不会被执行计划拾取并且不会被使用。

另外,由于 38 列中的 28 列是通过此查询提取的,因此表中的 28/38 列存储在这些覆盖索引中,因此我不确定这会有多大帮助。

您认为书签查找功能是否足够好,或者其他选择是什么?

(我应该指定这是 SQL Server 2000)

I am working on optimizing a SQL query that goes against a very wide table in a legacy system. I am not able to narrow the table at this point for various reasons.

My query is running slowly because it does an Index Seek on an Index I've created, and then uses a Bookmark Lookup to find the additional columns it needs that do not exist in the Index. The bookmark lookup takes 42% of the query time (according to the query optimizer).

The table has 38 columns, some of which are nvarchars, so I cannot make a covering index that includes all the columns. I have tried to take advantage of index intersection by creating indexes that cover all the columns, however those "covering" indexes are not picked up by the execution plan and are not used.

Also, since 28 of the 38 columns are pulled out via this query, I'd have 28/38 of the columns in the table stored in these covering indexes, so I'm not sure how much this would help.

Do you think a Bookmark Lookup is as good as it is going to get, or what would another option be?

(I should specify that this is SQL Server 2000)

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

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

发布评论

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

评论(2

呆° 2024-07-20 23:15:18

哦,

包含的覆盖索引应该可以工作。 另一种选择可能是创建一个仅包含您需要的列的聚集索引视图

问候,
利文

OH,

the covering index with include should work. Another option might be to create a clustered indexed view containing only the columns you need.

Regards,
Lieven

病女 2024-07-20 23:15:18

您可以创建包含列的索引作为

BOL 的另一个选项示例,这是 2005 年及以上的版本

CREATE NONCLUSTERED INDEX IX_Address_PostalCode
    ON Person.Address (PostalCode)
    INCLUDE (AddressLine1, AddressLine2, City, StateProvinceID);

要回答这部分“我尝试通过创建覆盖所有列的索引来利用索引交集,但是那些“覆盖”索引没有被执行计划采纳并且没有被使用。”
仅当以可控制的方式创建查询时才能使用索引,换句话说,如果您在运算符左侧使用函数或在 WHERE 子句中省略索引的第一列,则索引将获胜不被利用。 如果索引的选择性较低,则也不会使用索引

查看 SQL Server 覆盖索引 了解更多信息

You could create an index with included columns as another option

example from BOL, this is for 2005 and up

CREATE NONCLUSTERED INDEX IX_Address_PostalCode
    ON Person.Address (PostalCode)
    INCLUDE (AddressLine1, AddressLine2, City, StateProvinceID);

To answer this part "I have tried to take advantage of index intersection by creating indexes that cover all the columns, however those "covering" indexes are not picked up by the execution plan and are not used."
An index can only be used when the query is created in a way that it is sargable, in other words if you use function on the left side of the operator or leave out the first column of the index in your WHERE clause then the index won't be used. If the selectivity of the index is low then also the index won't be used

Check out SQL Server covering indexes for some more info

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