SQLTXPLAIN
SQLTXPLAIN
SQLTXPLAIN
SQLTXPLAIN (SQLT): Tool that helps to diagnose SQL statements performing poorly
Program Agenda
<Insert Picture Here>
Overview Admin
Install/Uninstall/Upgrade
Standard Methods
XTRACT/XECUTE/XPLAIN/COMPARE
Advanced Methods
XTRXEC/PROFILE/XPLORE
Overview
Tool that helps to diagnose SQL statements performing poorly Often requested by Support or Development Latest version: Note 215187.1 Unwrapped code (SQL and PL/SQL) Not intrusive
SQLT does not expose application data Low/High column values and histograms can be hidden SQLT installs under its own schema
Installing SQLTXPLAIN
Requisites
Steps
Connect to SQL*Plus as SYS Uninstall a prior version with script (optional) sqlt/install/sqdrop.sql
doc documentation (includes this PPT and changes log) input to place input files for XECUTE and XPLAIN sample includes sample scripts install installation scripts run standard methods utl - PROFILE method and utilities xplore XPLORE method
Installation Parameters
sqlt/install/sqcreate.sql
UDUMP and STAGE directories Optional Connect Identifier SQLTXPLAIN password (case sensitive in some databases) SQLTXPLAIN Tablespaces (default and temp) Application schema name of main SQLT user Oracle Pack license
T for Oracle Tuning (and Oracle Diagnostic) Packs D for Oracle Diagnostic Pack N for None
Other SQLT users can be added using sqlt/install/sqguser.sql SQLT_USER_ROLE can also be granted directly
In most cases, nothing In some cases, an error is displayed in main report Unregistered user may not be able to see SQL Profiles or create an 11g test case using Oracle Test Case Builder
Installation Problems?
sqlt/install/sqcreate.sql
Create script disconnects in case of an error Installation logs are created in order Review most recent log Errors are self-explanatory
Uninstalling SQLTXPLAIN
Upgrading SQLTXPLAIN
Requisites
Steps
10
Standard Methods
Overview
XTRACT Finds SQL in memory and/or AWR XECUTE Actually executes SQL first then finds it XPLAIN Uses EXPLAIN PLAN FOR COMPARE Compares two executions of SQLT
11
Using XECUTE/XTRACT/XPLAIN
Requisites in Common
Should connect into SQL*Plus as the application user that issued original SQL to be analyzed
Only one SQL statement per use of SQLT SQL statement must be correct Semantically and syntactically
12
Requisites
SQL_ID or HASH_VALUE of SQL to be analyzed must be known before hand SQL must be in memory and/or in AWR
Steps
Connect to SQL*Plus as the application user for given SQL Execute script sqlt/run/sqltxtract.sql Provide as input parameter SQL_ID or HASH_VALUE # cd sqlt # sqlplus qtune/qtune SQL> START run/sqltxtract.sql cqkrws8pvc493
13
HASH_VALUE in all releases PARSING IN CURSOR #34 len=52 dep=0 uid=91 oct=47 lid=91 tim=1222426896737230 hv=1029988163 ad='3bce8ef0' SQL_ID in 11g PARSING IN CURSOR #9 len=210 dep=2 uid=0 oct=3 lid=0 tim=1255702184640591 hv=864012087 ad='3f94d318' sqlid='96g93hntrzjtr'
XTRACT Output
File sqlt_s92576.zip
15
SQL is not executed, saving resources if SQL is very slow Gets all known actual plans from memory and/or AWR RAC aware More diagnostics files and details than XPLAIN SQL Tuning Advisor and Test Case Builder are invoked Shows estimated and actual rows (statistics_level = ALL)
Cons
Trace 10053 may not be accurate if there are binds and bind peeking is enabled
16
Requisites
SQL to be analyzed must be provided within a text file Declare and initialize bind variables in same file
Steps
Connect to SQL*Plus as the application user for given SQL Execute script sqlt/run/sqltxecute.sql
17
Sample Script
sqlt/run/input/sample/script0.sql
select v.*, (orders_total - credit_limit) over_limit from customer_v v /* ^^unique_id */ where orders_total > credit_limit and customer_type = :b1 order by over_limit desc;
18
SQLT XECUTE will act only on last SQL in script SQL must end with semi-colon ";" Script must be able to execute stand-alone. Example:
19
XECUTE Output
File sqlt_s62831.zip
20
Generates a combined EVENT 10046 and 10053 trace EVENT 10053 trace is accurate (includes actual plan) Additional SQL execution metrics Invokes TKPROF on generated EVENT 10046 trace Invokes Trace Analyzer on 10046 More diagnostics files and details than XPLAIN SQL Tuning Advisor and Test Case Builder are invoked Shows estimated and actual rows (statistics_level = ALL)
Cons
21
Requisites
Steps
Connect to SQL*Plus as the application user for given SQL Execute script sqlt/run/sqltxplain.sql
22
Sample Script
sqlt/run/input/sample/sql0.sql
select v.*, (orders_total - credit_limit) over_limit from customer_v v where orders_total > credit_limit and customer_type = :b1 order by over_limit desc;
23
Leave the binds in place, or carefully replace them with literals of same data type Be aware of implicit data type conversions Verify explain plan is same as observed on existing TKPROF Explain plan created by XPLAIN may not be accurate
Rationale
XPLAIN uses EXPLAIN PLAN FOR command which is blind to bind peeking
24
XPLAIN Output
File sqlt_s62832.zip
25
Easy to use SQL is not executed, saving resources if SQL is very slow Accurate plan if there are no binds or bind peeking is disabled
Cons
Plan may not be accurate if there are binds and bind peeking is enabled Generates less diagnostics files than XTRACT or XECUTE SQL Tuning Advisor and Test Case Builder are not invoked Unless same SQL text is present in memory Shows estimated rows but not actual rows
26
XECUTE/XTRACT/XPLAIN
Generated Files
XTRACT, XECUTE and XPLAIN common output files XTRACT and XECUTE additional output files XECUTE additional output files
Method (XTRACT, XECUTE or XPLAIN) Release (11g or 10g) Tool parameters Schema objects related to SQL passed
27
XTRACT/XECUTE/XPLAIN
Main html report for diagnostics startup Export DMP file with SQLT repository for SQL Lite text report with just the plan and basic statistics Readme for further diagnostics Metadata script for TC creation Set CBO environment script for TC Set System Statistics for TC Event 10053 tracing the CBO Custom SQL Profile script STA and TCB (?) Log file Source SQL
28
Dynamic Content
29
30
XECUTE
Combined 10046 and 10053 TKPROF on 10046 Trace Analyzer files Split of 10046 and 10053 PX Traces, TKPROFs, TRCA
31
Output Overlap
in terms of content
XPLAIN
XTRACT
XECUTE
32
Requisites
SQLT installed in both SOURCES and in TARGET This means 1, 2 or 3 systems are involved
Steps
Import SQLT repositories from SOURCES into TARGET Only if SOURCE and TARGET are different systems Use syntax provided in readme or script within export.zip
33
COMPARE Method
What is compared?
SQL Text SQL Identification Environment CBO Environment Fix Control CBO System Statistics Execution Plan Tables and Partitions Indexes and Partitions Columns
34
Advanced Methods
Overview
XTRXEC Combines XTRACT and XECUTE PROFILE Creates a custom SQL Profile XPLORE Discovers plans for one SQL
35
Requisites
SQL_ID or HASH_VALUE of SQL to be analyzed must be known before hand SQL must be in memory and/or in AWR
Steps
Connect to SQL*Plus as the application user for given SQL Execute script sqlt/run/sqltxtrxec.sql Provide as input parameter SQL_ID or HASH_VALUE # cd sqlt # sqlplus qtune/qtune SQL> START run/sqltxtrxec.sql cqkrws8pvc493
36
XTRXEC Output
File sqlt_s62833_sqlt_s62834.zip
37
Requisites
Steps
Provide statement id and plan hash value when asked # cd sqlt # sqlplus qtune/qtune SQL> START utl/sqltprofile.sql
38
Best Plan
Find best plan according to performance statistics Short term solution to a SQL performance issue
39
Set of directive hints to the CBO associated to one signature (different than STA soft scaling hints) Signature is a function of SQL text Spaces, line feeds, tabs, upper/lower are ignored PROFILE is executed automatically by standard methods on best plan for a given SQL Best is defined in terms of average elapsed time To create SQL Profile you have to actually execute the output of PROFILE method on same or similar system Always review PROFILE script before implementing it
40
SQL performs poorly or returns wrong results while using a "bad" plan The bad plan can be reproduced on a test system (no data is preferred) A "good" plan can be reproduced on the test system by switching OFE You need to narrow reason to specific parameter or bug fix control You have full access to the test system, including SYS access
41
The SQL statement may cause corruption or update data There is high volume of data in tables referenced by SQL The execution of the SQL may take longer than a few seconds
Steps
Refer to sqlt/utl/xplore/readme.txt
42
Utilities
43
Utilities
44
References Note 215187.1 SQLTXPLAIN (SQLT) Note 224270.1 Trace Analyzer (TRCA) FAQ Refer to sqlt/sqlt_instructions.html
45