且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server:完全外部联接的顺序重要吗?

更新时间:2023-01-20 11:38:00

否,重新排列JOIN顺序不应影响性能. MSSQL(与其他DBMS一样)具有查询优化器,其作用是查找效率最高的查询计划任何给定的查询.通常,这些功能做得很好-因此,您不太可能轻易击败优化程序.

No, rearranging the JOIN orders should not affect the performance. MSSQL (as with other DBMS) has a query optimizer whose job it is to find the most efficient query plan for any given query. Generally, these do a pretty good job - so you're unlikely to beat the optimizer easily.

也就是说,他们偶尔会弄错它.这就是读取执行计划发挥作用的地方.您可以添加 JOIN提示来告诉MSSQL如何联接表(在排序确实重要).通常,您会从最小到最大的表进行排序(尽管使用FULL JOIN,这不太可能有太大关系),并遵循

That said, they do get it wrong occasionally. That's where reading an execution plan comes into play. You can add JOIN hints to tell MSSQL how to join your tables (at which point, ordering does matter). You'd generally order from smallest to largest table (though, with a FULL JOIN, it's not likely to matter very much) and follow the rules of thumb for join types.

由于您正在执行FULL JOINS,因此基本上可以从磁盘上读取全部4个表.那可能很昂贵.您可能需要重新检查该问题,并查看是否可以通过其他方式解决.

Since you're doing FULL JOINS, you're basically reading the entirety of 4 tables off disk. That's likely to be very expensive. You may want to re-examine the problem, and see if it can be accomplished in a different way.