在HelloDBA网站找到一个分析sql性能的工具—showplan,记录一下

showplan.sql下载路径:http://www.HelloDBA.com/Download/showplan.zip

使用方式就是调用该工具,传入SQL_ID作为参数。

SQL> @/dmp/showplan.sql 26xj87b2f8g6u

---showplan.sql

-- ################################################################################
-- #
-- # name: showplan.sql v1.0
-- #
-- # File: showplan.sql
-- # Description: Show SQL Plan and performance details
-- # Usage: @showplan <SQL_ID> [Plan Hash Value] [Details: [+](B)inds|SQL (T)ext|(Pee(K)ed Binds|(P)lan|(O)utlines|Pre(D)icate|Plan (L)oading|(W)ait events|(S)tatistics]
-- # Created: 2014-03-12
-- # Author: Wei Huang
-- # Web Site: www.HelloDBA.com
-- #Latest Version: http://www.HelloDBA.com/download/showplan.zip
-- # User run as: dba
-- # Tested DB: 11gR2
-- # Parameters: 1: SQL_ID of SQL to be shown
-- # Parameters: 2: Plan Hash Value, if null (Default), will show all plans
-- # Parameters: 3: Details to be shown: [+](B)inds|SQL (T)ext|(Pee(K)ed Binds|(P)lan|(O)utlines|Pre(D)icate|Plan (L)oading|(W)ait events|(S)tatistics,
-- # default is BPDTLWS; + stand for the default options
-- #
-- # Copyright (c) 2014 Wei Huang
-- #
-- # History
-- # Modified by When Why
-- # ----------- ------- ----------------------------------------------------
-- ################################################################################
set autot off verify off feedback off pagesize 50000 lines 2000 long 10000000 longchunksize 10000000 serveroutput on size unlimited format wrapped buffer 99999999 head off
set termout off
col p1 noprint
col p2 new_value 2 noprint
col p3 new_value 3 noprint
select null p2, null p3 from dual where 1=2;
select nvl(upper(decode(upper('&2'),'NULL',null,upper('&2'))),null) p2, nvl(upper(decode(upper('&3'),'NULL','BPDTLWS',upper('&3'))),'BPDTLWS')||decode(instr('&3','+'),0,'','BPDTLWS') p3 from dual;
set termout on
clear columns
col xxx format a2000

prompt Usage: @showplan <SQL_ID> [Plan Hash Value] [Details: [+](B)inds|SQL (T)ext|(Pee(K)ed Binds|(P)lan|(O)utlines|Pre(D)icate|Plan (L)oading|(W)ait events|(S)tatistics]
prompt Description: Show SQL Plan
prompt

set termout off
var sqlid varchar2(32);
var planHashValue varchar2(32);
var showOptions varchar2(32);
begin select '&1', decode(upper('&2'),'NULL',null,'&2'), nvl(upper(decode(upper('&3'),'NULL','BPDTLWS',upper('&3'))),'BPDTLWS')||decode(instr('&3','+'),0,'','BPDTLWS') into :sqlid, :planHashValue, :showOptions from dual; end;
/
set termout on

with q as (select /*+materialize*/*
from (select sql_fulltext from v$sqlarea where sql_id=:sqlid
union all
select sql_text from dba_hist_sqltext
where sql_id=:sqlid and not exists (select 1 from v$sqlarea where sql_id=:sqlid))),
p as (select /*+materialize*/*
from (select m.SQL_ID,SQL_PLAN_HASH_VALUE PLAN_HASH_VALUE,PLAN_LINE_ID ID,PLAN_PARENT_ID PARENT_ID,
PLAN_OPERATION OPERATION,p.OTHER_TAG,PLAN_OPTIONS OPTIONS,PLAN_OBJECT_NAME OBJECT_NAME,
PLAN_OBJECT_TYPE OBJECT_TYPE,p.OPTIMIZER,PLAN_COST COST,OUTPUT_ROWS||' rows' CARDINALITY,
PHYSICAL_READ_BYTES+PHYSICAL_WRITE_BYTES||'/'||PLAN_BYTES BYTES,
p.access_predicates, p.filter_predicates, p.parsing_schema_name
from v$sql_plan_monitor m, (select p.SQL_ID, p.PLAN_HASH_VALUE, p.ID, p.CHILD_ADDRESS, p.OTHER_TAG,
p.OPTIMIZER, p.access_predicates, p.filter_predicates, q.parsing_schema_name
from v$sql_plan p, v$sql q
where p.SQL_ID=:sqlid AND (:planHashValue is NULL or p.PLAN_HASH_VALUE=to_number(:planHashValue))
and p.sql_id=q.sql_id(+) and p.CHILD_ADDRESS=q.CHILD_ADDRESS(+)
union
select p.SQL_ID, p.PLAN_HASH_VALUE, ID, null CHILD_ADDRESS, p.OTHER_TAG,
p.OPTIMIZER, access_predicates, p.filter_predicates, q.parsing_schema_name
from dba_hist_sql_plan p, dba_hist_sqlstat q
where p.SQL_ID=:sqlid AND (:planHashValue is NULL or p.PLAN_HASH_VALUE=to_number(:planHashValue))
and p.sql_id=q.sql_id(+) and p.PLAN_HASH_VALUE=q.PLAN_HASH_VALUE(+)
and not exists (select 1 from V$SQL_PLAN p1
where p1.SQL_ID=:sqlid AND (:planHashValue is NULL or p1.PLAN_HASH_VALUE=to_number(:planHashValue)))) p
where m.SQL_ID=:sqlid AND (:planHashValue is NULL or m.SQL_PLAN_HASH_VALUE=to_number(:planHashValue))
and last_refresh_time = (select max(last_refresh_time) from v$sql_plan_monitor m
where m.SQL_ID=:sqlid AND (:planHashValue is NULL or m.SQL_PLAN_HASH_VALUE=to_number(:planHashValue)))
and m.SQL_ID=p.SQL_ID(+) and m.SQL_PLAN_HASH_VALUE=p.PLAN_HASH_VALUE(+) and m.PLAN_LINE_ID=p.ID(+) and m.SQL_CHILD_ADDRESS=p.CHILD_ADDRESS(+)
union
select p.SQL_ID,p.PLAN_HASH_VALUE, p.ID, p.PARENT_ID,p.OPERATION,p.OTHER_TAG,p.OPTIONS,p.OBJECT_NAME,
p.OBJECT_TYPE, p.OPTIMIZER,p.COST,''||p.CARDINALITY CARDINALITY,''||p.BYTES BYTES,
p.access_predicates, p.filter_predicates, q.parsing_schema_name
from V$SQL_PLAN p, v$sql q
where p.SQL_ID=:sqlid AND (:planHashValue is NULL or p.PLAN_HASH_VALUE=to_number(:planHashValue))
and p.child_number = (select max(child_number) from V$SQL_PLAN p1
where p1.SQL_ID=:sqlid AND (:planHashValue is NULL or p1.PLAN_HASH_VALUE=to_number(:planHashValue)))
and not exists (select 1 from v$sql_plan_monitor m
where m.SQL_ID=:sqlid AND (:planHashValue is NULL or m.SQL_PLAN_HASH_VALUE=to_number(:planHashValue)))
and p.sql_id=q.sql_id(+) and p.CHILD_ADDRESS=q.CHILD_ADDRESS(+)
union
select p.SQL_ID,p.PLAN_HASH_VALUE, p.ID, p.PARENT_ID,p.OPERATION,p.OTHER_TAG,p.OPTIONS,p.OBJECT_NAME,
p.OBJECT_TYPE,p.OPTIMIZER,p.COST,''||p.CARDINALITY CARDINALITY,''||p.BYTES BYTES,
p.access_predicates, p.filter_predicates, q.parsing_schema_name
from dba_hist_sql_plan p, dba_hist_sqlstat q
where p.SQL_ID=:sqlid AND (:planHashValue is NULL or p.PLAN_HASH_VALUE=to_number(:planHashValue))
and timestamp = (select max(timestamp) from dba_hist_sql_plan p1
where p1.SQL_ID=:sqlid AND (:planHashValue is NULL or p1.PLAN_HASH_VALUE=to_number(:planHashValue)))
and not exists (select 1 from v$sql_plan_monitor m
where m.SQL_ID=:sqlid AND (:planHashValue is NULL or m.SQL_PLAN_HASH_VALUE=to_number(:planHashValue)))
and not exists (select 1 from V$SQL_PLAN p1
where p1.SQL_ID=:sqlid AND (:planHashValue is NULL or p1.PLAN_HASH_VALUE=to_number(:planHashValue)))
and p.sql_id=q.sql_id(+) and p.PLAN_HASH_VALUE=q.PLAN_HASH_VALUE(+))),
pa as ( select /*+materialize*/sql_plan_hash_value plan_hash_value, sql_plan_line_id,
sql_plan_operation||' '||nvl(sql_plan_options,'') sql_plan_op,nvl(event, 'ON CPU') event,
TEMP_SPACE_ALLOCATED, PGA_ALLOCATED, current_obj#, count(*) over () total_waits
from v$active_session_history
where sql_plan_line_id is not null and sql_id=:sqlid AND (:planHashValue is NULL or SQL_PLAN_HASH_VALUE=to_number(:planHashValue))
union all
select sql_plan_hash_value plan_hash_value, sql_plan_line_id,
sql_plan_operation||' '||nvl(sql_plan_options,'') sql_plan_op,nvl(event, 'ON CPU') event,
TEMP_SPACE_ALLOCATED, PGA_ALLOCATED, current_obj#, count(*) over () total_waits
from dba_hist_active_sess_history
where not exists (select 1 from v$active_session_history
where sql_id=:sqlid AND (:planHashValue is NULL or SQL_PLAN_HASH_VALUE=to_number(:planHashValue)))
and sql_plan_line_id is not null and sql_id=:sqlid AND (:planHashValue is NULL or SQL_PLAN_HASH_VALUE=to_number(:planHashValue))),
pl as ( select plan_hash_value, sql_plan_line_id, sql_plan_op, total_waits, count(*) waits
from pa
group by plan_hash_value, sql_plan_line_id, sql_plan_op, total_waits),
we as (select pa.plan_hash_value, pa.event, o.owner||'.'||o.object_name||'('||o.object_type||')' wait_object,
count(*) waits, total_waits from pa, dba_objects o
where pa.current_obj#=o.object_id
group by pa.plan_hash_value, pa.event, o.owner, o.object_name, o.object_type, total_waits),
pb as (select /*+inline*/plan_hash_value,b.name,b.value,
decode(b.type#,
1, 'VARCHAR2('||b.maxlength||')',
2, decode(b.scale, null,
decode(b.precision#, null, 'NUMBER', 'FLOAT'),
'NUMBER'),
8, 'LONG',
9, 'VARCHAR('||b.maxlength||')',
12, 'DATE',
23, 'RAW', 24, 'LONG RAW',
69, 'ROWID',
96, 'CHAR('||b.maxlength||')',
100, 'BINARY_FLOAT',
101, 'BINARY_DOUBLE',
105, 'MLSLABEL',
106, 'MLSLABEL',
112, 'CLOB',
113, 'BLOB', 114, 'BFILE', 115, 'CFILE',
178, 'TIME(' ||b.scale|| ')',
179, 'TIME(' ||b.scale|| ')' || ' WITH TIME ZONE',
180, 'TIMESTAMP(' ||b.scale|| ')',
181, 'TIMESTAMP(' ||b.scale|| ')' || ' WITH TIME ZONE',
231, 'TIMESTAMP(' ||b.scale|| ')' || ' WITH LOCAL TIME ZONE',
182, 'INTERVAL YEAR(' ||b.precision#||') TO MONTH',
183, 'INTERVAL DAY(' ||b.precision#||') TO SECOND(' ||
b.scale || ')',
208, 'UROWID',
'UNDEFINED') data_type
from v$sql_plan m, xmltable('/*/peeked_binds/bind' passing xmltype(m.OTHER_XML)
columns name varchar2(4000) path '/bind/@nam',
type# varchar2(4000) path '/bind/@dty',
precision# varchar2(4000) path '/bind/@pre',
scale varchar2(4000) path '/bind/@scl',
maxlength varchar2(4000) path '/bind/@mxl',
value varchar2(4000) path '/bind') b
where m.sql_id = :sqlid and (:planHashValue is NULL or PLAN_HASH_VALUE=to_number(:planHashValue))
and trim(OTHER_XML) is not null),
mb as (select /*+inline*/m.sid,m.session_serial#,sql_id,b.name,b.data_type,b.value
from V$SQL_MONITOR m, xmltable('/binds/bind' passing xmltype(m.BINDS_XML)
columns name varchar2(30) path '/bind/@name',
data_type varchar2(30) path '/bind/@dtystr',
value varchar2(4000) path '/bind') b
where m.sql_id = :sqlid
and exists (select 1 from V$SQL_MONITOR m1
where m1.sid=m.sid and m1.session_serial#=m.session_serial# and m1.sql_id=m.sql_id
and (not exists (select 1 from v$sql_plan
where sql_id = :sqlid and (:planHashValue is NULL or PLAN_HASH_VALUE=to_number(:planHashValue)))
or exists (select 1 from v$sql_plan p
where sql_id = :sqlid and (:planHashValue is NULL or PLAN_HASH_VALUE=to_number(:planHashValue))
and m1.sql_child_address=p.child_address))
group by sid,session_serial#,sql_id
having max(m1.last_refresh_time)=m.last_refresh_time)
and m.BINDS_XML is not null),
ol as (select /*+inline*/plan_hash_value,b.hint
from v$sql_plan m, xmltable('/*/outline_data/hint' passing xmltype(m.OTHER_XML)
columns hint varchar2(4000) path '/hint') b
where m.sql_id = :sqlid and (:planHashValue is NULL or PLAN_HASH_VALUE=to_number(:planHashValue))
and trim(OTHER_XML) is not null),
bc as ( select distinct name,datatype,datatype_string,value_string from v$sql_bind_capture
where sql_id = :sqlid
and last_captured = (select max(last_captured) from v$sql_bind_capture c
where sql_id = :sqlid
and (not exists (select 1 from v$sql_plan
where sql_id = :sqlid and (:planHashValue is NULL or PLAN_HASH_VALUE=to_number(:planHashValue)))
or exists (select 1 from v$sql_plan p
where sql_id = :sqlid and (:planHashValue is NULL or PLAN_HASH_VALUE=to_number(:planHashValue))
and c.child_address=p.child_address)))),
bc1 as ( select distinct b.name,b.datatype,b.datatype_string,b.value_string,b.snap_id from dba_hist_sqlbind b, dba_hist_snapshot s
where b.sql_id = :sqlid and b.snap_id=s.snap_id and b.instance_number=s.instance_number
and not exists (select 1 from bc)
and b.snap_id = (select max(c.snap_id) from dba_hist_sqlbind c
where sql_id = :sqlid)),
cb as (select /*+materialize*/*
from (select LISTAGG('var '||substr(name,2)||' '||decode(datatype_string,'VARCHAR2(4001)','CLOB',datatype_string)||';' ,chr(10)) WITHIN GROUP (ORDER BY name) var,
LISTAGG('exec '||name||':='||nvl2(value_string,decode(datatype,1,'''','')||value_string||decode(datatype,1,'''','')||';','null;'),chr(10)) WITHIN GROUP (ORDER BY name) exe
from bc
union all
select LISTAGG('var '||substr(name,2)||' '||decode(datatype_string,'VARCHAR2(4001)','CLOB',datatype_string)||';' ,chr(10)) WITHIN GROUP (ORDER BY name) var,
LISTAGG('exec '||name||':='||nvl2(value_string,decode(datatype,1,'''','')||value_string||decode(datatype,1,'''','')||';','null;'),chr(10)) WITHIN GROUP (ORDER BY name) exe
from bc1
group by snap_id)
where (var is not null or exe is not null)),
sd as (select PLAN_HASH_VALUE, '1,Loads: '||q.LOADS||'; 2,Load Versions: '||q.LOADED_VERSIONS||'; 3,First Load Time: '||q.FIRST_LOAD_TIME||'; 4,Last Load Time: '||q.LAST_LOAD_TIME||'; 5,User Openings: '||q.USERS_OPENING||'; 6,Parse Calls: '||q.PARSE_CALLS||'; 7,Executions: '||q.EXECUTIONS||'; 8,Sorts(Average): '||round(q.SORTS/decode(nvl(q.EXECUTIONS,0),0,1,q.EXECUTIONS),3)||'; 9,Fetches(Average): '||round(q.FETCHES/decode(nvl(q.EXECUTIONS,0),0,1,q.EXECUTIONS),3)||'; 10,Disk Reads(Average): '||round(q.DISK_READS/decode(nvl(q.EXECUTIONS,0),0,1,q.EXECUTIONS),3)||'; 11,Buffer Gets(Average): '||round(q.BUFFER_GETS/decode(nvl(q.EXECUTIONS,0),0,1,q.EXECUTIONS),3)||'; 12,Elapsed Time(Average): '||ROUND(q.ELAPSED_TIME/1000/1000/decode(nvl(q.EXECUTIONS,0),0,1,q.EXECUTIONS),3)||' seconds; 13,CPU Time(Average): '||ROUND(q.CPU_TIME/1000/1000/decode(nvl(q.EXECUTIONS,0),0,1,q.EXECUTIONS),3)||' seconds; 14,Run Time Memory(Average): '||ROUND(q.RUNTIME_MEM/1024/1024/decode(nvl(q.EXECUTIONS,0),0,1,q.EXECUTIONS),3)||'M' str,
';' spliter
from (select PLAN_HASH_VALUE, sum(LOADS) LOADS, min(FIRST_LOAD_TIME) FIRST_LOAD_TIME, max(LAST_LOAD_TIME) LAST_LOAD_TIME,
sum(LOADED_VERSIONS) LOADED_VERSIONS, sum(USERS_OPENING) USERS_OPENING, sum(EXECUTIONS) EXECUTIONS,
sum(PARSE_CALLS) PARSE_CALLS, sum(SORTS) SORTS, sum(FETCHES) FETCHES, sum(DISK_READS) DISK_READS,
sum(BUFFER_GETS) BUFFER_GETS, max(RUNTIME_MEM) RUNTIME_MEM, sum(CPU_TIME) CPU_TIME,
sum(ELAPSED_TIME) ELAPSED_TIME
from v$sql
where sql_id=:sqlid and (:planHashValue is NULL or PLAN_HASH_VALUE=to_number(:planHashValue))
group by PLAN_HASH_VALUE
union
select PLAN_HASH_VALUE, max(LOADS_TOTAL) LOADS, null FIRST_LOAD_TIME, null LAST_LOAD_TIME,
max(LOADED_VERSIONS) LOADED_VERSIONS, 0 USERS_OPENING, max(EXECUTIONS_TOTAL) EXECUTIONS,
max(PARSE_CALLS_TOTAL) PARSE_CALLS, max(SORTS_TOTAL) SORTS, max(FETCHES_TOTAL) FETCHES,
max(DISK_READS_TOTAL) DISK_READS, max(BUFFER_GETS_TOTAL) BUFFER_GETS, 0 RUNTIME_MEM,
max(CPU_TIME_TOTAL) CPU_TIME, max(ELAPSED_TIME_TOTAL) ELAPSED_TIME
from dba_hist_sqlstat
where sql_id=:sqlid and (:planHashValue is NULL or PLAN_HASH_VALUE=to_number(:planHashValue))
and not exists (select 1 from v$sqlarea where sql_id = :sqlid and (:planHashValue is NULL or PLAN_HASH_VALUE=to_number(:planHashValue)))
group by PLAN_HASH_VALUE) q
where EXECUTIONS is not null and CPU_TIME is not null and ELAPSED_TIME is not null),
ss as (select /*+materialize*/*
from (select PLAN_HASH_VALUE, max(temp_size) temp_size, 0 pga_size
from (select t.SESSION_ADDR,nvl(q.PLAN_HASH_VALUE,99999999999999) PLAN_HASH_VALUE,
nvl(sum(t.BLOCKS*to_number(p.value)/1024/1024/1024),0) temp_size
from v$sort_usage t, v$parameter p, v$session s, v$sql q
where p.name = 'db_block_size' and t.sql_id=:sqlid
and t.SESSION_ADDR=s.saddr(+) and t.sql_id=s.sql_id(+)
and s.sql_id=q.sql_id(+) and s.sql_child_number=q.child_number(+)
and (:planHashValue is NULL or q.PLAN_HASH_VALUE is null or q.PLAN_HASH_VALUE=to_number(:planHashValue))
group by t.SESSION_ADDR,nvl(q.PLAN_HASH_VALUE,99999999999999))
group by PLAN_HASH_VALUE
union all
select nvl(q.PLAN_HASH_VALUE,99999999999999) PLAN_HASH_VALUE,0 temp_size, nvl(max(PGA_MAX_MEM/1024/1024/1024),0) pga_size
from v$process p, v$session s, v$sql q
where s.paddr=p.addr and s.sql_id = :sqlid
and s.sql_id=q.sql_id(+) and s.sql_child_number=q.child_number(+)
and (:planHashValue is NULL or q.PLAN_HASH_VALUE is null or q.PLAN_HASH_VALUE=to_number(:planHashValue))
group by nvl(q.PLAN_HASH_VALUE,99999999999999)
union all
select pa.PLAN_HASH_VALUE,nvl(max(TEMP_SPACE_ALLOCATED/1024/1024/1024),0) temp_size,
nvl(max(PGA_ALLOCATED/1024/1024/1024),0) pga_size
from pa
group by pa.PLAN_HASH_VALUE))
select /*+no_monitoring*/xxx
from (
select 0 PLAN_HASH_VALUE, 1 seq, 0 ID, 'SQL ID: '||:sqlid xxx from dual
union
select 0 PLAN_HASH_VALUE, 1 seq, 1 ID, chr(10)||'------------- Last Monitored Binds --------------' xxx from dual where exists (select 1 from mb) and instr(:showOptions,'B')>0
union
select 0 PLAN_HASH_VALUE, 2 seq, to_number(sid||'.'||session_serial#||'000001') ID,
'--SID: '||sid||','||session_serial#||chr(10)||LISTAGG('var '||substr(b.name,2)||' '||b.data_type,chr(10)) WITHIN GROUP (ORDER BY b.name) xxx
from mb b
where instr(:showOptions,'B')>0
GROUP BY sid,session_serial#,sql_id
union
select 0 PLAN_HASH_VALUE, 2 seq, to_number(sid||'.'||session_serial#||'000002') ID,
'--SID: '||sid||','||session_serial#||chr(10)||LISTAGG('exec '||b.name||':='||decode(instr(b.data_type,'NUMBER'),0,''''||b.value||''';',b.value),chr(10)) WITHIN GROUP (ORDER BY b.name) xxx
from mb b
where instr(:showOptions,'B')>0
GROUP BY sid,session_serial#,sql_id
union
select 0 PLAN_HASH_VALUE, 3 seq, 1 ID, chr(10)||'------------- Last Captured Binds --------------' xxx from dual where exists (select 1 from cb) and instr(:showOptions,'B')>0 and not exists (select 1 from mb)
union
select 0 PLAN_HASH_VALUE, 3 seq, 2 ID, var xxx from cb
where instr(:showOptions,'B')>0 and not exists (select 1 from mb)
union
select 0 PLAN_HASH_VALUE, 3 seq, 3 ID, exe xxx from cb
where instr(:showOptions,'B')>0 and not exists (select 1 from mb)
union
select 0 PLAN_HASH_VALUE, 10 seq, 0 ID, chr(10)||'------------- SQL Text --------------' xxx from dual
where instr(:showOptions,'T')>0
union
select *
from (select /*+no_merge*/0 PLAN_HASH_VALUE, 11 seq, level ID, to_char(substr(sql_fulltext,(level-1)*2000+1,2000)) sql_text
from q
where instr(:showOptions,'T')>0
connect by level<=ceil(length(sql_fulltext)/2000))
UNION
select distinct PLAN_HASH_VALUE, 30 seq, -1 ID, chr(10)||'------------- SQL Plan (Plan Hash Value:'||PLAN_HASH_VALUE||'; Parsed by schema:'||PARSING_SCHEMA_NAME||') --------------' xxx
from p
where instr(:showOptions,'P')>0
UNION
select *
from (SELECT /*+no_merge*/PLAN_HASH_VALUE, 31 seq, ID,
lpad(nvl2(access_predicates,'*','')||nvl2(filter_predicates,'#','')||ID,6,' ')||lpad('('||nvl(PARENT_ID||'',' ')||')',6,' ')||LPAD(' ',(LEVEL-1))||OPERATION||DECODE(OTHER_TAG,NULL,'','*')||DECODE(OPTIONS,NULL,'',' ('||OPTIONS||')')||DECODE(OBJECT_NAME,NULL,'',' OF '''||OBJECT_NAME||'''')||DECODE(OBJECT_TYPE,NULL,'',' ('||OBJECT_TYPE||')')||DECODE(ID,0,DECODE(OPTIMIZER,NULL,'',' Optimizer='||OPTIMIZER))||DECODE(COST,NULL,'',' (Cost='||COST||DECODE(CARDINALITY,NULL,'',' Card='||CARDINALITY)||DECODE(BYTES,NULL,'',' Bytes='||BYTES)||')') xxx --,OBJECT_NODE OBJECT_NODE_PLUS_EXP
FROM P
where instr(:showOptions,'P')>0
START WITH ID=0
CONNECT BY PRIOR ID=PARENT_ID AND PRIOR SQL_ID=SQL_ID AND PRIOR PLAN_HASH_VALUE=PLAN_HASH_VALUE)
UNION
select distinct PLAN_HASH_VALUE, 33 seq, 0 ID, chr(10)||'------------- Stored Outline (Plan Hash Value:'||PLAN_HASH_VALUE||') --------------' xxx
from OL
where instr(:showOptions,'O')>0
UNION
select PLAN_HASH_VALUE, 33 seq, 1 ID, '/*+' xxx from OL
where instr(:showOptions,'O')>0
UNION
select PLAN_HASH_VALUE, 33 seq, 2 ID, lpad(' ',3,' ')||'BEGIN_OUTLINE_DATA' xxx from OL
where instr(:showOptions,'O')>0
UNION
select PLAN_HASH_VALUE, 33 seq, 3 ID,lpad(' ',3,' ')||hint xxx from OL
where instr(:showOptions,'O')>0
union
select PLAN_HASH_VALUE, 33 seq, 4 ID, lpad(' ',3,' ')||'END_OUTLINE_DATA' xxx from OL
where instr(:showOptions,'O')>0
UNION
select PLAN_HASH_VALUE, 33 seq, 5 ID, '*/' xxx from OL
where instr(:showOptions,'O')>0
UNION
select distinct PLAN_HASH_VALUE, 35 seq, 0 ID, chr(10)||'------------- Peeked Binds (Plan Hash Value:'||PLAN_HASH_VALUE||') --------------' xxx
from pb
where instr(:showOptions,'K')>0
UNION
select PLAN_HASH_VALUE, 35 seq, 1 ID,
LISTAGG('var '||substr(name,2)||' '||data_type,chr(10)) WITHIN GROUP (ORDER BY name) xxx
from pb
where instr(:showOptions,'K')>0
group by PLAN_HASH_VALUE
UNION
select PLAN_HASH_VALUE, 35 seq, 2 ID,LISTAGG('exec '||name||':='||decode(instr(data_type,'NUMBER'),0,''''||value||''';',value),chr(10)) WITHIN GROUP (ORDER BY name) xxx
from pb
where instr(:showOptions,'K')>0
group by PLAN_HASH_VALUE
UNION
select distinct PLAN_HASH_VALUE, 36 seq, -1 ID, chr(10)||'------------- Predicate Information (Plan Hash Value:'||PLAN_HASH_VALUE||') --------------' xxx
from P
where ((access_predicates is not null) or (filter_predicates is not null))
and instr(:showOptions,'D')>0
UNION
select PLAN_HASH_VALUE, 36 seq, ID,lpad(id,3,' ')||' Access: '||access_predicates xxx
from P
where (access_predicates is not null)
and instr(:showOptions,'D')>0
union
select PLAN_HASH_VALUE, 36 seq, ID,lpad(id,3,' ')||' Filter: '||filter_predicates xxx
from P
where (filter_predicates is not null)
and instr(:showOptions,'D')>0
union
select distinct P.PLAN_HASH_VALUE, 50 seq, -1 ID, chr(10)||'------------- Plan Loading (Plan Hash Value:'||P.PLAN_HASH_VALUE||') --------------' xxx
from P, PL
where P.PLAN_HASH_VALUE=PL.PLAN_HASH_VALUE and p.ID=SQL_PLAN_LINE_ID
and total_waits>0
and instr(:showOptions,'L')>0
UNION
select P.PLAN_HASH_VALUE, 50 seq, PL.TOTAL_WAITS-PL.WAITS ID,
lpad(P.ID,3,' ')||': '||RPAD(PL.sql_plan_op,50,' ')||rpad('#',round(pl.waits/pl.total_waits*50),'#')||'('||round(pl.waits/pl.total_waits*100,2)||'%)' xxx
from P, PL
where P.PLAN_HASH_VALUE=PL.PLAN_HASH_VALUE and p.ID=SQL_PLAN_LINE_ID
and PL.total_waits>0
and instr(:showOptions,'L')>0
union
select distinct PLAN_HASH_VALUE, 55 seq, -1 ID, chr(10)||'------------- Waits Events (Plan Hash Value:'||PLAN_HASH_VALUE||') --------------' xxx
from we
where total_waits>0
and instr(:showOptions,'W')>0
UNION
select PLAN_HASH_VALUE, 55 seq, TOTAL_WAITS-WAITS ID,
rpad(event||' on '||wait_object,75,' ')||rpad('#',round(waits/total_waits*50),'#')||'('||round(waits/total_waits*100,2)||'%)' xxx
from we
where total_waits>0
and instr(:showOptions,'W')>0
union
select PLAN_HASH_VALUE, 60 seq, 1 ID, chr(10)||'------------- Statistics Data '||decode(PLAN_HASH_VALUE,99999999999999,'','(Plan Hash Value:'||PLAN_HASH_VALUE||')')||'--------------' xxx from sd
where instr(:showOptions,'S')>0
union
select PLAN_HASH_VALUE, 60 seq,
10+to_number(substr(str,1,instr(str,',')-1)) ID, substr(str,instr(str,',')+1) xxx
from (select PLAN_HASH_VALUE, trim(regexp_substr(str, '[^'||spliter||']+', 1, level)) str from sd
connect by level <= length (regexp_replace (str, '[^'||spliter||']+')) + 1)
union
select PLAN_HASH_VALUE, 60 seq, 101 ID,
'PGA Size(Maximum): '||round(max(nvl(pga_size,0)),3)||'G' xxx
from ss
where instr(:showOptions,'S')>0
group by PLAN_HASH_VALUE
union
select PLAN_HASH_VALUE, 60 seq, 102 ID,
'Temp Space(Maximum): '||round(max(nvl(temp_size,0)),3)||'G' xxx
from ss
where instr(:showOptions,'S')>0
group by PLAN_HASH_VALUE
order by PLAN_HASH_VALUE, SEQ, ID, XXX)
;

undef 1 2 3
set head on
clear columns

转://使用showplan.sql分析sql Performance的更多相关文章

  1. 使用showplan.sql分析sql Performance

    在HelloDBA网站找到一个分析sql性能的工具-showplan,记录一下 showplan.sql下载路径:http://www.HelloDBA.com/Download/showplan.z ...

  2. MySQL SQL分析(SQL profile)

    分析SQL优化运营开销SQL的重要手段.在MySQL数据库.可配置profiling参数启用SQL分析.此参数可以在全局和session水平集.级别则作用于整个MySQL实例,而session级别紧影 ...

  3. 【转】Microsoft® SQL Server® 2012 Performance Dashboard Reports

    http://www.cnblogs.com/shanyou/archive/2013/02/12/2910232.html SQL Server Performance Dashboard Repo ...

  4. 品味性能之道<六>:图形化SQL分析工具

         在上一章里,重点分享了命令行SQL分析工具的使用方法.在本章将重点分享PL/SQL的SQL分析工具. 一.如何打开PL/SQL执行计划      开启PL/SQL这工具,推荐如下方法: 点击 ...

  5. 品味性能之道<五>:SQL分析工具

    一.SQL语句到底是怎么执行的? 想了解SQL语句到底是怎么执行的,那就需要进行SQL语句执行计划分析. 那什么是SQL语句执行计划呢? 就是Oracle服务器执行SQL语句的过程.例如确定是否使用索 ...

  6. 如何使用SQLPLUS分析SQL语句(查询执行计划跟踪)

    方法一:autotrace 1,  connect sys/密码 as sysdba,在sys用户下运行$ORACLE_HOME/sqlplus/admin/plustrce.sql这段sql的实际内 ...

  7. 使用show profiles分析SQL性能

    如何查看执行SQL的耗时 使用show profiles分析sql性能. Show profiles是5.0.37之后添加的,要想使用此功能,要确保版本在5.0.37之后. 查看数据库版本 mysql ...

  8. mysql优化(三)–explain分析sql语句执行效率

    mysql优化(三)–explain分析sql语句执行效率 mushu 发布于 11个月前 (06-04) 分类:Mysql 阅读(651) 评论(0) Explain命令在解决数据库性能上是第一推荐 ...

  9. 【MS SQL】通过执行计划来分析SQL性能

    原文:[MS SQL]通过执行计划来分析SQL性能 如何知道一句SQL语句的执行效率呢,只知道下面3种: 1.通过SQL语句执行时磁盘的活动量(IO)信息来分析:SET STATISTICS IO O ...

随机推荐

  1. Docker入门之一Docker在Window下安装

    最近这几年,各个大公司都在打造自己的云平台,什么阿里云,华为云,腾讯云等等云,以及各种的微服务架构,其实在这当中Docker容器技术算是一个很重要的角色. 一.下载 在下载之前首先检查一下自己的电脑是 ...

  2. [PHP]算法- 二叉树的深度的PHP实现

    二叉树的深度: 输入一棵二叉树,求该树的深度.从根结点到叶结点依次经过的结点(含根.叶结点)形成树的一条路径,最长路径的长度为树的深度. 思路: 1.非递归层序遍历 2.使用辅助队列,根结点先入队列 ...

  3. elasticsearch6.7 05. Document APIs(10)Reindex API

    9.REINDEX API Reindex要求为源索引中的所有文档启用_source. reindex 不会配置目标索引,不会复制源索引的设置.你需要在reindex之前先指定mapping,分片数量 ...

  4. 关于eclipse项目的x号报错的一些问题

    有些时候项目中并未有什么问题 但项目前会有一个X号报错且无法运行项目 我们不妨从jre和Tomcat的一些配置中找原因 1,首先查看jre的安装是否正确,可以看见并未出错 ,如果有问题,重新导入一下即 ...

  5. Python编程-从入门到实践 Eric Matthes 著 袁国忠 译 - - 第二章 动手试一试

    因为第一章的动手试一试基本都是探索性的,所以直接进入第二章. # 2.2 动手试一试 # 2_1 简单消息: 将一条消息存储到变量中,再将其打印出来. message = 'python 编程从入门到 ...

  6. AIMLBot (中文自动回复)文本自动回复机器人

    https://github.com/chivandikwa/AIMLBot (csharp) https://github.com/gunthercox/ChatterBot (python) ht ...

  7. 【代码笔记】Web-JavaScript-JavaScript 变量

    一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  8. DB、ETL、DW、OLAP、DM、BI关系 ZT

    在此大概用口水话简单叙述一下他们几个概念: (1)DB/Database/数据库——这里一般指的就是OLTP数据库,在线事物数据库,用来支持生产的,比如超市的买卖系统.DB保留的是数据信息的最新状态, ...

  9. 活字格Web应用平台学习笔记 8 - 查询记录

    基础教程只剩一点点了,学完算了. 这一课的目标是:查询记录 这个操作的原理很简单,增加一个表格,绑定“部门”那个数据,然后增加一个命令,点击查询. 绑定命令: 完成后的实际界面,查询前面是个下拉框: ...

  10. TCP协议学习总结

    1.TCP协议通过三次握手建连接,四次挥手断连接. 2.TCP的定时器都有哪些? 做什么用途? 3.TCP的慢启动是什么意思? 4.TCP的快速重传是什么意思?