如何为整个存储过程生成解释计划

时间:2010-12-22 15:05:18

标签: oracle stored-procedures sql-execution-plan

我通常在sqlplus中使用以下内容生成解释计划:

SET AUTOTRACE ON
SET TIMING ON
SET TRIMSPOOL ON
SET LINES 200
SPOOL filename.txt
SET AUTOTRACE TRACEONLY;

{query goes here}

SPOOL OFF
SET AUTOTRACE OFF

但是如果我想为存储过程生成解释计划呢?

有没有办法为整个存储过程生成解释计划? SP没有输入/输出参数。

2 个答案:

答案 0 :(得分:7)

您正在生成的内容被正确地称为“执行计划”。 “解释计划”是用于生成和查看执行计划的命令,就像您的示例中的AUTOTRACE TRACEONLY一样。

根据定义,执行计划适用于单个SQL语句。 PL / SQL块没有执行计划。如果它包含一个或多个SQL语句,那么每个语句都将有一个执行计划。

一种选择是从PL / SQL代码手动提取SQL语句并使用您已经显示的过程。

另一种选择是激活SQL跟踪然后运行该过程。这将在服务器上生成一个跟踪文件,其中包含会话中执行的所有语句的执行计划。跟踪是相当原始的形式,因此通常最容易使用Oracle的TKPROF工具对其进行格式化;还有各种第三方工具可以处理这些跟踪文件。

答案 1 :(得分:1)

Hi I have done like below for the stored procedure:
SET AUTOTRACE ON
SET TIMING ON
SET TRIMSPOOL ON
SET LINES 200
SPOOL filename.txt
SET AUTOTRACE TRACEONLY;
@your stored procedure path
SPOOL OFF
SET AUTOTRACE OFF

And got the below statistics: 

   Statistics
-----------------------------------------------------------
               6  CPU used by this session
               8  CPU used when call started
              53  DB time
               6  Requests to/from client
          188416  cell physical IO interconnect bytes
             237  consistent gets
             112  consistent gets - examination
             237  consistent gets from cache
             110  consistent gets from cache (fastpath)
            2043  db block gets
               1  db block gets direct
            2042  db block gets from cache
             567  db block gets from cache (fastpath)
              27  enqueue releases
              27  enqueue requests
               4  messages sent
              31  non-idle wait count
              19  non-idle wait time
              44  opened cursors cumulative
               2  opened cursors current
              22  physical read total IO requests
          180224  physical read total bytes
               1  physical write total IO requests
            8192  physical write total bytes
               1  pinned cursors current
             461  recursive calls
               4  recursive cpu usage
            2280  session logical reads
         1572864  session pga memory
              19  user I/O wait time
               9  user calls
               1  user commits
No Errors.
Autotrace Disabled