《Oracle PL/SQL实例精讲》学习笔记26——优化PL/SQL(第三部分——子程序内联)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hpdlzu80100/article/details/84194678

本章内容:

1. PL/SQL调优工具

2. PL/SQL优化级别

3. 子程序内联

代码如下:

1. 查看dbmshptab.sql脚本内容

Rem
Rem $Header: rdbms/admin/dbmshptab.sql /main/4 2013/07/08 10:56:15 sylin Exp $
Rem
Rem dbmshptab.sql
Rem
Rem Copyright (c) 2005, 2013, Oracle and/or its affiliates. 
Rem All rights reserved.
Rem
Rem    NAME
Rem      dbmshptab.sql - dbms hierarchical profiler table creation
Rem
Rem    DESCRIPTION
Rem       Create tables for the dbms hierarchical profiler
Rem
Rem    NOTES
Rem      The following tables are required to collect data:
Rem        dbmshp_runs
Rem          information on hierarchical profiler runs
Rem
Rem        dbmshp_function_info -
Rem          information on each function profiled
Rem
Rem        dbmshp_parent_child_info -
Rem          parent-child level profiler information
Rem
Rem      The dbmshp_runnumber sequence is used for generating unique
Rem      run numbers.
Rem
Rem      The tables and sequence can be created in the schema for each user
Rem      who wants to gather profiler data. Alternately these tables can be
Rem      created in a central schema. In the latter case the user creating
Rem      these objects is responsible for granting appropriate privileges
Rem      (insert,update on the tables and select on the sequence) to all
Rem      users who want to store data in the tables. Appropriate synonyms
Rem      must also be created so the tables are visible from other user
Rem      schemas.
Rem
Rem      THIS SCRIPT DELETES ALL EXISTING DATA!
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    sylin       06/12/13 - long identifier
Rem    sylin       07/30/07 - Modify foreign key constraints with on delete
Rem                           cascade clause
Rem    kmuthukk    06/13/06 - fix comments 
Rem    sylin       03/15/05 - Created
Rem

drop table dbmshp_runs                     cascade constraints;
drop table dbmshp_function_info            cascade constraints;
drop table dbmshp_parent_child_info        cascade constraints;

drop sequence dbmshp_runnumber;

create table dbmshp_runs
(
  runid               number primary key,  -- unique run identifier,
  run_timestamp       timestamp,
  total_elapsed_time  integer,
  run_comment         varchar2(2047)    -- user provided comment for this run
);

comment on table dbmshp_runs is
        'Run-specific information for the hierarchical profiler';

create table dbmshp_function_info
(
  runid                  number references dbmshp_runs on delete cascade,
  symbolid               number,               -- unique internally generated
                                               -- symbol id for a run
  owner                  varchar2(32),       -- user who started run -- dbms_id
  module                 varchar2(32),         -- module name -- dbms_id
  type                   varchar2(32),         -- module type
  function               varchar2(4000),       -- function name
  line#                  number,               -- line number where function
                                               -- defined in the module.
  hash                   raw(32) DEFAULT NULL, -- hash code of the method.
  -- name space/language info (such as PL/SQL, SQL)
  namespace              varchar2(32) DEFAULT NULL,
  -- total elapsed time in this symbol (including descendats)
  subtree_elapsed_time   integer DEFAULT NULL,
  -- self elapsed time in this symbol (not including descendants)
  function_elapsed_time  integer DEFAULT NULL,
  -- number of total calls to this symbol
  calls                  integer DEFAULT NULL,
  --  
  primary key (runid, symbolid)
);

comment on table dbmshp_function_info is
        'Information about each function in a run';

create table dbmshp_parent_child_info
(
  runid                  number,       -- unique (generated) run identifier
  parentsymid            number,       -- unique parent symbol id for a run
  childsymid             number,       -- unique child symbol id for a run
  -- total elapsed time in this symbol (including descendats)
  subtree_elapsed_time   integer DEFAULT NULL,
  -- self elapsed time in this symbol (not including descendants)
  function_elapsed_time  integer DEFAULT NULL,
  -- number of calls from the parent
  calls                  integer DEFAULT NULL,
  --
  foreign key (runid, childsymid)
    references dbmshp_function_info(runid, symbolid) on delete cascade,
  foreign key (runid, parentsymid)
    references dbmshp_function_info(runid, symbolid) on delete cascade
);

comment on table dbmshp_parent_child_info is
        'Parent-child information from a profiler runs';

create sequence dbmshp_runnumber start with 1 nocache;

2. 在C##STUDENT模式下执行该脚本(dbmshptab.sql)

SQL> @D:\app\pdh\product\12.1.0\dbhome_2\RDBMS\ADMIN\dbmshptab.sql

Table dropped.


Table dropped.


Table dropped.


Sequence dropped.


Table created.


Comment created.


Table created.


Comment created.


Table created.


Comment created.


Sequence created.

3. 调试过程中遇到错误,留待后续解决

SQL> /* Formatted on 2018/11/20 23:19:53 (QP5 v5.256.13226.35538) */
SQL> DECLARE
  2     v_num      PLS_INTEGER;
  3     v_run_id   BINARY_INTEGER; --    run    ID    generated    by    the    profiler
  4
  5     FUNCTION test_func (num1 IN PLS_INTEGER, num2 IN PLS_INTEGER)
  6        RETURN PLS_INTEGER
  7     IS
  8     BEGIN
  9        RETURN (num1 + num2);
 10     END test_func;
 11  BEGIN
 12     DBMS_HPROF.START_PROFILING ('PLSHPROF_DIR', 'test.txt');
 13
 14     FOR i IN 1 .. 100000
 15     LOOP
 16        v_num := test_func (i - 1, i);
 17     END LOOP;
 18
 19     DBMS_HPROF.STOP_PROFILING;
 20
 21     --    Analyze    profiler    output    and    display    its    run    ID
 22     v_run_id := DBMS_HPROF.ANALYZE ('PLSHPROF_DIR', 'test.txt');
 23     DBMS_OUTPUT.PUT_LINE (
 24           'Inline    pragma    is    not    enabled,    run    ID    -    '
 25        || v_run_id);
 26  END;
 27  /
DECLARE
*
ERROR at line 1:
ORA-29280: invalid directory path
ORA-06512: at "SYS.DBMS_HPROF", line 38
ORA-06512: at line 12

猜你喜欢

转载自blog.csdn.net/hpdlzu80100/article/details/84194678