Вы находитесь на странице: 1из 45

1

2
<Insert Picture Here>
How to create in 5 minutes a SQL Tuning Test Case using
SQLTXPLAIN
Carlos Sierra
Consulting Technical Advisor
Copyright 2013, Oracle and/or its affiliates
3
Carlos Sierra
Job/Hobby: SQL Tuning frequent practitioner
Experience: Oracle since 1996
Home: Orlando, Florida
Besides SQL Tuning: Spinning, Biking, Racquetball and Parenting!
Author of: SQLTXPLAIN (SQLT), TRCANLZR (TRCA), SQLHC, etc.

Consulting Technical Advisor - Center of Expertise (CoE)
4
About SQLTXPLAIN (SQLT)
Tool to diagnose SQL statements performing poorly
Comprehensive set of diagnostics reports
Automatic Test Case (TC) extraction
Not a product but an add-on tool
Needs to be installed
Used by Oracle Support since 1999
Works on 11g and 10.2 (UNIX, Linux and Windows)
Prior versions for 10.1, 9i and 8.1 are available

Copyright 2013, Oracle and/or its affiliates
5
Topics
A Test Case (TC) for SQL Tuning
How SQLTXPLAIN (SQLT) helps with a TC?
What is included in a SQLT TC?
Demo of SQLT TC implementation
Beyond a SQLT TC
Q&A
Copyright 2013, Oracle and/or its affiliates
6
A Test Case (TC) for SQL Tuning
First Objective
Reproduce an Execution Plan from Source into Target system
What for?
Apply WHAT-IF scenarios which are not feasible to test in
Source system
Investigate unexpected results
Two-phases
Extraction and implementation
Copyright 2013, Oracle and/or its affiliates
7
What is needed to create a TC?
A similar system in terms of database release
Be aware of possible one-offs
SQL text
Metadata to create schema objects
Tables, Indexes, Views
Functions, Packages, Constraints
CBO Statistics
Schema Objects
Copyright 2013, Oracle and/or its affiliates
8
What else is needed to create a TC?
Binds declaration and values
CBO Statistics
System Statistics
CBO Environment
Parameters
Fix Control
Schema owner(s) re-map
Common but not required

Copyright 2013, Oracle and/or its affiliates
9
Some Methods to extract a TC
Manual
Easy if Target contains same schema objects
Export and Import of CBO schema object statistics
What about CBO environment and System stats?
11g Test Case Builder (TCB)
Overloaded DBMS_SQLDIAG.EXPORT_SQL_TESTCASE
Inputs SQL from Memory, Text or Incident
Copyright 2013, Oracle and/or its affiliates
10
Some Methods to extract a TC
SQLTXPLAIN (SQLT) Test Case (TC)
Available for 11g, 10g and 9i
Inputs SQL from Memory, Text or AWR
Some SQLT dependencies
New internal SQLT Test Case Xpress (TCX)
Available for 11g and 10g (since November 2012)
No SQLT dependencies
Almost as complete as SQLT TC
Copyright 2013, Oracle and/or its affiliates
11
How SQLTXPLAIN helps with a TC?

SQLT XTRACT, XECUTE and XTRXEC
Automatic 11g TCB export on every 11g execution
If SQL is found in memory
Automatic SQLT TC/TCX extraction on every 10g/11g execution
If SQL is found in memory or AWR
SQLT XTRSBY and XPLAIN
Automatic SQLT TC/TCX extraction on every 10g/11g execution
SQLT on 9i provides a rudimentary TC
Copyright 2013, Oracle and/or its affiliates
12
SQLT TC/TCX implementation

SQLT TC provides two implementation modes
CUSTOM
Seven steps for better control during TC implementation
XPRESS
One driver script for a fast TC implementation
SQLT TCX provides one implementation mode
INSTALL
One driver script for a fast TCX implementation

Copyright 2013, Oracle and/or its affiliates
13
Where do I find the SQL TC?
Inside sqlt_sNNNNN.zip
Review sqlt_sNNNNN_main.html
SQLT TC implementation requires
Readme file sqlt_sNNNNN_readme.html
SQLT TC zip file sqlt_sNNNNN_tc.zip
Look for Implement SQLT Test Case (TC) on
readme file
Copyright 2013, Oracle and/or its affiliates
14
Files inside sqlt_sNNNNN_tc.zip
Copyright 2013, Oracle and/or its affiliates
XECUTE
XTRACT
XPLAIN
readme
sqlt tc
15
What is included in a SQLT TC?
TC zip contains several files
Most used by TC implementation
Some miscellaneous utilities
A readme file in text format
Copyright 2013, Oracle and/or its affiliates
16
What is included in a SQLT TC?
Metadata script
Create schema objects
Purge script
Avoid collisions on statement_id
Export DMP file
SQLT repository from Source
Restore script
Map and import CBO schema stats

Copyright 2013, Oracle and/or its affiliates
17
What is included in a SQLT TC?
System Statistics script
Set system stats in Target
Set CBO environment script
Set CBO Parameters
Set Fix Control
Test Case script
Execute Query
Produce Plan

Copyright 2013, Oracle and/or its affiliates
18
What is included in a SQLT TC?
XPRESS scripts
XPRESS.sh
XPRESS.sql
Miscellaneous utilities
Readme file
Copyright 2013, Oracle and/or its affiliates
19
About Metadata script
Creates TC user TCNNNNN
Schema owner re-map into TCNNNNN
Suffix to branch a TC
TC12345CS, TC12345A
Defaults (recommended)
Re-map: yes
Suffix: no
Copyright 2013, Oracle and/or its affiliates
20
About Metadata script
Always review Invalid section at end of execution
Invalid synonyms
Mostly safe to ignore
Invalid libraries
Sometimes require attention
Fix code
Invalid views
Always require attention
Eliminate references to schema names on FROM
Copyright 2013, Oracle and/or its affiliates
21
Metadata Customization Section
Copyright 2013, Oracle and/or its affiliates
22
About Purge script
SQLT repository for statement_id (NNNNN) is
about to be imported
Purge script deletes prior repository entries for
statement_id NNNNN
Avoids possible but very infrequent collisions on NNNNN
Copyright 2013, Oracle and/or its affiliates
23
About Purge script
Purge script becomes important when TC is refreshed
In such case manually drop user TCNNNNN before hand
DROP USER TCNNNNN CASCADE;
Purge script only executes a SQLT library
EXEC sqltxadmin.sqlt$a.purge_repository(93896, 93896);
Copyright 2013, Oracle and/or its affiliates
24
About Exported DMP file
DMP file is created on Source when SQLT is executed
XTRACT
XECUTE
XTRXEC
XTRSBY
XPLAIN
Contains SQLT repository for statement_id NNNNN
No application data is exported

Copyright 2013, Oracle and/or its affiliates
25
About Exported DMP file
Import gets SQLT repository for NNNNN including a
STATTAB staging table
imp sqltxplain FILE=sqlt_s93896_exp.dmp TABLES=sqlt% IGNORE=Y
Default utility is original export/import
SQLT can be configured to use Data Pump instead

Copyright 2013, Oracle and/or its affiliates
26
About Restore script
Restore (import) schema object CBO statistics for all
tables accessed by SQL
Re-maps CBO statistics to TCNNNNN user
Re-maps extended statistics columns
Expression or column group
Uses DBMS_STATS.IMPORT_TABLE_STATS
If re-map of owner is not desired use instead
sqlt/utl/sqltimp.sql
Copyright 2013, Oracle and/or its affiliates
27
About System Statistics script
Deletes CBO System Statistics on Target
Restores (set) using values from Source
Calls DBMS_STATS.DELETE_SYSTEM_STATS
Followed by DBMS_STATS.SET_SYSTEM_STATS
Copyright 2013, Oracle and/or its affiliates
28
About Set CBO Environment script
Captures CBO Environment from Source
SQLT session
Executed on Target after connecting as TC user
Sets Optimizer Features Enable (OFE)
Sets CBO Parameters
Using ALTER SESSION and ALTER SYSTEM commands
Sets Bug Fix Control
Copyright 2013, Oracle and/or its affiliates
29
About TC script (tc.sql)
Executes q.sql followed by plan.sql
Script q.sql contains SQL being analyzed
CBO environment for SQL when captured from memory
Bind variables (if applicable)
Declaration and values assignment
SQL text
Script plan.sql displays execution plan
Calls DBMS_XPLAN.DISPLAY_CURSOR
Copyright 2013, Oracle and/or its affiliates
30
About XPRESS scripts (sh and sql)
Shell script xpress.sh executes SQL script
xpress.sql connected as SYSDBA


Script xpress.sql executes all same 7 steps from
CUSTOM mode
TC implementation can be restarted from any
intermediate step
Copyright 2013, Oracle and/or its affiliates
31
About Miscellaneous Utilities and Files
SQL statement script q.sql
Display plan script plan.sql
Flush shared pool script flush.sql
EVENT 10053 script 10053.sql
Selectivity script sel.sql
Auxiliary selectivity script sel_aux.sql
Delete TC Histograms sqlt_sNNNNN_del_hgrm.sql
Text readme sqlt_sNNNNN_readme.txt
Setup script setup.sql for stand-alone TC
Copyright 2013, Oracle and/or its affiliates
32
SQLT TC implementation steps
Requirements
A sqlt_sNNNNN.zip file from Source system
A Target system with same database version (or higher)
Be aware of possible one-offs
SQLTXPLAIN installed on Target system
Copyright 2013, Oracle and/or its affiliates
33
SQLT TC implementation steps
Preparation
Unzip sqlt_sNNNNN.zip
Review main diagnostics report
Find Implement SQLT Test Case (TC) section in readme
Copy sqlt_sNNNNN_tc.zip file to Target server
Follow Preparation then XPRESS or CUSTOM mode
Copyright 2013, Oracle and/or its affiliates
34
Typical menu from a SQLT readme
Copyright 2013, Oracle and/or its affiliates
35
SQLT TC Preparation
Copyright 2013, Oracle and/or its affiliates
36
CUSTOM implementation mode
Copyright 2013, Oracle and/or its affiliates
37
CUSTOM implementation mode
Copyright 2013, Oracle and/or its affiliates
38
XPRESS implementation mode
Copyright 2013, Oracle and/or its affiliates
39
XPRESS script xpress.sql
Copyright 2013, Oracle and/or its affiliates
40
Demonstration
Implementing a SQLT TC using Xpress method
41
Beyond a SQLT TC
A TC enables a SQL Tuning environment on Test
After reproducing Execution Plan
Apply any WHAT-IF
If a regression try pre-upgrade OFE
If OFE produces good plan consider SQLT XPLORE
If suspecting statistics consider SQLT XHUME
Only on a disposable Test system
If suspecting histograms consider SQLT XGRAM
Copyright 2013, Oracle and/or its affiliates
42
Removing SQLT dependencies from
Test Case
To isolate TC from any SQLTXPLAIN dependencies
refer to Create TC with no SQLT dependencies on
readme
Copyright 2013, Oracle and/or its affiliates
43
Create TC with no SQLT dependencies
Copyright 2013, Oracle and/or its affiliates
44
References
MOS 215187.1 SQLTXPLAIN (SQLT)

carlos.sierra@oracle.com
http://carlos-sierra.net

Copyright 2013, Oracle and/or its affiliates
45

Вам также может понравиться