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")
  • 相关阅读:
    C#调用Delphi的dll 详解
    C# 用API截取桌面屏幕
    C# 控件代码设置置顶和置底属性
    C#用API 获取电脑桌面背景图地址
    利用JS使IE浏览器默认打开是全屏显示
    aspx页面生成xml数据
    MacOS下安装Anaconda+Pycharm+TensorFlow+Keras
    GitHub编辑README
    Win10(64位)下安装Anaconda+Tensorflow(GPU)
    Win7(64位)下安装Anaconda+Tensorflow(CPU)
  • 原文地址:https://www.cnblogs.com/heyang78/p/12238421.html
Copyright © 2011-2022 走看看