Sql JOIN 顺序会影响性能吗? [英] Does Sql JOIN order affect performance?

查看:64
本文介绍了Sql JOIN 顺序会影响性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我遇到这个查询时,我只是在整理一些 sql:

I was just tidying up some sql when I came across this query:

SELECT 
        jm.IMEI ,
        jm.MaxSpeedKM ,
        jm.MaxAccel ,
        jm.MaxDeccel ,
        jm.JourneyMaxLeft ,
        jm.JourneyMaxRight ,
        jm.DistanceKM ,
        jm.IdleTimeSeconds ,
        jm.WebUserJourneyId ,
        jm.lifetime_odo_metres ,
        jm.[Descriptor]
FROM    dbo.Reporting_WebUsers AS wu WITH (NOLOCK)
        INNER JOIN dbo.Reporting_JourneyMaster90 AS jm WITH (NOLOCK) ON wu.WebUsersId = jm.WebUsersId
        INNER JOIN dbo.Reporting_Journeys AS j WITH (NOLOCK) ON jm.WebUserJourneyId = j.WebUserJourneyId
WHERE   ( wu.isActive = 1 )
        AND ( j.JourneyDuration > 2 )
        AND ( j.JourneyDuration < 1000 )
        AND ( j.JourneyDistance > 0 )

我的问题是,对于我会做的上述查询,连接顺序是否会对性能产生任何影响

My question is does it make any performance difference the order of the joins as for the above query I would have done

FROM dbo.Reporting_JourneyMaster90 AS jm

然后将其他 2 个表加入到那个表中

and then joined the other 2 tables to that one

推荐答案

不会,JOIN by order 是在优化过程中改变的.

No, the JOIN by order is changed during optimization.

唯一需要注意的是选项 FORCE ORDER 将强制加入以您指定的确切顺序发生.

The only caveat is the Option FORCE ORDER which will force joins to happen in the exact order you have them specified.

这篇关于Sql JOIN 顺序会影响性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆