如何强制 MS SQL Server 执行索引连接?

发布于 2024-07-15 00:59:18 字数 170 浏览 10 评论 0原文

我正在做一个作业,我应该比较 SQL Server 中的不同连接方法,即散列连接、合并连接和索引连接。

我在让 SQL Server 执行索引连接时遇到困难。 谁能告诉我如何强制它使用索引连接(使用连接提示或类似的),或者只是简单地提供一个带有连接的简单查询,其中SQL Server使用索引连接方法?

I'm working on an assignment where I'm supposed to compare different join methods in SQL Server, namely hash-join, merge-join and index-join.

I'm having difficulties getting SQL Server to perform an index-join. Can anyone show me how I can force it to use an index-join (using a join hint or similar), or just simply provide a simple query with a join on which SQL server uses the index-join method?

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

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

发布评论

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

评论(3

帅的被狗咬 2024-07-22 00:59:18

You have Loop, hash and merge joins (BOL) only. No index joins.

For more than you ever needed to know, Craig Friedman's series on JOINs (he's one of the team that designed the relation engine for SQL Server)

余生一个溪 2024-07-22 00:59:18

您可以在直接选择上有索引提示,但我不确定相同的语法是否可用于连接。

SELECT blah FROM table WITH (INDEX (index_name))

您可以在非 ansi (?) 连接中使用它

SELECT blah FROM TABLE1, TABLE2
WHERE TABLE2.ForiegnKeyID = TABLE1.ID
WITH (INDEX (index_name))

并带有索引提示:

SELECT
    ticket.ticket_id
FROM
    purchased_tickets
JOIN   ticket WITH (INDEX ( ticket_ix3))
    ON ticket.original_ticket_id = purchased_tickets.ticket_id
       AND ticket.paid_for = 1
       AND ticket.punched = 0
WHERE  purchased_tickets.seller_id = @current_user
OPTION (KEEPFIXED PLAN); 

You can have an Index hint on straight select, but I'm not sure that the same syntax is available for a join.

SELECT blah FROM table WITH (INDEX (index_name))

you could use this in a non-ansi (?) join

SELECT blah FROM TABLE1, TABLE2
WHERE TABLE2.ForiegnKeyID = TABLE1.ID
WITH (INDEX (index_name))

Join with a index hint:

SELECT
    ticket.ticket_id
FROM
    purchased_tickets
JOIN   ticket WITH (INDEX ( ticket_ix3))
    ON ticket.original_ticket_id = purchased_tickets.ticket_id
       AND ticket.paid_for = 1
       AND ticket.punched = 0
WHERE  purchased_tickets.seller_id = @current_user
OPTION (KEEPFIXED PLAN); 
凹づ凸ル 2024-07-22 00:59:18

我在 SQL Server 中找不到此类术语。

http://en.wikipedia.org/wiki/Join_(SQL)#Join_algorithms< /a>

您是否只是在寻找使用索引的嵌套循环,从而导致索引查找?

I'm having trouble finding such terminology in SQL server.

http://en.wikipedia.org/wiki/Join_(SQL)#Join_algorithms

Are you just looking for a nested loop that uses indexes, resulting in an index seek?

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