Beruflich Dokumente
Kultur Dokumente
Oracle Tuning Scripts
Oracle Tuning Scripts
SQLTXPLAIN.SQL
Erweiterter Explain Plan sowie Informationen zur Diagnose von SQL Statements (8.1.5-9.2.0)
Purpose
Given one SQL Statement as input, generate a comprehensive report that includes:
1. Enhanced Explain Plan,
2. Details about all schema objects in which the SQL statement depends on,
3. Rows count for all Tables accessed by the SQL Statement provided as input,
4. All Indexes and indexed columns for Tables reported,
5. CBO Stats at all levels for these Tables and Indexes,
6. Relevant INIT.ORA Parameters
The generated report includes extensive information that can be used to:
1. Expedite the data collection process requested by Oracle APPS Support when reporting one
FORM or Concurrent Program performing poorly (Note:169935.1),
2. Diagnose and troubleshoot typical SQL Tuning issues (specially valuable for both APPS and
non-APPS databases).
The scripts in this note supersede these two: COE_XPLAIN.SQL (Note:156958.1) and
COE_IMPORT_STATTAB.SQL (Note:156964.1).
Configuring SQLTXPLAIN.SQL
SQLTXPLAIN.SQL includes 6 seeded parameters. Leave the default seeded values unless you need
to modify according to particular requirements, or as per Support instructions:
1. p_days_to_keep_repo (30): Every execution of SQLTXPLAIN.SQL purges data from the
staging repository that is older than value specified.
2. p_compute_count_star (YES): Performs a COUNT(*) on all accessed Tables. It is useful to
determine if CBO Stats should be re-gathered.
3. p_include_col_stats (YES): CBO Stats for all indexed columns are always reported. When
this parameter is YES, CBO Stats for all table columns (besides indexed columns) are also
reported.
4. p_include_extents (NO): When set to YES, Segments and Extents are reported. This info
can be valuable when using in conjunction to raw SQL Trace generated by EVENT 10046
Level 8 (see Note:171647.1). Seeded value is NO because of known performance issues on
'ALL_' and 'DBA_' views.
5. p_include_histograms (YES): When set to YES, Table, Partition and Sub-partition
Histograms are included for all indexed columns or table columns (the latter if
p_include_col_stats is also set to YES).
6. p_include_source (YES): Controls if source code, on which the SQL Statement depends, is
reported or not (Triggers, Views, Packages, Procedures and Functions).
Before the staging SQLT$ repository is created (during the installation), you may want to change the
Tablespace to be used. See Installing SQLTXPLAIN.SQL and Staging Repository below.
If not sure if Staging Repository has been previously installed or not, simply re-install following same
instructions above. Once installed, you are ready to use the SQLTXPLAIN.SQL and
SQLTSTATTAB.SQL scripts concurrently.
If SQLTCPKGB.PLS errors with PLS-00201 while executed by SQLTCREATE.SQL, execute then
SQLTGRANT.SQL connecting into SQL*Plus with a user that has the privilege of granting SELECT ON
data dictionary views and ANALYZE ANY to another user (SYSTEM, SYS or INTERNAL). Inline
parameter is USER which will be executing SQLTXPLAIN.SQL and which tried to install
SQLTCREATE.SQL.
# sqlplus system/<system_pwd>
SQL> START SQLTGRANT.SQL <user>;
To uninstall the whole tool and repository, execute SQLTDROP.SQL and remove SQLT* scripts from
dedicated OS directory that contains them. If script SQLTGRANT.SQL was ever used, execute also
SQLTREVOKE.SQL after SQLTDROP.SQL and before removing all SQLT* scripts.
Using SQLTXPLAIN.SQL
For brief instructions and feedback, please refer to the INSTRUCTIONS.TXT file included on same
SQLT.zip downloaded file.
Start by uncompressing latest file SQLT.zip into one dedicated directory from where you can connect
into SQL*Plus.
The file sql.txt, whose filename is provided as an inline parameter when SQLTXPLAIN.SQL is
executed, has some restrictions and characteristics explained below. If you were not provided with
one sql.txt file, create it and place under same dedicated directory where you placed all SQLT scripts.
SQLTXPLAIN.SQL will try to open file <sql.txt> under same directory where you placed all SQLT
scripts.
Restrictions and characteristics for file sql.txt:
1. It is a plain text file (flat file) with one and only one valid SQL Statement to be explained
(SELECT, INSERT, UPDATE or DELETE),
2. It cannot have empty lines (blank lines),
3. At the very end of the file, after the very last character of the SQL Statement, one and only
one 'carriage return' ('enter' or 'line feed') should be provided, with no spaces before or after it
(review file sql0.txt provided as an example),
4. The SQL Statement should NOT have a semicolon ';' at the end,
5. If you get an error similar to 'Bind variable "b2" not declared', you have empty lines within the
SQL Statement, or at the end (review sql0.txt provided as a correct example),
6. Do NOT replace bind variables with literals. Since the SQLTXPLAIN.SQL script does not
execute the SQL Statement provided on the <sql.txt> file, there is no need to replace the bind
variables on it. Actually, by replacing the bind variables with literals, the resulting Explain Plan
can change substantially and may lead to confusion or false conclusions,
7. The filename <sql.txt> is NOT hard-coded. Therefore, if multiple SQL Statements are being
diagnosed, use filenames sql1.txt, sql2.txt, sql3.txt, etc.; or any other set of names,
8. File sql.txt is usually created out of the TKPROF by extracting a specific expensive SQL
Statement. File sql.txt is normally created with a simple Cut&Paste OS command into one
new flat file,
9. File sql0.txt is provided as an example only (use it to test SQLTXPLAIN.SQL on APPS
databases)
To execute the SQLTXPLAIN.SQL script, login into SQL*Plus. If using Oracle APPS, login with APPS
USER and password. If using on a non-APPS database, connect into SQL*Plus with same USER that
CAN execute the SQL Statement provided within the <sql.txt> file. Be aware that the USER executing
the SQLTXPLAIN.SQL script must have access to the objects specified in the sql.txt file, PLUS to the
'ALL_', 'DBA_' and 'V$' views (see also SQLTGRANT.SQL).
# sqlplus apps/<apps_pwd>
SQL> START SQLTXPLAIN.SQL sql.txt;
# exp apps/<apps_pwd>
file=SQLT tables='SQLT$STATTAB'
If you have problems executing the script SQLTXPLAIN.SQL, read this note in detail and review/test
example file provided sql0.txt (for Oracle APPS databases).
If you notice in the output report that CBO Stats are outdated, or just want to refresh them to test if the
Explain Plan changes, use provided script SQLTGSTATS.SQL. This script requires one parameter,
which is the STATEMENT_ID identifying your unique execution of the SQLTXPLAIN.SQL. It then
executes either FND_STATS or DBMS_STATS (APPS or non-APPS) and gathers all CBO Stats
related to Tables and Indexes shown in the SQLTXPLAIN.SQL output report. If after gathering Stats
the Explain Plan changes, try testing the performance of the new plan.
# imp apps/<apps_pwd>
file=SQLT tables='SQLT$STATTAB' ignore=y
Using SQLTSTATTAB.SQL
This script requires only one parameter, which is the STATEMENT_ID for which the corresponding
CBO Stats are being restored from Table SQLT$STATTAB into the Data Dictionary. Since
STATEMENT_ID is always unique across instances, Table SQLT$STATTAB supports CBO Stats for
same <sql.txt> file from different instances (for example Test and Production).
Execute this SQLTSTATTAB.SQL on the destination instance passing as inline parameter the full or
partial name of the STATEMENT_ID from the source instance. Table SQLT$STATTAB should be
exported from the source instance and imported into the destination instance, prior to execution of
SQLTSTATTAB.SQL.
To execute the SQLTSTATTAB.SQL script, login into SQL*Plus. If using Oracle APPS, login with
APPS USER and password. If using on a non-APPS database, connect into SQL*Plus with same
USER that will execute the SQLTXPLAIN.SQL script in the destination instance. Be aware that the
USER executing the SQLTXPLAIN.SQL and SQLTSTATTAB.SQL scripts must have access to the
objects specified in the sql.txt file, PLUS ANALYZE ANY privilege (see also SQLTGRANT.SQL).
# sqlplus apps/<apps_pwd>
SQL> START SQLTSTATTAB.SQL <statement_id>;
If SQLTSTATTAB.SQL finds CBO Stats for columns that exist in the source instance but not on the
destination one, it just skips the CBO Stats for these columns and reports them as 'MISSING
COLUMNS'.
Source and Destination instances should be very similar (like Test and Production, or two APPS
instances on same release).
Supplied Scripts
Scripts for installation and maintenance
SQLTCREATE.SQL: installs and re-installs the entire SQLT environment (calls
SQLTDROP.SQL, SQLTCTAB.SQL, SQLTCPKGS.PLS and SQLTCPKGB.PLS).
SQLTDROP.SQL: uninstalls the entire SQLT environment by dropping SQLT Package, Views,
Tables and Sequence.
SQLTCTAB.SQL: creates all SQLT$ schema objects except Package SQLT$XPLAIN
(creates Sequence, Tables and Views). It also seeds required and recommended INIT.ORA
parameters for APPS 11i. If a different Tablespace is required other than default for USER,
modify this script (only one line) prior to execution.
SQLTCPKGS.PLS: creates Package Specs for SQLT$XPLAIN.
SQLTCPKGB.PLS: creates Package Body for SQLT$XPLAIN.
SQLTGRANT.SQL: grants SELECT ON some data dictionary views, and ANALYZE ANY, to
user of SQLTXPLAIN.SQL.
SQLTREVOKE.SQL: revokes grants created by SQLTGRANT.SQL to user of
SQLTXPLAIN.SQL.
SQLTRUNC.SQL: truncates all staging Tables on the SQLT environment, with the exception
of the seeded required and recommended INIT.ORA parameters for APPS 11i.
SQLTPURGE.SQL: purges old data out of the staging Tables on the SQLT environment,
leaving only 'X' number of days (where 'X' is an input execution parameter).
Related Documents
All SQLT scripts mentioned in this note may be obtained within compressed file SQLT.zip from the
following external FTP directory. Get always latest version. Current version of SQLT scripts is 12-
NOV-02.
ftp://oracle-ftp.oracle.com/apps/patchsets/AOL/SCRIPTS/PERFORMANCE/
If interested in learning more in Troubleshooting Oracle Apps Performance Issues, read
Note:169935.1
This . . . .