in-list expansion也被称作or expansion

--针对in后面是常量集合的另外一种处理方法。优化器会把目标sql中in后面的常量集合拆开,把里面的每个常量都提出来形成一个分支,各分支之间用union all来连接。即in-list expansion本质是把带in的目标sql等价写成union all连接的各个分支。

in-list expansion改写成union all连接分支后,各个分支可以各自走索引、分区裁剪、表连接等相关的执行计划而不互相干扰;缺点是,改写后,随着union all分支的递加,sql解析时间对增多。

#先禁掉in-list iterator特性
SQL> alter session set events '10142 trace name context forever';
SQL> alter session set events '10157 trace name context forever';
SQL> exec dbms_stats.gather_table_stats(ownname=>'SCOTT',tabname=>'EMP1',cascade=>true,no_invalidate=>false);
SQL> select /*+ use_concat +*/ * from emp1 where deptno in (10,20,30);
SQL> select * from table(dbms_xplan.display_cursor(null,null,'advanced')); PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------
SQL_ID 2nk52krswqkxk, child number 0
-------------------------------------
select /*+ use_concat +*/ * from emp1 where deptno in (10,20,30) Plan hash value: 1141053746 ----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 6 (100)| |
| 1 | CONCATENATION | | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP1 | 3 | 114 | 2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | IDX_EMP1_DEPT | 3 | | 1 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| EMP1 | 5 | 190 | 2 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | IDX_EMP1_DEPT | 5 | | 1 (0)| 00:00:01 |
| 6 | TABLE ACCESS BY INDEX ROWID| EMP1 | 6 | 228 | 2 (0)| 00:00:01 |
|* 7 | INDEX RANGE SCAN | IDX_EMP1_DEPT | 6 | | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id):
------------------------------------------------------------- 1 - SEL$1
2 - SEL$1_1 / EMP1@SEL$1
3 - SEL$1_1 / EMP1@SEL$1
4 - SEL$1_2 / EMP1@SEL$1_2
5 - SEL$1_2 / EMP1@SEL$1_2
6 - SEL$1_3 / EMP1@SEL$1_3
7 - SEL$1_3 / EMP1@SEL$1_3 ...... Predicate Information (identified by operation id):
--------------------------------------------------- 3 - access("DEPTNO"=10)
5 - access("DEPTNO"=20)
7 - access("DEPTNO"=30)

in-list expansion后,上面的语句其实被改写成下面的格式了:

select * from emp1 where deptno=10
union all
select * from emp1 where deptno=20
union all
select * from emp1 where deptno=30
union all;

要想优化器不走in-list expansion,需要使用no_expand hint

SQL> select /*+ no_expand +*/ * from emp1 where deptno in (10,20,30);
SQL> select * from table(dbms_xplan.display_cursor(null,null,'advanced')); PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------
SQL_ID akwm5wds8km03, child number 0
-------------------------------------
select /*+ no_expand +*/ * 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 | 10 | 380 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------

  

对于in后面常量集合中所含元素数量非常多的情形(或or条件比较多的sql,OR关联词在CBO解析时,会变形(EXPAND)为UNION ALL的关联语句),可以考虑以下的优化方案:
1.使用no_expand hint不让cbo走in-list expansion类型的执行计划
2.将in后面的常量集合存储在一个中间表里,并将原始目标sql中的in改写成和这个表中间表做表连接

可以参考别人的优化示例:http://blog.itpub.net/26687597/viewspace-1207432/

in-list expansion的更多相关文章

  1. Protecting against XML Entity Expansion attacks

    https://blogs.msdn.microsoft.com/tomholl/2009/05/21/protecting-against-xml-entity-expansion-attacks/ ...

  2. BigDecimal除法运算出现java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result的解决办法

    BigDecimal除法运算出现java.lang.ArithmeticException: Non-terminating decimal expansion; no exact represent ...

  3. Project Euler 80:Square root digital expansion 平方根数字展开

    Square root digital expansion It is well known that if the square root of a natural number is not an ...

  4. poj 3168 Barn Expansion 几何yy

    题链:http://poj.org/problem? id=3168 Barn Expansion Time Limit: 1000MS   Memory Limit: 65536K Total Su ...

  5. poj3358 Period of an Infinite Binary Expansion

    Period of an Infinite Binary Expansion 题目大意:给你一个分数,求这个分数二进制表示下从第几位开始循环,并求出最小循环节长度. 注释:int范围内. 想法:这题说 ...

  6. expansion pattern ‘Frame&’ contains no argument packs

    camera/CameraImpl.h::: error: expansion pattern ‘Frame&’ contains no argument packs void read_fr ...

  7. UVA12627-Erratic Expansion(递归)

    Problem UVA12627-Erratic Expansion Accept: 465  Submit: 2487Time Limit: 3000 mSec Problem Descriptio ...

  8. 论文笔记系列-Multi-Fidelity Automatic Hyper-Parameter Tuning via Transfer Series Expansion

    论文: Multi-Fidelity Automatic Hyper-Parameter Tuning via Transfer Series Expansion 我们都知道实现AutoML的基本思路 ...

  9. Codeforces 799D Field expansion(随机算法)

    Field expansion [题目链接]Field expansion [题目类型]随机化算法 &题解: 参考自:http://www.cnblogs.com/Dragon-Light/p ...

随机推荐

  1. CDOJ 1431 不是图论 Label:Tarjan || Kosarajn

    Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Description 给出一个nn个点, ...

  2. 【BZOJ】3456: 城市规划

    http://www.lydsy.com/JudgeOnline/problem.php?id=3456 题意:求n个点的无向连通图的方案.(n<=130000) #include <bi ...

  3. HDU 4750 Count The Pairs(并查集)

    题目链接 没有发现那个点,无奈. #include <cstdio> #include <cstring> #include <cmath> #include &l ...

  4. Android -- 自定义ImageView(圆形头像)

    1.  原图

  5. 升级OS X EI Capition 版本导致cocoapods 使用终端上pod: command not found

    1)安装过cocoapods, 那么输入 : sudo gem install -n /usr/local/bin cocoapods 当然 上个步骤解决了我的 难题 2)首先在终端输入 gem so ...

  6. 纪念逝去的岁月——C/C++选择排序

    选择排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...

  7. Node.js 手册查询-1-核心模块方法

    Node.js 学习手册 标签(空格分隔): node.js 模块 核心模块 核心模块是被编译成二进制代码,引用的时候只需require表示符即可 os 系统基本信息 os模块可提供操作系统的一些基本 ...

  8. MongoDB数据库的简介及安装

    一.MongoDB数据库简介 简介 MongoDB是一个高性能,开源,无模式的,基于分布式文件存储的文档型数据库,由C++语言编写,其名称来源取自“humongous”,是一种开源的文档数据库──No ...

  9. nginx和tomcat实现反向代理、负载均衡和session共享

    这类的文章很多,nginx和tomcat实现反向代理.负载均衡实现很容易,可以参照http://blog.csdn.net/liuzhigang1237/article/details/8880752 ...

  10. JS写四个图片滚动显示的效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...