Which SQL query is faster? Filter on Join criteria or Where clause?

前端 未结 9 954
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 03:36

Compare these 2 queries. Is it faster to put the filter on the join criteria or in the WHERE clause. I have always felt that it is faster on the join criteria b

相关标签:
9条回答
  • 2020-11-27 04:13

    It is really unlikely that the placement of this join will be the deciding factor for performance. I am not intimately familiar with the execution planning for tsql, but it's likely that they will be optimized automatically to similar plans.

    0 讨论(0)
  • 2020-11-27 04:16

    As far as the two methods go.

    • JOIN/ON is for joining tables
    • WHERE is for filtering results

    Whilst you can use them differently it always seems like a smell to me.

    Deal with performance when it is a problem. Then you can look into such "optimisations".

    0 讨论(0)
  • 2020-11-27 04:17

    Rule #0: Run some benchmarks and see! The only way to really tell which will be faster is to try it. These types of benchmarks are very easy to perform using the SQL profiler.

    Also, examine the execution plan for the query written with a JOIN and with a WHERE clause to see what differences stand out.

    Finally, as others have said, these two should be treated identically by any decent optimizer, including the one built into SQL Server.

    0 讨论(0)
提交回复
热议问题