in-list iterator

in-list iterator

--针对目标sql的in后面是常量集合的首选项处理方法,其处理效率通常都会比in-list expansion高
--使用in-list iterator的时候,in所在列上一定要有索引
--可以通过联合设置10142和10157事件来禁掉in-list iterator,但是没有hint来强制使用in-list iterator

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的:

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/52017297

转载于:https://www.cnblogs.com/abclife/p/5992199.html

### Java List Iterator Usage and Example In Java, an `Iterator` is used to traverse through the elements of a collection object such as a `List`. The `Iterator` interface provides methods like `hasNext()`, which returns true if there are more elements in the iteration, and `next()`, which retrieves the next element in the sequence. For lists specifically, one can obtain an iterator by calling the `iterator()` method on any class implementing the `List` interface. Here’s how it works: ```java import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { public static void main(String[] args) { // Create a new ArrayList (which implements List) List<String> myList = new ArrayList<>(); // Add some items into our list myList.add("Apple"); myList.add("Banana"); myList.add("Orange"); // Obtain an Iterator instance from the List Iterator<String> myIterator = myList.iterator(); while(myIterator.hasNext()) { // Check whether there's another item available String fruit = myIterator.next(); // Get the current item System.out.println(fruit); // Print out each item found during traversal } } } ``` The above code snippet demonstrates obtaining an iterator using the `iterator()` method provided by classes that implement the `List` interface[^4]. Each call to `myIterator.next()` advances the cursor position within the underlying data structure until no further entries remain. Additionally, iterators support removal operations via their own `remove()` function without directly modifying the original container outside safe boundaries established when creating them. However, adding or removing elements elsewhere may throw exceptions due to concurrent modification issues unless explicitly supported by specialized implementations.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值