My sqlplus script xplan has been designed to dump, in a concise and complete text report, all the
informations that are needed to tune a SGA-resident SQL statement.
When tuning (or simply studying) a statement, one typically needs or eagerly wants:
the accessed tables definition (columns, indexes, partitions) and their CBO-related statistics
the text of referenced views, PL/SQL functions or packages (and sequences, evil triggers, etc)
its plan, and for every plan line, its performance measures (i.e. elapsed time, buffer gets, rows returned,
etc)
peeked bind values and types
instance and session parameters, and system statistics
wait event profile from ASH (Active Session History)
Christian Antognini
Connor McDonald
Jonathan Lewis
Julian Dyke
Oak Table
Steve Adams
Tom Kyte
All these informations are automatically dumped by xplan, sparing us from a lot of tedious and error-prone
work.
Wolfgang Breitling
You can identify the statement(s) you want in the report by matching a like-expression, or by sql_id,
hash_value, module, action, instance_id, parsing user, or a combination of them. E.g.:
SQL>@xplan "select%my_table%" "module=MY_MODULE,parsed_by=WEB_USER"
This dumps all select statements that reference my_table, issued by module MY_MODULE and parsed by
WEB_USER.
Blogroll (alphabetical order)
Please note that since xplan is a sqlplus script, you don't need to install anything anywhere - you just
need sqlplus and an account with the necessary privileges.
Chen Shapira
CBO Development Group
Christian Antognini
You can find more details in the main script (xplan.sql) header, and a report example below.
Coskan Gundogar
Report example
Doug Burns
Greg Rahn
A report example from Oracle 11g (from demo script xplan_showcase.sql) - comments in bold:
Statement text:
SELECT /*+ index(t,t_fbi) ordered use_nl(v) xplan_test_marker */ T.RR, PLSQL_FUNC(MAX(T.X)) FROM T, V WHERE UPPER(T.X) >= '0' AND T.X > :B1 AND V.RR
='x' GROUP BY T.RR ORDER BY T.RR
Names of non-table objects depended on (from v$object_dependency) - full definition at the bottom of the report:
- depends on view DELLERA.V
- depends on function DELLERA.PLSQL_FUNC
Peeked binds values, and bind infos:
bind_sensitive
peeked binds values: :B1 = 0
peeked binds types : :B1 = number(22)
Plan (format similar to dbms_xplan one) and most important infos (columns ending with "+" are self statistics):
-----------------------------------------------------------------------------------------------------------------------------|CR+CU |CR+CU+|Ela
|Ela+
|Id|Operation
|Name |Table|Erows |Arows
|Cost |IoCost|Psta|Psto|IdP|
-last---last---last-------last----------------------------------------------------------last---------------------------------|63,062|
=|13,099,838|
=| 0|SELECT STATEMENT
|
|
|
|
1|12,894|
|
|
|
|
|63,062|
=|13,099,838|+2,058,481| 1| SORT GROUP BY
|
|
|
1|
1|12,894|12,827|
|
|
|
|63,062|
=|11,041,357|+3,958,949| 2| NESTED LOOPS
|
|
|999,500|1,000,000|12,852|12,827|
|
|
|
| 1,050|
=|
479,553|
+4,061| 3|
PARTITION RANGE ITERATOR|
|
| 1,000|
1,000|
96|
96|KEY |3
| 3|
| 1,050|+1,000|
475,492|
+31,840| 4|
INDEX UNIQUE SCAN
|T_PK |T
| 1,000|
1,000|
96|
96|KEY |3
| 3|
|
50|
50|
443,652|
443,652| 5|
INDEX RANGE SCAN
|T_FBI|T
|
64|
1,000|
49|
49|KEY |3
| 3|
|62,012|
=| 6,602,855|+3,964,550| 6|
PARTITION RANGE ALL
|
|
| 1,000|1,000,000|
13|
13|1
|3
| 6|
|62,012|62,012| 2,638,305| 2,638,305| 7|
INDEX FAST FULL SCAN
|T_PK |T
| 1,000|1,000,000|
13|
13|1
|3
| 6|
---------------usec-------usec-----------------------------------------------------------------------------------------------.
4 - access[ T.X>:B1 AND T.SYS_NC00004$>='0' ]
.
5 - access[ T.X>:B1 AND T.SYS_NC00004$>='0' ]
.
- filter[ T.SYS_NC00004$>='0' ]
.
7 - filter[ (RR='x' AND X>0) ]
Wait event profile (from ASH):
---------------------------------|ash event
|cnt|%
|
---------------------------------|cpu
| 10|76.9|
|db file sequential read| 3|23.1|
---------------------------------Main plan statistics:
CR=Consistent Reads, CU=CUrrent reads, diskR=Disk Reads, diskW=Disk Writes, etc.
---------------------------------------------------------------------------------------------------|Id|Starts|CR
|CR+
|CU |diskR|diskR+|diskW|E0ram|E1ram|Aram |Policy|A01M
|0/1/M|ActTim
|
----last---last---last---last-last--last---last--------------last---------last----------avg--------| 0|
1|63,062|
=|
0| 103|
=|
0|
|
|
|
|
|
|
|
| 1|
1|63,062|
=|
0| 103|
=|
0|3,072|3,072|2,048|MANUAL|OPTIMAL|1/0/0|132,552,130|
| 2|
1|63,062|
=|
0| 103|
=|
0|
|
|
|
|
|
|
|
| 3|
1| 1,050|
=|
0|
51|
=|
0|
|
|
|
|
|
|
|
| 4|
3| 1,050|+1,000|
0|
51|
+1|
0|
|
|
|
|
|
|
|
| 5|
3|
50|
50|
0|
50|
50|
0|
|
|
|
|
|
|
|
| 6| 1,000|62,012|
=|
0|
52|
=|
0|
|
|
|
|
|
|
|
| 7| 3,000|62,012|62,012|
0|
52|
52|
0|
|
|
|
|
|
|
|
-------------------------------------------------KB----KB----KB-------------------#-----msec-------note: stats Aram, A01M, 0/1/M, ActTim do not seem to be always accurate.
Additional plan details (qb_name, alias, column projection information):
----------------------------------------------------------------------------------------------|Id|Qb_name
|ObjAlias|ObjType
|Obj |BaseObj|Projection
|
----------------------------------------------------------------------------------------------| 0|
|
|
|
|
|
|
| 1|SEL$F5BB74E1|
|
|
|
|(#keys=1)T.RR,MAX(T.X)
|
| 2|
|
|
|
|
|T.X,T.RR
|
| 3|
|
|
|
|
|T.X,T.RR
|
| 4|SEL$F5BB74E1|T@SEL$1 |INDEX (UNIQUE)|T_PK |T
|T.X,T.RR
|
| 5|SEL$F5BB74E1|T@SEL$1 |INDEX
|T_FBI|T
|T.ROWID,T.X,T.RR,T.SYS_NC00004$,T.ROWID|
| 6|
|
|
|
|
|
|
| 7|SEL$F5BB74E1|T@SEL$2 |INDEX (UNIQUE)|T_PK |T
|
|
----------------------------------------------------------------------------------------------CBO-related parameters different from instance ones:
WARNING: 6 params in gv$sql_optimizer_env are not the same as instance ones:
---------------------------------- -------------------------------- ------------------------------|optimizer param name
|value
| |optimizer param name |value
| |optimizer param name |value |
---------------------------------- -------------------------------- ------------------------------|_smm_auto_cost_enabled | false | |sort_area_size
|2000000 | |statistics_level
|
all |
|hash_area_size
|2000000 | |sqlstat_enabled
|
true | |workarea_size_policy |manual |
---------------------------------- -------------------------------- ------------------------------Accessed table(s) informations:
############################################# table DELLERA.T ###
PARTITIONED BY RANGE ( X, PADDING )
IOT
Accessed table columns definitions and constraints :
Note that the FBI expression for hidden columns is provided
Note the concise index/constraint report on the right
E.g. Index #4 is a Unique index on (X,PADDING)
Index #1 is a non-unique index on (X, UPPER(TO_CHAR("X")), PADDING )
Primary Key is on (X,PADDING)
Unique Constraint U2 is on (PADDING,X)
Unique Constraint U1 is referenced (R) by some FK from another table
Foreign Key R1 is from column RR
---------------------------------------------------------------------|Id|IId|V|ColName
|Type
|Null|Expression|1|2|3|4|5|
-------------------------------------------------trunc------------U-U| 1| 1|N|X
|NUMBER
|NOT |
|1|1|2|1| |
| 2| 2|N|PADDING
|VARCHAR2 (1200 byte)|NOT |
|3| |1|2|1|
| 3| 3|N|RR
|VARCHAR2 (1 byte)
|yes |
| | | | | |
| | 4|Y|SYS_NC00004$|VARCHAR2 (40 byte) |yes |I:UPPER(TO|2| | | | |
| | 5|Y|SYS_NC00005$|VARCHAR2 (6 byte)
|yes |I:CASE "X"| |2| | | |
------------------------------------------------------------------------------------------------------|Id|IId|V|ColName
|P|U1|U2|R1|
---------------------------------| 1| 1|N|X
|1| |2 | |
| 2| 2|N|PADDING
|2|R1|1 | |
| 3| 3|N|RR
| | | |1 |
| | 4|Y|SYS_NC00004$| | | | |
| | 5|Y|SYS_NC00005$| | | | |
return varchar2
is
begin
return p;
end plsql_func;
############################################# view DELLERA.V ###
view columns: #1 X(NUMBER),#2 PADDING(VARCHAR2),#3 RR(VARCHAR2)
select x, padding, rr
from t
where x > 0
Options and Statement text filter SQL-like expression summary:
OPTIONS: inst_id=1 plan_stats=last access_predicates=Y lines=150 ash_profile_mins=15 module= action= hash= sql_id= parsed_by= child_number=
dbms_xplan=N dbms_metadata=N plan_details=Y plan_env=Y tabinfos=Y objinfos=Y partinfos=Y self=Y order_by= numbers_with_comma=Y
spool_name=xplan_i1.lst spool_files=single
SQL_LIKE="%xplan_test_marker%"
Licence warning:
-- Warning: since ash_profile_mins > 0, you are using ASH/AWR; make sure you are licensed to use it.