zoukankan      html  css  js  c++  java
  • 从两表连接看Oracle sql优化器的效果

    select emp.*,dept.* from tb_emp03 emp,tb_dept03 dept where emp.deptno=dept.id 
    
    -- 不加hint SQL
    > select emp.*,dept.* from tb_emp03 emp,tb_dept03 dept where emp.deptno=dept.id ; 已用时间: 00: 00: 00.00 执行计划 ---------------------------------------------------------- Plan hash value: 2666916627 -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1818K| 97M| 3619 (2)| 00:00:44 | |* 1 | HASH JOIN | | 1818K| 97M| 3619 (2)| 00:00:44 | | 2 | TABLE ACCESS FULL| TB_DEPT03 | 10 | 160 | 3 (0)| 00:00:01 | | 3 | TABLE ACCESS FULL| TB_EMP03 | 2000K| 76M| 3601 (1)| 00:00:44 | -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("EMP"."DEPTNO"="DEPT"."ID") select /*+ leading(emp,dept) use_nl(emp) */emp.*,dept.* from tb_emp03 emp,tb_dept03 dept where emp.deptno=dept.id; SQL> select /*+ leading(emp,dept) use_nl(emp) */emp.*,dept.* from tb_emp03 emp,tb_dept03 dept where emp.deptno=dept.id; 已用时间: 00: 00: 00.00 执行计划 ---------------------------------------------------------- Plan hash value: 960397288 ---------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | ---------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1818K| 97M| | 8558 (1)| 00:01:43 | |* 1 | HASH JOIN | | 1818K| 97M| 99M| 8558 (1)| 00:01:43 | | 2 | TABLE ACCESS FULL| TB_EMP03 | 2000K| 76M| | 3601 (1)| 00:00:44 | | 3 | TABLE ACCESS FULL| TB_DEPT03 | 10 | 160 | | 3 (0)| 00:00:01 | ---------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("EMP"."DEPTNO"="DEPT"."ID") select /*+ leading(dept,emp) use_nldept) */emp.*,dept.* from tb_emp03 emp,tb_dept03 dept where emp.deptno=dept.id; SQL> select /*+ leading(dept,emp) use_nldept) */emp.*,dept.* from tb_emp03 emp,tb_dept03 dept where emp.deptno=dept.id; 已用时间: 00: 00: 00.00 执行计划 ---------------------------------------------------------- Plan hash value: 2666916627 -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1818K| 97M| 3619 (2)| 00:00:44 | |* 1 | HASH JOIN | | 1818K| 97M| 3619 (2)| 00:00:44 | | 2 | TABLE ACCESS FULL| TB_DEPT03 | 10 | 160 | 3 (0)| 00:00:01 | | 3 | TABLE ACCESS FULL| TB_EMP03 | 2000K| 76M| 3601 (1)| 00:00:44 | -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("EMP"."DEPTNO"="DEPT"."ID") select /*+ ordered */emp.*,dept.* from tb_emp03 emp,tb_dept03 dept where emp.deptno=dept.id; SQL> select /*+ ordered */emp.*,dept.* from tb_emp03 emp,tb_dept03 dept where emp.deptno=dept.id; 已用时间: 00: 00: 00.00 执行计划 ---------------------------------------------------------- Plan hash value: 960397288 ---------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | ---------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1818K| 97M| | 8558 (1)| 00:01:43 | |* 1 | HASH JOIN | | 1818K| 97M| 99M| 8558 (1)| 00:01:43 | | 2 | TABLE ACCESS FULL| TB_EMP03 | 2000K| 76M| | 3601 (1)| 00:00:44 | | 3 | TABLE ACCESS FULL| TB_DEPT03 | 10 | 160 | | 3 (0)| 00:00:01 | ---------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("EMP"."DEPTNO"="DEPT"."ID") select /*+ use_hash(dept,emp) */emp.*,dept.* from tb_emp03 emp,tb_dept03 dept where emp.deptno=dept.id; SQL> select /*+ use_hash(dept,emp) */emp.*,dept.* from tb_emp03 emp,tb_dept03 dept where emp.deptno=dept.id; 已用时间: 00: 00: 00.00 执行计划 ---------------------------------------------------------- Plan hash value: 2666916627 -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1818K| 97M| 3619 (2)| 00:00:44 | |* 1 | HASH JOIN | | 1818K| 97M| 3619 (2)| 00:00:44 | | 2 | TABLE ACCESS FULL| TB_DEPT03 | 10 | 160 | 3 (0)| 00:00:01 | | 3 | TABLE ACCESS FULL| TB_EMP03 | 2000K| 76M| 3601 (1)| 00:00:44 | -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("EMP"."DEPTNO"="DEPT"."ID") select /*+ use_hash(emp,dept) */emp.*,dept.* from tb_emp03 emp,tb_dept03 dept where emp.deptno=dept.id; SQL> select /*+ use_hash(emp,dept) */emp.*,dept.* from tb_emp03 emp,tb_dept03 dept where emp.deptno=dept.id; 已用时间: 00: 00: 00.00 执行计划 ---------------------------------------------------------- Plan hash value: 2666916627 -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1818K| 97M| 3619 (2)| 00:00:44 | |* 1 | HASH JOIN | | 1818K| 97M| 3619 (2)| 00:00:44 | | 2 | TABLE ACCESS FULL| TB_DEPT03 | 10 | 160 | 3 (0)| 00:00:01 | | 3 | TABLE ACCESS FULL| TB_EMP03 | 2000K| 76M| 3601 (1)| 00:00:44 | -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("EMP"."DEPTNO"="DEPT"."ID")
  • 相关阅读:
    SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
    简单的使用SLF4J门面和log4j
    详细的Log4j使用教程
    java的Mybatis动态代理方式(二)
    java的一个基础的Mybatis例子(一)
    java的注解学习
    ArrayList输出的几种方法
    自己写的一个java链接数据库的类
    ipv4的TCP的几个状态 (SYN, FIN, ACK, PSH, RST, URG)
    tomcat的CATALINA_HOME环境变量可以不用设置
  • 原文地址:https://www.cnblogs.com/heyang78/p/12238421.html
Copyright © 2011-2022 走看看