初识Oracle执行计划

php中文网
发布: 2016-06-07 17:10:42
原创
1131人浏览过

初识Oracle执行计划,表连接的实现方法还有排序合并和嵌套循环方式,在后面做介绍.Predicate Information (identified by operati

1,先建立测试表和数据,
create   table emp as
  select level   empl_id,
             (mod (rownum, 20)+1) dept_id,
             substr(dbms_random.string ('x', dbms_random.value (20, 50)),0,10) empname,
             trunc (dbms_random.value (1000, 500000), 2)  salary,
             decode (round (dbms_random.value (1, 2)), 1, 'm', 2, 'f')   gender,
             to_date (   round (dbms_random.value (1, 28))
                      || '-'
                      || round (dbms_random.value (1, 12))
                      || '-'
                      || round (dbms_random.value (1900, 2010)),
                      'dd-mm-yyyy')    dob
        from dual
  connect by level create    table dept as
  select level   dept_id,
             substr(dbms_random.string ('x', dbms_random.value (20, 50)),0,10) manager,
             decode (round (dbms_random.value (1, 2)), 1, 'm', 2, 'f')   gender,
             to_date (   round (dbms_random.value (1, 28))
                      || '-'
                      || round (dbms_random.value (1, 12))
                      || '-'
                      || round (dbms_random.value (1900, 2010)),
                      'dd-mm-yyyy')    estbdate
        from dual
  connect by level
2,没有索引,第一次执行sql
sql> set autotrace on;
sql> select empl_id,empname,dept.dept_id,manager from emp,dept where emp.dept_id=dept.dept_id;

execution plan
----------------------------------------------------------
plan hash value: 615168685
---------------------------------------------------------------------------
| id  | operation          | name | rows  | bytes | cost (%cpu)| time     |
---------------------------------------------------------------------------
|   0 | select statement   |      |  1000 | 53000 |     8  (13)| 00:00:01 |
|*  1 |  hash join         |      |  1000 | 53000 |     8  (13)| 00:00:01 |
|   2 |   table access full| dept |    30 |   600 |     3   (0)| 00:00:01 |
|   3 |   table access full| emp  |  1000 | 33000 |     4   (0)| 00:00:01 |
---------------------------------------------------------------------------
predicate information (identified by operation id):
---------------------------------------------------
   1 - access("emp"."dept_id"="dept"."dept_id")
note
-----
   - dynamic sampling used for this statement
statistics
----------------------------------------------------------
        504  recursive calls
          0  db block gets
        151  consistent gets
         19  physical reads
          0  redo size
      39139  bytes sent via sql*net to client
       1107  bytes received via sql*net from client
         68  sql*net roundtrips to/from client
         10  sorts (memory)
          0  sorts (disk)
       1000  rows processed

对这个计划的一些解释:
plan hash value: 615168685,根据执行的sql文本得到一个hash值,表示放在共享池中的地址,如果同样的sql再次执行,直接用这个执行计划.
|*  1 |  hash join         |      |  1000 | 53000 |     8  (13)| 00:00:01 |
|   2 |   table access full| dept |    30 |   600 |     3   (0)| 00:00:01 |
|   3 |   table access full| emp  |  1000 | 33000 |     4   (0)| 00:00:01 |
两个表做连接的一种方式,这里是hash join,这里是是先将dept表的所有数据做扫描,对每一条数据,根据dept 的dept_id算出一个hash值,放在该hash值代表的内存join区域,然后扫描emp表,对每一条emp表的数据的dept_id计算hash值,然后按照hash值放到join区域,形成数据的连接.

linux

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号