在Oracle中,举例说明“连接因式分解(Join factorization,JF)”查询转换。
♣ 答案部分
1LHR@orclasm > SELECT /*+FULL(A) FULL(B)*/ A.*,B.DNAME FROM SCOTT.EMP A,SCOTT.DEPT B WHERE A.DEPTNO=B.DEPTNO AND A.EMPNO=6
2 2 UNION ALL
3 3 SELECT /*+FULL(A) FULL(B)*/ A.*,B.DNAME FROM SCOTT.EMP A,SCOTT.DEPT B WHERE A.DEPTNO=B.DEPTNO AND A.EMPNO=7;
4
5no rows selected
6
7
8Execution Plan
9----------------------------------------------------------
10Plan hash value: 1245103347
11
12-------------------------------------------------------------------------------------------
13| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
14-------------------------------------------------------------------------------------------
15| 0 | SELECT STATEMENT | | 2 | 244 | 8 (13)| 00:00:01 |
16|* 1 | HASH JOIN | | 2 | 244 | 8 (13)| 00:00:01 |
17| 2 | VIEW | VW_JF_SET$623BBB07 | 2 | 200 | 4 (0)| 00:00:01 |
18| 3 | UNION-ALL | | | | | |
19|* 4 | TABLE ACCESS FULL| EMP | 1 | 87 | 2 (0)| 00:00:01 |
20|* 5 | TABLE ACCESS FULL| EMP | 1 | 87 | 2 (0)| 00:00:01 |
21| 6 | TABLE ACCESS FULL | DEPT | 4 | 88 | 3 (0)| 00:00:01 |
22-------------------------------------------------------------------------------------------
23
24Predicate Information (identified by operation id):
25---------------------------------------------------
26
27 1 - access("ITEM_1"="B"."DEPTNO")
28 4 - filter("A"."EMPNO"=6)
29 5 - filter("A"."EMPNO"=7)
30
31Note
32-----
33 - dynamic sampling used for this statement (level=2)
34
35
36Statistics
37----------------------------------------------------------
38 99 recursive calls
39 7 db block gets
40 32 consistent gets
41 0 physical reads
42 4536 redo size
43 866 bytes sent via SQL*Net to client
44 509 bytes received via SQL*Net from client
45 1 SQL*Net roundtrips to/from client
46 0 sorts (memory)
47 0 sorts (disk)
48 0 rows processed
49
50LHR@orclasm > ALTER SESSION SET "_OPTIMIZER_JOIN_FACTORIZATION"=FALSE;
51
52Session altered.
53
54LHR@orclasm > SELECT /*+FULL(A) FULL(B)*/ A.*,B.DNAME FROM SCOTT.EMP A,SCOTT.DEPT B WHERE A.DEPTNO=B.DEPTNO AND A.EMPNO=6
55 2 UNION ALL
56 3 SELECT /*+FULL(A) FULL(B)*/ A.*,B.DNAME FROM SCOTT.EMP A,SCOTT.DEPT B WHERE A.DEPTNO=B.DEPTNO AND A.EMPNO=7;
57
58no rows selected
59
60
61Execution Plan
62----------------------------------------------------------
63Plan hash value: 2703228680
64
65----------------------------------------------------------------------------
66| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
67----------------------------------------------------------------------------
68| 0 | SELECT STATEMENT | | 2 | 218 | 8 (50)| 00:00:01 |
69| 1 | UNION-ALL | | | | | |
70| 2 | NESTED LOOPS | | 1 | 109 | 4 (0)| 00:00:01 |
71|* 3 | TABLE ACCESS FULL| EMP | 1 | 87 | 2 (0)| 00:00:01 |
72|* 4 | TABLE ACCESS FULL| DEPT | 82 | 1804 | 2 (0)| 00:00:01 |
73| 5 | NESTED LOOPS | | 1 | 109 | 4 (0)| 00:00:01 |
74|* 6 | TABLE ACCESS FULL| EMP | 1 | 87 | 2 (0)| 00:00:01 |
75|* 7 | TABLE ACCESS FULL| DEPT | 82 | 1804 | 2 (0)| 00:00:01 |
76----------------------------------------------------------------------------
77
78Predicate Information (identified by operation id):
79---------------------------------------------------
80
81 3 - filter("A"."EMPNO"=6)
82 4 - filter("A"."DEPTNO"="B"."DEPTNO")
83 6 - filter("A"."EMPNO"=7)
84 7 - filter("A"."DEPTNO"="B"."DEPTNO")
85
86
87Statistics
88----------------------------------------------------------
89 93 recursive calls
90 7 db block gets
91 14 consistent gets
92 0 physical reads
93 4536 redo size
94 866 bytes sent via SQL*Net to client
95 509 bytes received via SQL*Net from client
96 1 SQL*Net roundtrips to/from client
97 0 sorts (memory)
98 0 sorts (disk)
99 0 rows processed
本文选自《Oracle程序员面试笔试宝典》,作者:李华荣。
---------------优质麦课------------
详细内容可以添加麦老师微信或QQ私聊。
● 本文作者:小麦苗,只专注于数据库的技术,更注重技术的运用
● 作者博客地址:http://blog.itpub.net/26736162/abstract/1/
● 本系列题目来源于作者的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解
● 版权所有,欢迎分享本文,转载请保留出处
● QQ:646634621 QQ群:618766405
● 提供OCP、OCM和高可用部分最实用的技能培训
● 题目解答若有不当之处,还望各位朋友批评指正,共同进步
长按下图识别二维码或微信扫描下图二维码来关注小麦苗的微信公众号:xiaomaimiaolhr,学习最实用的数据库技术。
本文分享自微信公众号 - DB宝(lhrdba)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。