in-list iteratorsql
--針對目標sql的in後面是常量集合的首選項處理方法,其處理效率一般都會比in-list expansion高
--使用in-list iterator的時候,in所在列上必定要有索引
--能夠經過聯合設置10142和10157事件來禁掉in-list iterator,可是沒有hint來強制使用in-list iteratororacle
SQL> create table emp1 as select * from emp; SQL> create index idx_emp1_dept on emp1(deptno); SQL> select * from emp1 where deptno in (10,20,30); SQL> select * from table(dbms_xplan.display_cursor(null,null,'advanced')); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------- SQL_ID df7dw3ph8g0t7, child number 0 ------------------------------------- select * from emp1 where deptno in (10,20,30) Plan hash value: 2544692611 ---------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 2 (100)| | | 1 | INLIST ITERATOR | | | | | | | 2 | TABLE ACCESS BY INDEX ROWID| EMP1 | 14 | 1218 | 2 (0)| 00:00:01 | |* 3 | INDEX RANGE SCAN | IDX_EMP1_DEPT | 1 | | 1 (0)| 00:00:01 | ----------------------------------------------------------------------------------------------
oracle中in和or是等價的:優化
SQL> select * from emp1 where deptno=10 or deptno=20 or deptno=30; SQL> select * from table(dbms_xplan.display_cursor(null,null,'advanced')); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------- SQL_ID 2yya3cuswm15m, child number 0 ------------------------------------- select * from emp1 where deptno=10 or deptno=20 or deptno=30 Plan hash value: 2544692611 ---------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 2 (100)| | | 1 | INLIST ITERATOR | | | | | | | 2 | TABLE ACCESS BY INDEX ROWID| EMP1 | 14 | 1218 | 2 (0)| 00:00:01 | |* 3 | INDEX RANGE SCAN | IDX_EMP1_DEPT | 1 | | 1 (0)| 00:00:01 | ----------------------------------------------------------------------------------------------
刪除索引後就會走全表掃描,用不到INLIST ITERATOR的:.net
SQL> drop index idx_emp1_dept; SQL> select * from emp1 where deptno in (10,20,30); SQL> select * from table(dbms_xplan.display_cursor(null,null,'advanced')); PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------------------- SQL_ID df7dw3ph8g0t7, child number 0 ------------------------------------- select * from emp1 where deptno in (10,20,30) Plan hash value: 2226897347 -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 3 (100)| | |* 1 | TABLE ACCESS FULL| EMP1 | 14 | 1218 | 3 (0)| 00:00:01 | --------------------------------------------------------------------------
使用in-list iterator優化示例:http://blog.csdn.net/zengxuewen2045/article/details/52017297blog