SQL Server 会自动丢弃不必要的连接吗?

发布于 2024-09-11 17:47:03 字数 180 浏览 2 评论 0原文

如果我向 SQL Server 2005 提交一个查询,其中包含许多 LEFT JOIN 子句,而其中所连接的表从未被引用,那么连接是否仍然会发生,或者 SQL Server 是否足够智能以丢弃它们?

显然它不能丢弃 INNER JOIN [错误的假设!请参阅答案],因为这可能会改变结果,但是它可以用于 LEFT JOIN 吗?

If I submit a query to SQL Server 2005 which contains a number of LEFT JOIN clauses where the table joined to is then never referenced, will the joins still happen or is SQL Server intelligent enough to discard them?

Obviously it wouldn't be able to discard INNER JOINs [false assumption! see answers] as that would potentially change the result, but can it do it for LEFT JOINs?

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

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

发布评论

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

评论(2

梦忆晨望 2024-09-18 17:47:03

可以通过检查约束来丢弃 INNER JOIN 和 LEFT JOIN。如果您不使用表中的列,并且通过 (FK) 约束保证单行存在,则不需要使用该表。显然,这取决于查询,该表可能仍然被使用,因为它是最佳计划。

这是约束非常有用并且应该的另一个原因比设计中经常考虑的频率更高。

It can discard both INNER and LEFT JOINs by inspecting the constraints. If you don't use a column in the table and there is a guaranteed single row existence by (FK) constraint, then the table does not need to be used. Obviously it depends on the query, it's possible that the table still gets used because it's the best plan.

This is yet another reason that constraints are tremendously useful and should be considered more frequently than they often are in designs.

等数载,海棠开 2024-09-18 17:47:03

如果有很多匹配项,左连接可能会增加结果集。

因此仍然会对其进行评估。

A left join could potentially multiply your result set if there are many matches.

So therefore it would still be evaluated.

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