zl程序教程

您现在的位置是:首页 >  其他

当前栏目

深入SQL执行计划之CBO查询转换(7):Distinct 配置最优机能(Distinct Placement)

转换配置SQL执行 查询 深入 计划 最优
2023-06-13 09:11:17 时间

编者按:

本文作者系杨昱明,现就职于甲骨文公司,从事数据库方面的技术支持。希望能通过发表文章,把一些零散的知识再整理整理。个人主页:https://blog.csdn.net/weixin_50513167,经其本人授权发布。

【免责声明】本号文章仅代表个人观点,与任何公司无关。

编辑|SQL和数据库技术(ID:SQLplusDB)

CBO 查询转换系列(深入了解Oracle执行计划)

CBO 查询转换(1):子查询展开机能(Subquery Unnesting)

CBO 查询转换(2):反结合的NULL识别机能(null aware anti-join )

CBO 查询转换(3):结合谓词下推机能(Join Predicate Pushdown)

CBO 查询转换 (4):Group By 配置最优机能(Group By Placement)

CBO查询转换(5):星型转换(Star Transformation)

CBO查询转换(6):子查询关联集展开机能(unnest correlation set subquery)

同之前聊过的 Group By 配置最优机能同等的,还有 Distinct 配置最优机能(Distinct Placement)。

还是用下面的 Test case 进行简单的演示,说明一下 Distinct 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> SQL> select /*+ place_distinct(t2) */
      distinct t1.c2, t2.c2
from t1, t2
where t1.c1 = t2.c1;  2    3    4
 
        C2         C2
---------- ----------
         1          2
         2          2
 
 
Execution Plan
----------------------------------------------------------
Plan hash value: 107983552
 
-----------------------------------------------------------------------------------------
| Id  | Operation             | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |                 |     2 |   104 |     8  (25)| 00:00:01 |
|   1 |  HASH UNIQUE          |                 |     2 |   104 |     8  (25)| 00:00:01 |
|*  2 |   HASH JOIN           |                 |     2 |   104 |     7  (15)| 00:00:01 |
|   3 |    VIEW               | VW_DTP_AE9E49E8 |     1 |    26 |     4  (25)| 00:00:01 |
|   4 |     HASH UNIQUE       |                 |     1 |    26 |     4  (25)| 00:00:01 |
|   5 |      TABLE ACCESS FULL| T2              |     1 |    26 |     3   (0)| 00:00:01 |
|   6 |    TABLE ACCESS FULL  | T1              |     3 |    78 |     3   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
 
   2 - access("T1"."C1"="ITEM_1")
 
Note
-----
   - dynamic sampling used for this statement (level=2)

特征是使用了内部转换的试图 VW_DTP_*。

关闭此功能的方法是 "_optimizer_distinct_placement" = false。