Sie sind auf Seite 1von 45

<Insert Picture Here>

SQLTXPLAIN (SQLT): Tool that helps to diagnose SQL statements performing poorly

Carlos Sierra Center of Expertise CoE

Program Agenda
<Insert Picture Here>

Overview Admin

Install/Uninstall/Upgrade

Standard Methods

XTRACT/XECUTE/XPLAIN/COMPARE

Advanced Methods

XTRXEC/PROFILE/XPLORE

Utilities References and FAQ

2010 Oracle Corporation Proprietary and Confidential

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

Free download and use

2010 Oracle Corporation Proprietary and Confidential

Installing SQLTXPLAIN

Requisites and Steps

Requisites

Database release 11g or 10g Linux, Unix or Windows Operating Systems

Steps

Download sqlt.zip from Note 215187.1 Unzip sqlt.zip in server

Connect to SQL*Plus as SYS Uninstall a prior version with script (optional) sqlt/install/sqdrop.sql

Execute installation script sqlt/install/sqcreate.sql

2010 Oracle Corporation Proprietary and Confidential

SQLT Directory Structure

sqlt root directory and instructions

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

2010 Oracle Corporation Proprietary and Confidential

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

2010 Oracle Corporation Proprietary and Confidential

About SQLTXPLAIN Users

What if there is more than one SQLT user?

Installation grants SQLT_USER_ROLE to main SQLT user

Other SQLT users can be added using sqlt/install/sqguser.sql SQLT_USER_ROLE can also be granted directly

What happens if a SQLT user is not registered?

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

2010 Oracle Corporation Proprietary and Confidential

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

2010 Oracle Corporation Proprietary and Confidential

Uninstalling SQLTXPLAIN

Connect to SQL*Plus as SYS Execute script sqlt/install/sqdrop.sql

2010 Oracle Corporation Proprietary and Confidential

Upgrading SQLTXPLAIN

Requisites and Steps

Requisites

Prior version 11.0.1 or higher

Steps

Download sqlt.zip from Note 215187.1 Unzip sqlt.zip in server

Connect to SQL*Plus as SYS Execute script sqlt/install/sqcreate.sql

2010 Oracle Corporation Proprietary and Confidential

10

Standard Methods

Overview

Standard methods are in the sqlt/run directory

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

In case of a disconnect read log file

2010 Oracle Corporation Proprietary and Confidential

11

Using XECUTE/XTRACT/XPLAIN

Requisites in Common

SQLTXPLAIN tool must be pre-installed Regarding SQLT user

Must have access to sqlt/run directory or have a copy of it

Should connect into SQL*Plus as the application user that issued original SQL to be analyzed

Regarding input SQL statement

Only one SQL statement per use of SQLT SQL statement must be correct Semantically and syntactically

2010 Oracle Corporation Proprietary and Confidential

12

Using XTRACT Method

Requisites and Steps

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

2010 Oracle Corporation Proprietary and Confidential

13

Finding SQL_ID or HASH_VALUE

needed by XTRACT method

Available in AWR or StatsPack reports From 10046 Trace

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'

Both SQL_ID and HASH_VALUE are persistent


14

2010 Oracle Corporation Proprietary and Confidential

XTRACT Output

File sqlt_s92576.zip

2010 Oracle Corporation Proprietary and Confidential

15

XTRACT Pros and Cons

Overall rate Pros

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

2010 Oracle Corporation Proprietary and Confidential

16

Using XECUTE Method

Requisites and Steps

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

Provide as input parameter path and name of file with SQL

# cd sqlt # sqlplus qtune/qtune SQL> START run/sqltxecute.sql input/sample/script0.sql

2010 Oracle Corporation Proprietary and Confidential

17

Sample Script

sqlt/run/input/sample/script0.sql

VAR b1 CHAR(1); EXEC :b1 := '1';

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;

2010 Oracle Corporation Proprietary and Confidential

18

About Input Script

provided to XECUTE method

Force a hard-parse every time you use SQLT XECUTE:

Option 1: Include token /* ^^unique_id */ in any place

Option 2: Add a space in any place of the SQL text

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:

SQL> START script0.sql

Script can begin with ALTER SESSION commands

2010 Oracle Corporation Proprietary and Confidential

19

XECUTE Output

File sqlt_s62831.zip

2010 Oracle Corporation Proprietary and Confidential

20

XECUTE Pros and Cons

Overall rate Pros

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

SQL is executed, consuming resources if SQL is very slow

2010 Oracle Corporation Proprietary and Confidential

21

Using XPLAIN Method

Requisites and Steps

Requisites

SQL to be analyzed must be provided within a text file

Steps

Connect to SQL*Plus as the application user for given SQL Execute script sqlt/run/sqltxplain.sql

Provide as input parameter path and name of file with SQL

# cd sqlt # sqlplus qtune/qtune SQL> START run/sqltxplain.sql input/sample/sql0.sql

2010 Oracle Corporation Proprietary and Confidential

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;

2010 Oracle Corporation Proprietary and Confidential

23

About Bind Variables in SQL

while using XPLAIN method

If SQL has bind variables and bind peeking is enabled

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

If SQL has no binds or bind peeking is disabled

This XPLAIN method should provide an accurate explain plan

Rationale

XPLAIN uses EXPLAIN PLAN FOR command which is blind to bind peeking

2010 Oracle Corporation Proprietary and Confidential

24

XPLAIN Output

File sqlt_s62832.zip

2010 Oracle Corporation Proprietary and Confidential

25

XPLAIN Pros and Cons

Overall rate Pros

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

2010 Oracle Corporation Proprietary and Confidential

26

XECUTE/XTRACT/XPLAIN

Generated Files

One zip file with variable content

XTRACT, XECUTE and XPLAIN common output files XTRACT and XECUTE additional output files XECUTE additional output files

Variable content drivers

Method (XTRACT, XECUTE or XPLAIN) Release (11g or 10g) Tool parameters Schema objects related to SQL passed

Main html report provides variable content

2010 Oracle Corporation Proprietary and Confidential

27

XTRACT/XECUTE/XPLAIN

Common Output Files

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

2010 Oracle Corporation Proprietary and Confidential

Main HTML Report

Dynamic Content

2010 Oracle Corporation Proprietary and Confidential

29

XTRACT and XECUTE

Additional Output Files

SQLT TC script and sql Test Case Builder for 11g

2010 Oracle Corporation Proprietary and Confidential

30

XECUTE

Additional Output Files

Combined 10046 and 10053 TKPROF on 10046 Trace Analyzer files Split of 10046 and 10053 PX Traces, TKPROFs, TRCA

2010 Oracle Corporation Proprietary and Confidential

31

Output Overlap

in terms of content

XPLAIN

XTRACT

XECUTE

2010 Oracle Corporation Proprietary and Confidential

32

Using COMPARE Method

Requisites and Steps

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

Connect to SQL*Plus (any user) Execute script sqlt/run/sqltcompare.sql

Respond 4 input parameters 2 statement ids and 2 plan hash values

2010 Oracle Corporation Proprietary and Confidential

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

2010 Oracle Corporation Proprietary and Confidential

Advanced Methods

Overview

Advanced methods are in the run and utl directories

XTRXEC Combines XTRACT and XECUTE PROFILE Creates a custom SQL Profile XPLORE Discovers plans for one SQL

Use these methods only if requested by Support

2010 Oracle Corporation Proprietary and Confidential

35

Using XTRXEC Method

Requisites and Steps

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

2010 Oracle Corporation Proprietary and Confidential

36

XTRXEC Output

File sqlt_s62833_sqlt_s62834.zip

XTRACT output XECUTE output

2010 Oracle Corporation Proprietary and Confidential

37

Using PROFILE Method

Requisites and Steps

Requisites

A prior execution of SQLT XECUTE/XTRACT/XPLAIN Oracle Tuning Pack license

Steps

Connect to SQL*Plus Execute script sqlt/utl/sqltprofile.sql

Provide statement id and plan hash value when asked # cd sqlt # sqlplus qtune/qtune SQL> START utl/sqltprofile.sql

2010 Oracle Corporation Proprietary and Confidential

38

Creating Custom SQL Profile

Best Plan

Find best plan according to performance statistics Short term solution to a SQL performance issue

2010 Oracle Corporation Proprietary and Confidential

39

Remarks about Custom SQL Profiles

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

2010 Oracle Corporation Proprietary and Confidential

40

Using XPLORE Method

Requisites and Steps

Use XPLORE only when ALL these conditions are met

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

2010 Oracle Corporation Proprietary and Confidential

41

Using XPLORE Method

Requisites and Steps

Do not use XPLORE when ANY of these conditions is true

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

2010 Oracle Corporation Proprietary and Confidential

42

Utilities

Change stage directory sqlt/utl/sqltcdirs.sql

Restore schema object statistics sqlt/utl/sqltimp.sql

Restore fixed object statistics sqlt/utl/sqltimpfo.sql

2010 Oracle Corporation Proprietary and Confidential

43

Utilities

Create custom SQL Profile outside SQLT sqlt/utl/coe_xfr_sql_profile.sql

Get a prior SQLT file from repository sqlt/utl/sqlthistfile.sql

Purge SQLT repository sqlt/utl/sqlthistpurge.sql

2010 Oracle Corporation Proprietary and Confidential

44

References and FAQ

References Note 215187.1 SQLTXPLAIN (SQLT) Note 224270.1 Trace Analyzer (TRCA) FAQ Refer to sqlt/sqlt_instructions.html

2010 Oracle Corporation Proprietary and Confidential

45

Das könnte Ihnen auch gefallen