查看存储过程的执行计划

    1. 存储过程没有执行计划,查看的是存储过程中SQL语句的执行计划,这里用10046来看  
    2.   
    3. ----------------------------------------------------    
    4. 创建存储过程  
    5. Create Or Replace Procedure Lee_Xc(Eno Number) Is  
    6.   
    7. Begin  
    8.   
    9.   Select Empno, Ename, Dname  
    10.     From Emp, Dept  
    11.    Where Emp.Deptno = Dept.Deptno  
    12.      And Emp.Deptno = Eno;  
    13.   Commit;  
    14. End;  
    15. /  
    16. ----------------------------------------------------    
    17. 追踪10046  
    18.   
    19. SQL> alter session set events '10046 trace name context forever, level 12';  
    20.    
    21. Session altered  
    22.    
    23. SQL> exec   LEE_HK(8800186378);  
    24.    
    25. PL/SQL procedure successfully completed  
    26.    
    27. SQL> alter session set events '10046 trace name context off';  
    28.    
    29. Session altered  
    30.    
    31. SQL>   
    32. SQL> SELECT    d.VALUE  
    33.   2         || '/'  
    34.   3         || LOWER (RTRIM (i.INSTANCE, CHR (0)))  
    35.   4         || '_ora_'  
    36.   5         || p.spid  
    37.   6         || '.trc' as "trace_file_name"  
    38.   7       FROM (SELECT p.spid  
    39.   8               FROM v$mystat m, v$session s, v$process p  
    40.   9              WHERE m.statistic# = 1 AND s.SID = m.SID AND p.addr = s.paddr) p,  
    41.  10           (SELECT t.INSTANCE  
    42.  11               FROM v$thread t, v$parameter v  
    43.  12             WHERE v.NAME = 'thread'  
    44.  13               AND (v.VALUE = 0 OR t.thread# = TO_NUMBER (v.VALUE))) i,  
    45.  14           (SELECT VALUE  
    46.  15               FROM v$parameter  
    47.  16            WHERE NAME = 'user_dump_dest') d  
    48.  17  ;  
    49.    
    50. trace_file_name  
    51. --------------------------------------------------------------------------------  
    52. /oracle/admin/jsjdata0/udump/jsjdata0_ora_19658.trc  
    53.   
    54. ----------------------------------------------------    
    55. 格式转换一下  
    56. [oracle@jsb2011data udump]$ tkprof jsjdata0_ora_19984.trc  lee1 sys=no explain=gcbb/gcbb  
    57.   
    58.   
    59. [oracle@jsb2011data udump]$ more lee5.prf   
    60.   
    61. TKPROF: Release 10.2.0.1.0 - Production on Thu Apr 26 14:50:56 2012  
    62.   
    63. Copyright (c) 1982, 2005, Oracle.  All rights reserved.  
    64.   
    65. Trace file: jsjdata0_ora_19984.trc  
    66. Sort options: default  
    67.   
    68. ********************************************************************************  
    69. count    = number of times OCI procedure was executed  
    70. cpu      = cpu time in seconds executing   
    71. elapsed  = elapsed time in seconds executing  
    72. disk     = number of physical reads of buffers from disk  
    73. query    = number of buffers gotten for consistent read  
    74. current  = number of buffers gotten in current mode (usually for update)  
    75. rows     = number of rows processed by the fetch or execute call  
    76. ********************************************************************************  
    77.   
    78. alter session set events '10046 trace name context forever, level 12'   
    79.   
    80.   
    81. call     count       cpu    elapsed       disk      query    current        rows  
    82. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    83. Parse        0      0.00       0.00          0          0          0           0  
    84. Execute      1      0.00       0.00          0          0          0           0  
    85. Fetch        0      0.00       0.00          0          0          0           0  
    86. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    87. total        1      0.00       0.00          0          0          0           0  
    88.   
    89. Misses in library cache during parse: 0  
    90. Misses in library cache during execute: 1  
    91. Optimizer mode: ALL_ROWS  
    92. Parsing user id: 54  (SCOTT)  
    93.   
    94. Elapsed times include waiting on following events:  
    95.   Event waited on                             Times   Max. Wait  Total Waited  
    96.   ----------------------------------------   Waited  ----------  ------------  
    97.   SQL*Net message to client                       1        0.00          0.00  
    98.   SQL*Net message from client                     1        0.03          0.03  
    99. ********************************************************************************  
    100.   
    101. begin :id := sys.dbms_transaction.local_transaction_id; end;  
    102.   
    103.   
    104. call     count       cpu    elapsed       disk      query    current        rows  
    105. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    106. Parse        4      0.00       0.00          0          0          0           0  
    107. Execute      4      0.00       0.00          0          0          0           4  
    108. Fetch        0      0.00       0.00          0          0          0           0  
    109. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    110. total        8      0.00       0.00          0          0          0           4  
    111.   
    112. Misses in library cache during parse: 0  
    113. Optimizer mode: ALL_ROWS  
    114. Parsing user id: 54  (SCOTT)  
    115.   
    116. Elapsed times include waiting on following events:  
    117.   Event waited on                             Times   Max. Wait  Total Waited  
    118.   ----------------------------------------   Waited  ----------  ------------  
    119.   SQL*Net message to client                       4        0.00          0.00  
    120.   SQL*Net message from client                     4        8.29         16.08  
    121. ********************************************************************************  
    122.   
    123. select 'x'   
    124. from  
    125.  dual  
    126.   
    127.   
    128. call     count       cpu    elapsed       disk      query    current        rows  
    129. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    130. Parse        2      0.00       0.00          0          0          0           0  
    131. Execute      2      0.00       0.00          0          0          0           0  
    132. Fetch        2      0.00       0.00          0          0          0           2  
    133. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    134. total        6      0.00       0.00          0          0          0           2  
    135.   
    136. Misses in library cache during parse: 0  
    137. Optimizer mode: ALL_ROWS  
    138. Parsing user id: 54  (SCOTT)  
    139.   
    140. Rows     Row Source Operation  
    141. -------  ---------------------------------------------------  
    142.       1  FAST DUAL  (cr=0 pr=0 pw=0 time=10 us)  
    143.   
    144.   
    145. Rows     Execution Plan  
    146. -------  ---------------------------------------------------  
    147.       0  SELECT STATEMENT   MODE: ALL_ROWS  
    148.       1   FAST DUAL  
    149.   
    150.   
    151. Elapsed times include waiting on following events:  
    152.   Event waited on                             Times   Max. Wait  Total Waited  
    153.   ----------------------------------------   Waited  ----------  ------------  
    154.   SQL*Net message to client                       4        0.00          0.00  
    155.   SQL*Net message from client                     4        0.01          0.03  
    156. ********************************************************************************  
    157.   
    158. begin lee_xc(7788); end;     --这里可以看到输入的参数   
    159.   
    160.   
    161. call     count       cpu    elapsed       disk      query    current        rows  
    162. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    163. Parse        1      0.00       0.00          0          0          0           0  
    164. Execute      1      0.00       0.00          0          0          0           1  
    165. Fetch        0      0.00       0.00          0          0          0           0  
    166. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    167. total        2      0.00       0.00          0          0          0           1  
    168.   
    169. Misses in library cache during parse: 1  
    170. Optimizer mode: ALL_ROWS  
    171. Parsing user id: 54  (SCOTT)  
    172.   
    173. Elapsed times include waiting on following events:  
    174.   Event waited on                             Times   Max. Wait  Total Waited  
    175.   ----------------------------------------   Waited  ----------  ------------  
    176.   log file sync                                   1        0.00          0.00  
    177.   SQL*Net message to client                       1        0.00          0.00  
    178.   SQL*Net message from client                     1        0.03          0.03  
    179. ********************************************************************************  
    180.   
    181. UPDATE EMP SET SAL = 30000  --这里看到带参的SQL  
    182. WHERE  
    183.  EMPNO = :B1   
    184.   
    185.   
    186. call     count       cpu    elapsed       disk      query    current        rows  
    187. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    188. Parse        0      0.00       0.00          0          0          0           0  
    189. Execute      1      0.00       0.00          0          1          2           1  
    190. Fetch        0      0.00       0.00          0          0          0           0  
    191. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    192. total        1      0.00       0.00          0          1          2           1  
    193.   
    194. Misses in library cache during parse: 0  
    195. Optimizer mode: ALL_ROWS  
    196. Parsing user id: 54  (SCOTT)   (recursive depth: 1)  
    197.   
    198. Rows     Execution Plan                                                    ---这里就是执行计划了  
    199. -------  ---------------------------------------------------  
    200.       0  UPDATE STATEMENT   MODE: ALL_ROWS  
    201.       0   UPDATE OF 'EMP'  
    202.       0    INDEX   MODE: ANALYZED (UNIQUE SCAN) OF 'PK_EMP' (INDEX   
    203.                (UNIQUE))  
    204.   
    205. ********************************************************************************  
    206.   
    207. COMMIT  
    208.   
    209.   
    210. call     count       cpu    elapsed       disk      query    current        rows  
    211. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    212. Parse        0      0.00       0.00          0          0          0           0  
    213. Execute      1      0.00       0.00          0          0          1           0  
    214. Fetch        0      0.00       0.00          0          0          0           0  
    215. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    216. total        1      0.00       0.00          0          0          1           0  
    217.   
    218. Misses in library cache during parse: 0  
    219. Parsing user id: 54  (SCOTT)   (recursive depth: 1)  
    220. ********************************************************************************  
    221.   
    222. alter session set events '10046 trace name context off'    
    223.   
    224.   
    225. call     count       cpu    elapsed       disk      query    current        rows  
    226. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    227. Parse        1      0.00       0.00          0          0          0           0  
    228. Execute      1      0.00       0.00          0          0          0           0  
    229. Fetch        0      0.00       0.00          0          0          0           0  
    230. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    231. total        2      0.00       0.00          0          0          0           0  
    232.   
    233. Misses in library cache during parse: 1  
    234. Optimizer mode: ALL_ROWS  
    235. Parsing user id: 54  (SCOTT)  
    236.   
    237.   
    238.   
    239. ********************************************************************************  
    240.   
    241. OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS  
    242.   
    243. call     count       cpu    elapsed       disk      query    current        rows  
    244. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    245. Parse        8      0.00       0.00          0          0          0           0  
    246. Execute      9      0.00       0.00          0          0          0           5  
    247. Fetch        2      0.00       0.00          0          0          0           2  
    248. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    249. total       19      0.00       0.00          0          0          0           7  
    250.   
    251. Misses in library cache during parse: 2  
    252. Misses in library cache during execute: 1  
    253.   
    254. Elapsed times include waiting on following events:  
    255.   Event waited on                             Times   Max. Wait  Total Waited  
    256.   ----------------------------------------   Waited  ----------  ------------  
    257.   SQL*Net message to client                      10        0.00          0.00  
    258.   SQL*Net message from client                    10        8.29         16.17  
    259.   log file sync                                   1        0.00          0.00  
    260.   
    261.   
    262. OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS  
    263.   
    264. call     count       cpu    elapsed       disk      query    current        rows  
    265. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    266. Parse        0      0.00       0.00          0          0          0           0  
    267. Execute      2      0.00       0.00          0          1          3           1  
    268. Fetch        0      0.00       0.00          0          0          0           0  
    269. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
    270. total        2      0.00       0.00          0          1          3           1  
    271.   
    272. Misses in library cache during parse: 0  
    273.   
    274.    11  user  SQL statements in session.  
    275.     0  internal SQL statements in session.  
    276.    11  SQL statements in session.  
    277.     2  statements EXPLAINed in this session.  
    278. ********************************************************************************  
    279. Trace file: jsjdata0_ora_19984.trc  
    280. Trace file compatibility: 10.01.00  
    281. Sort options: default  
    282.   
    283.        1  session in tracefile.  
    284.       11  user  SQL statements in trace file.  
    285.        0  internal SQL statements in trace file.  
    286.       11  SQL statements in trace file.  
    287.        7  unique SQL statements in trace file.  
    288.        2  SQL statements EXPLAINed using schema:  
    289.            SCOTT.prof$plan_table  
    290.              Default table was used.  
    291.              Table was created.  
    292.              Table was dropped.  
    293.      144  lines in trace file.  
    294.       16  elapsed seconds in trace file. 
posted @ 2017-02-16 16:16  xybxj  阅读(114)  评论(0)    收藏  举报