当前位置:  数据库>oracle

Oracle Execution Plan笔记

    来源: 互联网  发布时间:2017-04-18

    本文导语:  -- example select trs.name, rt.*  from rps_transaction rt, rps_transaction_status trs where rt.status_id = trs.id   and rt.original_rps_batch_id = 2790000 order by rt.id; Explain Plan For SQL> explain plan for  2  -- example   3  select trs.name, rt.*  4    from rps_transaction rt, ...

-- example
select trs.name, rt.*
  from rps_transaction rt, rps_transaction_status trs
 where rt.status_id = trs.id
   and rt.original_rps_batch_id = 2790000
 order by rt.id;







Explain Plan For

SQL> explain plan for
  2  -- example
  3  select trs.name, rt.*
  4    from rps_transaction rt, rps_transaction_status trs
  5   where rt.status_id = trs.id
  6     and rt.original_rps_batch_id = 2790000
  7   order by rt.id;

SQL> set lines 180
SQL> set pages 999
SQL> select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1655554624

-----------------------------------------------------------------------------------------------------------
| Id  | Operation                     | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT              |                           |     6 |   852 |     4  (25)| 00:00:01 |
|   1 |  SORT ORDER BY                |                           |     6 |   852 |     4  (25)| 00:00:01 |
|   2 |   NESTED LOOPS                |                           |     6 |   852 |     3   (0)| 00:00:01 |
|   3 |    TABLE ACCESS BY INDEX ROWID| RPS_TRANSACTION           |     6 |   762 |     2   (0)| 00:00:01 |
|*  4 |     INDEX RANGE SCAN          | RPS_TRANSACTION_N1        |     6 |       |     1   (0)| 00:00:01 |
|   5 |    TABLE ACCESS BY INDEX ROWID| RPS_TRANSACTION_STATUS    |     1 |    15 |     1   (0)| 00:00:01 |
|*  6 |     INDEX UNIQUE SCAN         | RPS_TRANSACTION_STATUS_PK |     1 |       |     0   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access("RT"."ORIGINAL_RPS_BATCH_ID"=2790000)
   6 - access("RT"."STATUS_ID"="TRS"."ID")


































AutoTrace

SQL> set autot
Usage: SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]
SQL> set autotrace traceonly explain
SQL> -- example
SQL> select trs.name, rt.*
  2    from rps_transaction rt, rps_transaction_status trs
  3   where rt.status_id = trs.id
   and rt.original_rps_batch_id = 2790000
  4     and rt.original_rps_batch_id = 2790000
  5   order by rt.id;

Execution Plan
----------------------------------------------------------
Plan hash value: 1655554624

-----------------------------------------------------------------------------------------------------------
| Id  | Operation                     | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT              |                           |     6 |   852 |     4  (25)| 00:00:01 |
|   1 |  SORT ORDER BY                |                           |     6 |   852 |     4  (25)| 00:00:01 |
|   2 |   NESTED LOOPS                |                           |     6 |   852 |     3   (0)| 00:00:01 |
|   3 |    TABLE ACCESS BY INDEX ROWID| RPS_TRANSACTION           |     6 |   762 |     2   (0)| 00:00:01 |
|*  4 |     INDEX RANGE SCAN          | RPS_TRANSACTION_N1        |     6 |       |     1   (0)| 00:00:01 |
|   5 |    TABLE ACCESS BY INDEX ROWID| RPS_TRANSACTION_STATUS    |     1 |    15 |     1   (0)| 00:00:01 |
|*  6 |     INDEX UNIQUE SCAN         | RPS_TRANSACTION_STATUS_PK |     1 |       |     0   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access("RT"."ORIGINAL_RPS_BATCH_ID"=2790000)
   6 - access("RT"."STATUS_ID"="TRS"."ID")






























V$SQL_PLAN

sql> select s.address, s.hash_value, substr(s.sql_text,1,100)
  2    from v$sqlarea s
  3   where lower(s.SQL_TEXT) like '-- example select trs.name,%';

ADDRESS  HASH_VALUE SUBSTR(S.SQL_TEXT,1,100)
-------- ---------- ----------------------------------------------------------------------------------------------------
44C7B5A0 1654873186 -- example select trs.name, rt.*   from rps_transaction rt, rps_transaction_status trs  where rt.sta

-- use this sql statement to display execution play in v$sql_plan
select /*+ rule */
 lpad(' ', p.depth, ' ') || p.operation || ' ' || p.options as operation,
 p.object_name,
 p.cardinality,
 p.cost
  from v$sql_plan p
 where p.address = '&addr;'
   and p.hash_value = '&hash;'
 order by p.id;


SQL> col operation for a50
SQL> /
Enter value for addr: 44C7B5A0
old   7:  where p.address = '&addr;'
new   7:  where p.address = '44C7B5A0'
Enter value for hash: 1654873186
old   8:    and p.hash_value = '&hash;'
new   8:    and p.hash_value = '1654873186'

OPERATION                                          OBJECT_NAME                    CARDINALITY       COST
-------------------------------------------------- ------------------------------ ----------- ----------
SELECT STATEMENT                                                                                       4
 SORT ORDER BY                                                                              6          4
  NESTED LOOPS                                                                              6          3
   TABLE ACCESS BY INDEX ROWID                     RPS_TRANSACTION                          6          2
    INDEX RANGE SCAN                               RPS_TRANSACTION_N1                       6          1
   TABLE ACCESS BY INDEX ROWID                     RPS_TRANSACTION_STATUS                   1          1
    INDEX UNIQUE SCAN                              RPS_TRANSACTION_STATUS_PK                1          0







































SQL Trace

SQL> alter session set events '10046 trace name context forever, level 12';

Session altered.

SQL> -- example
SQL> select trs.name, rt.*
  2    from rps_transaction rt, rps_transaction_status trs
  3   where rt.status_id = trs.id
  4     and rt.original_rps_batch_id = 2790000
  5   order by rt.id;

SQL> alter session set events '10046 trace name context off';

Session altered.

-- use this sql statement to display own trace file name
SELECT udd.udd || '/' || iname.iname || '_ora_' || sp.spid || '.trc' trcname
  FROM (SELECT lower(VALUE) iname
          FROM v$parameter
         WHERE NAME = 'instance_name') iname,
       (SELECT VALUE udd FROM v$parameter WHERE NAME = 'user_dump_dest') udd,
       (SELECT s.sid, s.serial#, p.spid
          FROM v$session s, v$process p, v$mystat m
         WHERE s.PADDR = p.ADDR
           AND m.sid = s.sid
           and m.statistic# = 1) sp;
SQL> /
TRCNAME
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/home/Oracle/product/10.2.0/db_1/admin/data/udump/data_ora_19366.trc

SQL> ! cp /home/oracle/product/10.2.0/db_1/admin/data/udump/data_ora_19366.trc /tmp/.

SQL> ! tkprof /tmp/data_ora_19366.trc /tmp/data_ora_19366.rpt sort=exeela

TKPROF: Release 10.2.0.1.0 - Production on Tue Apr 29 17:13:41 2008

Copyright (c) 1982, 2005, Oracle.  All rights reserved.
SQL> !cat /tmp/data_ora_19366.rpt
...

select trs.name, rt.*
  from rps_transaction rt, rps_transaction_status trs
 where rt.status_id = trs.id
   and rt.original_rps_batch_id = 2790000
 order by rt.id

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.01       0.03          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        2      0.00       0.00          0         10          0           6
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.01       0.04          0         10          0           6

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 268 

Rows     Row Source Operation
-------  ---------------------------------------------------
      6  SORT ORDER BY (cr=10 pr=0 pw=0 time=470 us)
      6   NESTED LOOPS  (cr=10 pr=0 pw=0 time=453 us)
      6    TABLE ACCESS BY INDEX ROWID RPS_TRANSACTION (cr=2 pr=0 pw=0 time=157 us)
      6     INDEX RANGE SCAN RPS_TRANSACTION_N1 (cr=1 pr=0 pw=0 time=73 us)(object id 837086)
      6    TABLE ACCESS BY INDEX ROWID RPS_TRANSACTION_STATUS (cr=8 pr=0 pw=0 time=206 us)
      6     INDEX UNIQUE SCAN RPS_TRANSACTION_STATUS_PK (cr=2 pr=0 pw=0 time=93 us)(object id 835587)

PLAN and Collection

-- prepare table and collection
create table ta as select * from dba_objects;

-- use function to return collection
drop function f_c;
create or replace function f_c return int_tab_type
is
  l_tab int_tab_type := int_tab_type();
begin
  select object_id bulk collect into l_tab from ta sample (10);
  return l_tab;
end;
/

-- collection没有准确的统计信息,可以检查E-Rows/A-Rows
select /*+ gather_plan_statistics */
 ta.object_name
  from ta, table(f_c()) tb
 where ta.object_id = tb.column_value;

SQL> select t.plan_table_output
  2    from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST')) t;
SQL_ID  5hjq4794jwgy9, child number 0
-------------------------------------
select /*+ gather_plan_statistics*/  ta.object_name   from ta, table(f_c()) tb  where ta.object_id = tb.column_value

Plan hash value: 2098580674

--------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                          | Name | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
--------------------------------------------------------------------------------------------------------------------------------
|*  1 |  HASH JOIN                         |      |      1 |   8168 |   7333 |00:00:00.15 |    2562 |   921K|   921K| 1282K (0)|
|   2 |   COLLECTION ITERATOR PICKLER FETCH| F_C  |      1 | |00:00:00.05 |    1040 |       |       |          |
|   3 |   TABLE ACCESS FULL                | TA   |      1 |  76919 |  75049 |00:00:00.23 |    1522 |       |       |          |
--------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access("TA"."OBJECT_ID"=VALUE(KOKBF$))

Note
-----
   - dynamic sampling used for this statement

-- 使用hint提供一个估计值给CBO,我这里提供了一个很大的值,导致plan改变
select /*+ gather_plan_statistics */
 ta.object_name
  from ta, table(f_c()) tb
 where ta.object_id = tb.column_value;

SQL> select t.plan_table_output
  2    from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST')) t;
SQL_ID  2mgcxsqg8pu8w, child number 0
-------------------------------------
select /*+ gather_plan_statistics cardinality(tb 99999999) */  ta.object_name   from ta, table(f_c()) tb  where
ta.object_id = tb.column_value

Plan hash value: 1609288054

--------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                          | Name | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
--------------------------------------------------------------------------------------------------------------------------------
|*  1 |  HASH JOIN                         |      |      1 |    |00:00:00.20 |    2080 |  3851K|  1063K| 5029K (0)|
|   2 |   TABLE ACCESS FULL                | TA   |      1 |  76919 |  75049 |00:00:00.23 |    1040 |       |       |          |
|   3 |   COLLECTION ITERATOR PICKLER FETCH| F_C  |      1 |        |   7545 |00:00:00.04 |    1040 |       |       |          |
--------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access("TA"."OBJECT_ID"=VALUE(KOKBF$))












































































































































href="/tag/if" target="_blank">if ($ != jQuery) { $ = jQuery.noConflict(); } var isLogined = false; var cb_blogId = 103266; var cb_entryId = 2304343; var cb_blogApp = "wait4friend"; var cb_blogUserGuid = "299af60e-271b-e111-b422-842b2b196315"; var cb_entryCreatedDate = '2011/12/28 10:14:00';

    
 
 

您可能感兴趣的文章:

  • Oracle 免费送出硬纸板的笔记本电脑?!
  • Linux+Oracle学习笔记
  • Oracle 10G进程体系学习笔记
  • 虚拟机装Oracle R12与Oracle10g iis7站长之家
  • Linux下安装oracle问题笔记
  • oracle 技巧学习笔记
  • Oracle数据库基本知识学习笔记
  • 如何在linux + text下安装oracle8/9,我的笔记本是dell latitude d600,我找不到显卡驱动
  • Oracle 下 spfile和pfile使用笔记
  • Linux Oracle 10g 新手笔记
  • Oracle学习笔记(六)
  • oracle9204升级到9206笔记
  • Linux下安装Oracle数据库完整笔记
  • ORACLE学习笔记-添加更新数据函数篇
  • Solaris 10 U3安装Oracle 10g R2实例笔记
  • Linux系统下安装Oracle数据库笔记
  • oracle学习笔记(二)
  • ORACLE学习笔记-新建用户及建表篇
  • ORACLE学习笔记-查询篇
  • Oracle笔记之简单查询、限定查询和排序
  •  
    本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
    本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • Oracle 12c发布简单介绍及官方下载地址
  • 在linux下安装oracle,如何设置让oracle自动启动!也就是让oracle那个服务自动启动,不是手动的
  • oracle 11g最新版官方下载地址
  • 请问su oracle 和su - oracle有什么不同?
  • Oracle 数据库(oracle Database)Select 多表关联查询方式
  • 虚拟机装Oracle R12与Oracle10g
  • Oracle数据库(Oracle Database)体系结构及基本组成介绍
  • Oracle 数据库开发工具 Oracle SQL Developer
  • 如何设置让Oracle SQL Developer显示的时间包含时分秒
  • Oracle EBS R12 支持 Oracle Database 11g
  • Oracle 10g和Oracle 11g网格技术介绍
  • SCO unix下安装oracle,但没有光盘,请大家推荐一个oracle下载站点(unix版本的)。谢谢!!!!
  • oracle中如何把表中具有相同值列的多行数据合并成一行
  • 请问大家用oracle数据库, 用import oracle.*;下的东西么? 还是用标准库?
  • Oracle 数据库(oracle Database)性能调优技术详解
  • Linux /$ORACLE_HOME $ORACLE_HOME
  • ORACLE日期相关操作
  • Linux系统下Oracle的启动与Oracle监听的启动
  • ORACLE数据库常用字段数据类型介绍
  • 请问在solaris下安装ORACLE,用root用户和用oracle用户安装有什么区别么?
  • Oracle 12c的九大最新技术特性介绍
  • 网间Oracle的连接,远程连接Oracle服务器??


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3