ORACLE CBO 的 SQL 自动转换(Cost Based Transformations)之四
之前讲过的转换是当存在 View,子查询时,把子查询展开,或者把谓词下推给子查询。
那是不是说 CBO 只是盯着 View,或子查询来做工作呢,结论当然不是了。
比如2张表进行结合,并对其中一个表进行了 Group by 操作时,如果能先进行 Group by 的结果集再和另外的表进行结合的话,可能会有更好的效果。
于是乎,就有了Group By 配置最优机能(Group By Placement)。
Group By 配置最优机能(Group By Placement)
还是老样子,先看看最初没经过转换时的样子。
drop table t1 purge;
drop table t2 purge;
create table t1(c1 number, c2 number not null);
create table t2(c1 number, c2 number not null);
insert into t1 values (1,1);
insert into t1 values (1,2);
insert into t1 values (2,2);
insert into t2 values (1,2);
commit;
SQL> select sum(t1.c2), t2.c2
from t1,t2
where t1.c1 = t2.c1
group by t2.c2; 2 3 4
SUM(T1.C2) C2
---------- ----------