about me:oracle ace pro,optimistic,passionate and harmonious. focus on oracle,mysql and other database programming,peformance tuning,db design, j2ee,linux/aix,architecture tech,etc
全部博文(166)
分类: oracle
2020-09-30 16:32:19

标量子查询特点:子查询执行次数依赖于连接列distinct数目,重复值越多,效率越好
反之,效率差。
从上面执行计划可以看出,虽然驱动的a-rows有108k行,但是因为distinct数目是11,实际上标量子查询只执行11次,由此可以看出,oracle内部构建了缓存存储键值对,从而减少子查询执行次数,达到优化目的。

|
select dname, (select max(b.sal) from scott.emp b where b.deptno = a.deptno) from scott.dept a;
|

只对于max,min,avg单个有效(类似max||min等组合的无效),对count、查询列等无效,受参数_optimizer_unnest_scalar_sq控制。