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. ACM Longest Repeated Sequence

    Description You are given a sequence of integers, A = a1, a2, ... an. A consecutive subsequence of A ...

  2. HTML无刷新提交表单

    通常对于无刷新提交表单,我们都是运用ajax实现的.前段时间跟着老大了解到另一种无刷新提交表单的方法,是利用iframe框架实现的.现在整理出来分享给大家. 第一种: (html页面) <!DO ...

  3. 【bzoj1078】[SCOI2008]斜堆

    2016-05-31 16:34:09 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1078 挖掘斜堆的性质233 http://www.cp ...

  4. asp.net mvc4 HTTP Error 403.14

    asp.net mvc4项目部署到II&上时,出现HTTP Error 403.14 - Forbidden - The Web server is configured to not lis ...

  5. IOS 登陆判断问题

    有一个登陆界面,还有一个包含多个选项卡的界面在ViewController.m中登陆按钮的代码如下 UIViewController *controller=[[Tabbarcontroller al ...

  6. 线上Java应用排查和诊断规范

    @郑昀 整理 标准做法一:OOM触发HeadpDump 目的: OOM发生时,输出堆栈快照文件,供研发人员分析. 在JVM中,如果98%的时间是用于 GC 且可用的 Heap size 不足2%的时候 ...

  7. php 小试 mysql-zmq-plugin 和 pthreads

    原文: http://my.oschina.net/neochen/blog/294354 https://github.com/netkiller/mysql-zmq-plugin 有2张表: 表1 ...

  8. HTML第一节课

    html的基本结构<html> <head> <title> 页面标题 </title> </head> <boby> 页面内容 ...

  9. 常用js或jq效果汇总

    实时监控输入框改变    $('#password').bind('input propertychange', function() {}

  10. 房间安排-nyoj168

    描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间,在中国上海市举行.本次世博会也是由中国举办的首届世界博览会.上海世博会以“城市,让生活 ...