11

Objective

Find out a way to visually capture the recursive call trees in the TKPROF output (SYS=YES specified).

Environment

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
Windows 7 64 bit on DELL Latitude core i7 2.8GHz 8G memory & SSD HDD

Background

I am tryng to understand the effect of indexing and the performance indications as in the question Oacle 11G - Performance effect of indexing at insert.

To further understand what is happening behind the scene for indexing, run a SQL trace on a create index statement.

Execution

Run trace on the index creation (SQL towards the bottom) and run tkprof with "sys=yes" option.

SQL> ALTER TABLE TBL2 ADD CONSTRAINT PK_TBL2_COL1 PRIMARY KEY(COL1) ;
Table altered.
Elapsed: 00:00:01.75

> trcsess clientid="CREATE_INDEX" output="report_createindex.trc" *.trc
> tkprof createindex.trc output=createindex.txt sys=yes

Question

I would like to know if there is a way to visucaly capture the call hierarchy like explain plan from the trace (.trc) file with tkprof or with other tools.

The generated report includes recursive calls such as "ALTER TABLE TBL2 ADD" inducing "INDEX BUILD UNIQUE", and probably further sys recursive calls down the path. I suppose the output does not reflect the call-hierarchy (parent first, childs following immediately after).

TKPROF OUTPUT

SQL ID: 2w9c2khpsfj4m
Plan Hash: 3219312727
CREATE UNIQUE INDEX "TRY"."PK_TBL2_COL1" on "TRY"."TBL2"("COL1") NOPARALLEL


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          1          0           0
Execute      1      0.63       0.84       2999      15565       3173           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        2      0.63       0.85       2999      15566       3173           0

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 106     (recursive depth: 1)  <----------------- child?

Rows     Row Source Operation
-------  ---------------------------------------------------
      1  INDEX BUILD UNIQUE PK_TBL2_COL1 (cr=15904 pr=3003 pw=2090 time=0 us)(object id 0)
1000000   SORT CREATE INDEX (cr=15486 pr=2997 pw=0 time=208370 us)
1000000    TABLE ACCESS FULL TBL2 (cr=15486 pr=2997 pw=0 time=245360 us cost=4413 size=5000000 card=1000000)


Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  db file sequential read                       575        0.00          0.08
  db file scattered read                        138        0.00          0.07
  direct path write                               1        0.00          0.00
********************************************************************************

SQL ID: 47f85g3cmftry
Plan Hash: 0
ALTER TABLE TBL2 ADD CONSTRAINT PK_TBL2_COL1 PRIMARY KEY(COL1) 

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.20       0.64      15630      29477          3           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        2      0.20       0.64      15630      29477          3           0

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 106  <------------------------------------------ parent?

Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  db file sequential read                         4        0.00          0.00
  db file scattered read                        259        0.01          0.42
  db file parallel read                           2        0.00          0.00
  SQL*Net message to client                       1        0.00          0.00
  SQL*Net message from client                     1        0.00          0.00
********************************************************************************

SQL

CREATE TABLE TBL2 (
    "COL1" NUMBER,
    "COL2" VARCHAR2(100 BYTE)
    -- CONSTRAINT "PK_TBL2_COL1" PRIMARY KEY ("COL1")
);
INSERT INTO TBL2 /*+ APPEND MONITOR GATHER_PLAN_STATISTICS CONNECTBY_INSERT */
SELECT LEVEL, rpad(TO_CHAR(LEVEL),100,'A') FROM DUAL CONNECT BY LEVEL <= 1000000
COMMIT;    
---------------------------------------------------------------------------
-- Flush the buffers and clear the caches.
---------------------------------------------------------------------------
ALTER SYSTEM CHECKPOINT;
ALTER SYSTEM FLUSH SHARED_POOL;
ALTER SYSTEM FLUSH BUFFER_CACHE;
ALTER SYSTEM SWITCH LOGFILE;
---------------------------------------------------------------------------
-- Start monitoring
---------------------------------------------------------------------------
ALTER SESSION SET TRACEFILE_IDENTIFIER ='CREATE_INDEX';
ALTER SESSION SET TIMED_STATISTICS=true;
BEGIN
  DBMS_SESSION.SET_IDENTIFIER('CREATE_INDEX');
  DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE('CREATE_INDEX', waits=>true, binds=>false);
  DBMS_MONITOR.CLIENT_ID_STAT_ENABLE('CREATE_INDEX');
END;
/
---------------------------------------------------------------------------
-- Run the SQL to insert and monitor
---------------------------------------------------------------------------
SET PAGESIZE 200 
SET LINESIZE 200
SET TIMING ON
SET ECHO ON
SET AUTOTRACE ON

ALTER TABLE TBL2 ADD CONSTRAINT PK_TBL2_COL1 PRIMARY KEY(COL1) ;

SET AUTOTRACE OFF
SET ECHO OFF
SET TIMING OFF
---------------------------------------------------------------------------
-- Stop monitoring.
---------------------------------------------------------------------------
BEGIN
  DBMS_MONITOR.CLIENT_ID_TRACE_DISABLE('CREATE_INDEX');
  DBMS_MONITOR.CLIENT_ID_STAT_DISABLE('CREATE_INDEX');
END;
/

References

Sometimes, to execute a SQL statement issued by a user, Oracle Database must issue additional statements. ...

If recursive calls occur while the SQL Trace facility is enabled, then TKPROF produces statistics for the recursive SQL statements and marks them clearly as recursive SQL statements in the output file.

Cœur
  • 37,241
  • 25
  • 195
  • 267
mon
  • 18,789
  • 22
  • 112
  • 205
  • did you check http://antognini.ch/2008/10/introduce-tvdxtat/ ? AFAIK this tool presents the relation between the original SQL and the recursive SQLs – Marmite Bomber Jul 05 '15 at 19:49
  • 1
    Judging by the sort options the answer appears to be be "no". Tkprof tends to get used purely for tuning atomic queries rather than the process/procedure as a whole. I think the best best for call tree profiling is DBMS_PROFILER. – TenG Jul 05 '15 at 23:10

3 Answers3

3

I recommend the traceanalyzer. You can download it from oracle support. TRCANLZR (TRCA): SQL_TRACE/Event 10046 Trace File Analyzer - Tool for Interpreting Raw SQL Traces (Doc ID 224270.1)

The trace analyzer features a chapter "SQL Genealogy" which shows a tree like view of recursive SQL.

Once the traceanalyzer is installed, you invoke it with

@trcanlzr <name of tracefile>

You can even do this remotely from you client (copy the trcanlzr.sql script to your local SQLPATH). It will eventually copy the html-file containing the analysis to your client machine.

Jan
  • 66
  • 6
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – Shine Sep 24 '15 at 09:41
  • @Shine: this **does** answer the question. TRCA is better suited for this than TKPROF. Revealing more information from the MOS Document would violate the Oracle license –  Sep 25 '15 at 11:53
  • @Jan 3 out of three mods think the same as me, so I guess you should revise the concept of "answer" here: or you detail it with references and examples or just post a comment saying "if I were you I'd use TRCA" – Shine Sep 25 '15 at 14:28
  • I mean that the question is rich, detailed and shows research effort. It deserves more than a two-liner containing a reference to an Orcle tool – Shine Sep 25 '15 at 14:30
  • 2
    There is a lot of information but only one question: "I would like to know if there is a way to visucaly capture the call hierarchy like explain plan from the trace (.trc) file with tkprof or with other tools." That's what I answered. I don't know why all the other information was provided as it doesn't matter how the tracefile was created and why to answer this question. – Jan Sep 28 '15 at 14:46
  • @Jan Adding an example here would probably be enough to win the bounty. – Jon Heller Sep 30 '15 at 15:14
  • Thanks for the information. I asked the DBA and got the TRCA. Will try to learn how to use it and will update. – mon Oct 02 '15 at 19:33
1

Based on the information from @Jan, run the TRCA. I understand that SQL Genealogy is the call hierarchy and breakdown, but please provide any suggestions/corrections.

SQL

SET AUTOTRACE OFF
SET ECHO ON
SET TIMING OFF

DROP TABLE TBL2 PURGE;
CREATE TABLE TBL2 (
    "COL1" NUMBER,
    "COL2" VARCHAR2(100 BYTE)
    -- CONSTRAINT "PK_TBL2_COL1" PRIMARY KEY ("COL1")
);
INSERT INTO TBL2 /*+ APPEND MONITOR GATHER_PLAN_STATISTICS CONNECTBY_INSERT */
SELECT LEVEL, rpad(TO_CHAR(LEVEL),100,'A') FROM DUAL CONNECT BY LEVEL <= 1000000;
COMMIT;    
---------------------------------------------------------------------------
-- Start monitoring
---------------------------------------------------------------------------
ALTER SESSION SET TRACEFILE_IDENTIFIER ='CREATE_INDEX';
ALTER SESSION SET TIMED_STATISTICS=TRUE;
alter session set events '10046 trace name context forever, level 8';

---------------------------------------------------------------------------
-- Run the SQL to insert and monitor
---------------------------------------------------------------------------
ALTER TABLE TBL2 ADD CONSTRAINT PK_TBL2_COL1 PRIMARY KEY(COL1) ;

---------------------------------------------------------------------------
-- Stop monitoring.
---------------------------------------------------------------------------
alter session set events '10046 trace name context off'; 

TRCA

@run/trcanlzr.sql nr_ora_6976_CREATE_INDEX.trc

TOP SQL (CPU)

enter image description here

SQL Genealogy

enter image description here

mon
  • 18,789
  • 22
  • 112
  • 205
-1

I use orasrp for analyze trace files. Its generate html-reports with hierarchy plans in easy to read form. Also its easy to use (in console) -

orasrp in_trace.trc out_report.html
Stawros
  • 918
  • 1
  • 10
  • 20