本帖最后由 bell6248 于 2011-11-15 11:34 编辑
Oracle解析where条件是根据条件的优先级的高低解析的, 不是根据书写条件顺序的, 也就是你说的到底是“从左到右, 还是从右到左” , 在CBO中没有这种规则,但在RBO中是有规则的,但是目前RBO已经被弃用了!
你看看如下的执行计划Predicate Information, 就就明白了!
SQL> select * from emp where deptno = 10 or (deptno !=10 and job = 'CLERK');
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6 | 192 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMP | 6 | 192 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("DEPTNO"=10 OR "JOB"='CLERK' AND "DEPTNO"<>10)
SQL> select * from emp where deptno = 10 or job = 'CLERK';
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 7 | 224 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMP | 7 | 224 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("DEPTNO"=10 OR "JOB"='CLERK')
SQL>