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

发布于 2024-10-08 12:23:16 字数 286 浏览 3 评论 0原文

我通常在 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 没有输入/输出参数。

I usually generate explain plans using the following in 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

But what If I want to generate explain plan for a stored procedure?

Is there a way to generate explain plan for the entire stored procedure? The SP has no input/output parameters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凯凯我们等你回来 2024-10-15 12:23:16

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

根据定义,执行计划是针对单个 SQL 语句的。 PL/SQL 块没有执行计划。如果它包含一个或多个 SQL 语句,那么每个语句都会有一个执行计划。

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

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

What you are generating is correctly called an "execution plan". "Explain plan" is a command used to generate and view an execution plan, much as AUTOTRACE TRACEONLY does in your example.

By definition, an execution plan is for a single SQL statement. A PL/SQL block does not have an execution plan. If it contains one or more SQL statements, then each of those will have an execution plan.

One option is to manually extract the SQL statements from the PL/SQL code and use the process you've already shown.

Another option is to active SQL tracing then run the procedure. This will produce a trace file on the server that contains the execution plans for all statements executed in the session. The trace is in fairly raw form so it is generally easiest to format it using Oracle's TKPROF tool; there are also various third-party tools that process these trace files as well.

扮仙女 2024-10-15 12:23:16
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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文