本文共 819 字,大约阅读时间需要 2 分钟。
随着Oracle版本的提升,优化器更趋向于智能,比如,12c中的标量子查询被transform成外连接。
select (select max(object_id) from test2 b where b.object_id =a.object_id) from test1 a;
11g中执行计划如下:
进入正题,当SQL中同时有or和子查询时,这种情况下查询无法展开(unnest),遇到这种情况只能改SQL来改变执行计划,并且在12c或18c中都没有智能改写。
select * from test1 where owner = 'SCOTT' or object_id in (select object_id from test2);
在不改写SQL的情况下我们在test2的join列上建立索引
create index idx_objid on test2(object_id);
下面用union改写sql
select * from test1 where owner = 'SCOTT' union select * from test1 where object_id in (select object_id from test2);
案例较为简单,希望通过此案例让大家了解优化器的一些行为,和unnest产生filter的一些情形。
| 作者简介
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28218939/viewspace-2221561/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28218939/viewspace-2221561/