在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 UNION ALL SELECT /*+FULL(A) FULL(B)*/ A.*,B.DNAME FROM SCOTT.EMP A,SCOTT.DEPT B WHERE A.DEPTNO=B.DEPTNO AND A.EMPNO=7; 5no rows selected 8Execution Plan 9---------------------------------------------------------- 10Plan hash value: 1245103347 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------------------------------------------------------------------------------------------- 24Predicate Information (identified by operation id): 25--------------------------------------------------- 1 - access("ITEM_1"="B"."DEPTNO") - filter("A"."EMPNO"=6) - filter("A"."EMPNO"=7) 31Note 32----- - dynamic sampling used for this statement (level=2) 36Statistics 37---------------------------------------------------------- recursive calls db block gets consistent gets physical reads redo size bytes sent via SQL*Net to client bytes received via SQL*Net from client SQL*Net roundtrips to/from client sorts (memory) sorts (disk) rows processed 50LHR@orclasm > ALTER SESSION SET "_OPTIMIZER_JOIN_FACTORIZATION"=FALSE; 52Session altered. 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 UNION ALL SELECT /*+FULL(A) FULL(B)*/ A.*,B.DNAME FROM SCOTT.EMP A,SCOTT.DEPT B WHERE A.DEPTNO=B.DEPTNO AND A.EMPNO=7; 58no rows selected 61Execution Plan 62---------------------------------------------------------- 63Plan hash value: 2703228680 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---------------------------------------------------------------------------- 78Predicate Information (identified by operation id): 79--------------------------------------------------- 3 - filter("A"."EMPNO"=6) - filter("A"."DEPTNO"="B"."DEPTNO") - filter("A"."EMPNO"=7) - filter("A"."DEPTNO"="B"."DEPTNO") 87Statistics 88---------------------------------------------------------- recursive calls db block gets consistent gets physical reads redo size bytes sent via SQL*Net to client bytes received via SQL*Net from client SQL*Net roundtrips to/from client sorts (memory) sorts (disk) rows processed
本文选自《Oracle程序员面试笔试宝典》,作者:李华荣。
详细内容可以添加麦老师微信或QQ私聊。
● 本文作者:小麦苗,只专注于数据库的技术,更注重技术的运用
● 作者博客地址:http://blog.itpub.net/26736162/abstract/1/
● 本系列题目来源于作者的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解
● 版权所有,欢迎分享本文,转载请保留出处
● QQ:646634621 QQ群:618766405
● 提供OCP、OCM和高可用部分最实用的技能培训
● 题目解答若有不当之处,还望各位朋友批评指正,共同进步
DBA宝典
长按下图识别二维码或微信扫描下图二维码来关注小麦苗的微信公众号:xiaomaimiaolhr,学习最实用的数据库技术。
本文分享自微信公众号 - DB宝(lhrdba)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。