[20160220]关于连接顺序2.txt

[20160220]关于连接顺序2.txt

--前几天被问一个问题,如果使用外连接的情况,连接顺序可以改变吗?我只能说我给测试看看,再回答这个问题:
--链接测试已经说明存在外连接的情况下,无法改变连接顺序的。

--今天想想忘记考虑全连接的情况,继续测试:

1.环境:
SCOTT@test01p> @ ver1

PORT_STRING                    VERSION        BANNER                                                                               CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0           12.1.0.1.0     Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

2.首先看看上次测试执行的语句:

select  * from dept,emp where dept.deptno=emp.deptno(+) and emp.ename='KING';

--我提到实际上上面的语句没有使用外连接,通过10053事件看看:

SCOTT@test01p> @10053on 12
Session altered.

SCOTT@test01p> Select  * from dept,emp where dept.deptno=emp.deptno(+) and emp.ename='KING';
    DEPTNO DNAME          LOC                EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- -------------- ------------- ---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
        10 ACCOUNTING     NEW YORK            7839 KING       PRESIDENT            1981-11-17 00:00:00       5000                    10

SCOTT@test01p> @10053off
Session altered.

--看看转储,可以发现最终转换
Final query after transformations:******* UNPARSED QUERY IS *******

SELECT "DEPT"."DEPTNO" "DEPTNO","DEPT"."DNAME" "DNAME","DEPT"."LOC" "LOC","EMP"."EMPNO" "EMPNO","EMP"."ENAME" "ENAME","EMP"."JOB" "JOB","EMP"."MGR"
       "MGR","EMP"."HIREDATE" "HIREDATE","EMP"."SAL" "SAL","EMP"."COMM" "COMM","EMP"."DEPTNO" "DEPTNO"
  FROM "SCOTT"."DEPT" "DEPT","SCOTT"."EMP" "EMP"
 WHERE "DEPT"."DEPTNO" = "EMP"."DEPTNO"
   AND "EMP"."ENAME"   = 'KING'
kkoqbc: optimizing query block SEL$C30CFC9A (#0)

--可以发现外连接实际上是取消了.煮为了显示的需要,做了格式化处理.

3.看看全连接的情况:

select /*+ leading(emp dept) */  * from dept full join emp on dept.deptno=emp.deptno ;
select /*+ leading(emp dept) */  * from emp full join dept on dept.deptno=emp.deptno ;

Plan hash value: 51889263

--------------------------------------------------------------------------------------------------------------
| Id  | Operation             | Name     | E-Rows |E-Bytes| Cost (%CPU)| E-Time   |  OMem |  1Mem | Used-Mem |
--------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |          |        |       |     6 (100)|          |       |       |          |
|   1 |  VIEW                 | VW_FOJ_0 |     15 |  1755 |     6   (0)| 00:00:01 |       |       |          |
|*  2 |   HASH JOIN FULL OUTER|          |     15 |   870 |     6   (0)| 00:00:01 |  1321K|  1321K| 1060K (0)|
|   3 |    TABLE ACCESS FULL  | DEPT     |      4 |    80 |     3   (0)| 00:00:01 |       |       |          |
|   4 |    TABLE ACCESS FULL  | EMP      |     14 |   532 |     3   (0)| 00:00:01 |       |       |          |
--------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1 / from$_subquery$_003@SEL$2
   2 - SEL$1
   3 - SEL$1 / DEPT@SEL$1
   4 - SEL$1 / EMP@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   2 - access("DEPT"."DEPTNO"="EMP"."DEPTNO")

--以上2种写法执行计划都是一样.再来看看10053事件.

SCOTT@test01p> @ 10053on 12
Session altered.

Select /*+ leading(emp dept) */  * from dept full join emp on dept.deptno=emp.deptno ;

SCOTT@test01p> @ 10053off
Session altered.

--检查转储文件:

Final query after transformations:******* UNPARSED QUERY IS *******

SELECT /*+ LEADING ("EMP" "DEPT") */ "VW_FOJ_0"."DEPTNO_0" "DEPTNO","VW_FOJ_0"."DNAME_1"
       "DNAME","VW_FOJ_0"."LOC_2" "LOC","VW_FOJ_0"."EMPNO_3" "EMPNO","VW_FOJ_0"."ENAME_4" "ENAME","VW_FOJ_0"."JOB_5"
       "JOB","VW_FOJ_0"."MGR_6" "MGR","VW_FOJ_0"."HIREDATE_7" "HIREDATE","VW_FOJ_0"."SAL_8" "SAL","VW_FOJ_0"."COMM_9"
       "COMM","VW_FOJ_0"."DEPTNO_10" "DEPTNO"
  FROM (
        SELECT "DEPT"."DEPTNO" "DEPTNO_0","DEPT"."DNAME" "DNAME_1","DEPT"."LOC" "LOC_2","EMP"."EMPNO"
               "EMPNO_3","EMP"."ENAME" "ENAME_4","EMP"."JOB" "JOB_5","EMP"."MGR" "MGR_6","EMP"."HIREDATE"
               "HIREDATE_7","EMP"."SAL" "SAL_8","EMP"."COMM" "COMM_9","EMP"."DEPTNO" "DEPTNO_10"
          FROM "SCOTT"."EMP" "EMP"
          FULL OUTER JOIN "SCOTT"."DEPT" "DEPT"
    ON "DEPT"."DEPTNO" = "EMP"."DEPTNO") "VW_FOJ_0"

kkoqbc: optimizing query block SEL$1 (#0)

--提示无效,理论讲这个那个在前在后都可以.

SCOTT@test01p> EXECUTE SYS.DBMS_STATS.SET_TABLE_STATS (OWNNAME=>user, TABNAME=>'dept', NUMROWS=> 1000,NO_INVALIDATE=>false);
PL/SQL procedure successfully completed.

Select /*+ leading(emp dept) */  * from dept full outer join emp on dept.deptno=emp.deptno ;
Plan hash value: 3194568465
--------------------------------------------------------------------------------------------------------------
| Id  | Operation             | Name     | E-Rows |E-Bytes| Cost (%CPU)| E-Time   |  OMem |  1Mem | Used-Mem |
--------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |          |        |       |     6 (100)|          |       |       |          |
|   1 |  VIEW                 | VW_FOJ_0 |   3750 |   428K|     6   (0)| 00:00:01 |       |       |          |
|*  2 |   HASH JOIN FULL OUTER|          |   3750 |   212K|     6   (0)| 00:00:01 |  1048K|  1048K|  646K (0)|
|   3 |    TABLE ACCESS FULL  | EMP      |     14 |   532 |     3   (0)| 00:00:01 |       |       |          |
|   4 |    TABLE ACCESS FULL  | DEPT     |   1000 | 20000 |     3   (0)| 00:00:01 |       |       |          |
--------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1 / from$_subquery$_003@SEL$2
   2 - SEL$1
   3 - SEL$1 / EMP@SEL$1
   4 - SEL$1 / DEPT@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   2 - access("DEPT"."DEPTNO"="EMP"."DEPTNO")

--不知道使用什么提示改变全连接顺序.

时间: 2024-10-04 11:20:58

[20160220]关于连接顺序2.txt的相关文章

[20160330]关于连接顺序3.txt

[20160330]关于连接顺序3.txt --关于连接顺序,曾经写过两篇blog,链接如下: http://blog.itpub.net/267265/viewspace-1991306/ http://blog.itpub.net/267265/viewspace-1991787/ --今天才发现自己犯了一个严重错误,使用外连接的情况,连接顺序是可以改变的,以前的blog存在严重错误-(:) --还是通过例子来讲解: 1.环境: SCOTT@book> @ &r/ver1 PORT_ST

[20160219]关于连接顺序.txt

[20160219]关于连接顺序.txt --今天被问一个问题,如果使用外连接的情况,连接顺序可以改变吗?我只能说我给测试看看,再回答这个问题: 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- ------------------------------------------------

急用 万分感谢-C++顺序读取txt的问题

问题描述 C++顺序读取txt的问题 0,-1145.1,2037.8,-0,-494.02,0 0,-2285.2,4060.2,-0,-982.1,0 0,-3415.9,6063,-0,-1464.1,0 0,-4541.8,8048.5,-0,-1939,0 0,-5659.5,10018,-0,-2409.6,0 我想顺序的读取这样的数据,然后把每一行数据顺序赋给x y z a b c,然互按照行的顺序不断刷新 x y z a b c,请大神指导,我有个思路是用两个循环,但不知有什么好

SQL优化之针对count、表的连接顺序、条件顺序、in及exist的优化_oracle

本文详述了SQL优化中针对count.表的连接顺序.条件顺序.in及exist的优化,非常具有实用价值!详述如下: 一.关于count 看过一些网上关于count(*)和count(列)的文章,count(列)的效率一定比count(*)高吗? 其实个人觉得count(*)和count(列)根本就没有可比性,count(*)统计的是表里面的总条数,而count(列)统计的是当列的非空记录条数. 不过我们可以通过实验来比较一下: 首先创建测试表: drop table test purge; cr

[20161021]显示记录顺序问题.txt

[20161021]显示记录顺序问题.txt --同事在维护数据库时,发现记录显示顺序发生变化,看了一下操作过程,可以猜测可能维护后发生了行迁移导致的情况. --通过例子说明: 1.建立测试环境: SCOTT@book> @ &r/ver1 PORT_STRING         VERSION    BANNER ------------------- ---------- ----------------------------------------------------------

[20150508]列顺序问题.txt

[20150508]列顺序问题.txt --链接: https://viveklsharma.wordpress.com/2015/04/30/cpu-cycles-for-column-skipping/ --测试列顺序对CPU cost的影响: SCOTT@test> @ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- --------

Oracle性能优化学习笔记之WHERE子句中的连接顺序

        ORACLE采用自下而上的顺序解析WHERE子句,根据这个原理,表之间的连接必须写在其他WHERE条件之前, 那些可以过滤掉最大数量记录的条件必须写在WHERE子句的末尾.         例如:        (低效,执行时间156.3秒) SELECT - FROM EMP E WHERE SAL > 50000 AND JOB = 'MANAGER' AND 25 < (SELECT COUNT(*) FROM EMP WHERE MGR=E.EMPNO);      

[20160212]闭包传递4.txt

[20160212]闭包传递4.txt --所谓闭包传递是指sql语句的谓词条件A=B and B=C 可以推出 A=C. oracle 的 优化器能够利用这个特性优化sql语句. --前一阵子看电子电子书<Apress.Expert.Oracle.SQL.Optimization.Deployment.and.Statistics.1430259779.pdf>测试链接: http://blog.itpub.net/267265/viewspace-1981803/ http://blog.

[20160211]闭包传递3.txt

[20160211]闭包传递3.txt --所谓闭包传递是指sql语句的谓词条件A=B and B=C 可以推出 A=C. oracle 的 优化器能够利用这个特性优化sql语句. --前一阵子看电子电子书<Apress.Expert.Oracle.SQL.Optimization.Deployment.and.Statistics.1430259779.pdf>测试链接: http://blog.itpub.net/267265/viewspace-1981803/ http://blog.