Execution order of conditions in SQL 'where' clause

后端 未结 6 1379
温柔的废话
温柔的废话 2020-12-06 05:31

I have a set of conditions in my where clause like

WHERE 
d.attribute3 = \'abcd*\'  
AND x.STATUS != \'P\' 
AND x.STATUS != \'J\' 
AND x.STATUS != \'X\' 
AND         


        
6条回答
  •  清歌不尽
    2020-12-06 06:14

    To add to the other comments on execution plans, under the cpu-based costing model introduced in 9i and used by default in 10g+ Oracle will also make an assessment of which predicate evaluation order will result in lower computational cost even if that does not affect the table access order and method. If executing one predicate before another results in fewer predicates calculations being executed then that optimisaton can be applied.

    See this article for more details: http://www.oracle.com/technology/pub/articles/lewis_cbo.html

    Furthermore, Oracle doesn't even have to execute predicates where comparison with a check constraint or partition definitions indicates that no rows would be returned anyway.

    Complex stuff.

提交回复
热议问题