SQL question: Does the order of the WHERE clause make a difference?

前端 未结 6 747
谎友^
谎友^ 2020-12-16 11:56

From a performance standpoint, does the order of my SQL WHERE statements make a difference?

For instance

SELECT ... FROM ...
WHERE a > 1
AND b <         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 12:06

    It depends on the DBMS. SQL itself does not say anything about how a query should execute. It is up to the specific implementation.

    If your DBMS had the very simplistic model of interpreting the query sequentially, then putting a > 1 first in your example would (obviously) be faster - because the DBMS would make two passes of which the second pass is through a much smaller resultset.

提交回复
热议问题