Académique Documents
Professionnel Documents
Culture Documents
for Oracle
User Guide
7.5.3
Other trademarks and registered trademarks used in this guide are property of their respective
owners.
Table of Contents
Introduction to Quest SQL Optimizer
Database Privileges
Use Quest SQL Optimizer
10
12
12
13
15
16
18
19
20
21
22
25
27
28
31
31
34
35
36
39
42
43
44
45
45
45
45
Index
46
1
Introduction to Quest SQL Optimizer
About Quest SQL Optimizer for Oracle
Quest SQL Optimizer for Oracle maximizes SQL performance by automating the manual, timeintensive, and uncertain process of ensuring that SQL statements are performing as fast as
possible. SQL Optimizer automatically analyzes, rewrites, and evaluates SQL statements within
multiple database objects, files, or collections of SQL statements from the SGA. The process of
optimizing problematic SQL from multiple source code locations is completely automated.
Whether you are a developer, DBA, or performance tuner, you can just let Quest SQL Optimizer
for Oracle analyze and optimize in batch all problem SQL from multiple sources and then SQL
Optimizer will provide you with the replacement code which includes the optimized SQL
statements.
SQL Optimizer also provides you a complete index optimization and plan change analysis
solution, from index recommendations for multiple SQL statements to simulated index impact
analysis, through comparison of multiple SQL execution plans.
SQL Optimizer consists of the following:
Batch Optimize
The Batch Optimize enables you to submit files, database objects, text, or a Performance
Analysis SQL repository for batch processing. It first scans the code to extract the SQL
statements, then optimizes the SQL statements and tests the SQL alternatives to find the best
performing SQL for your database environment. It provides the replacement code with the
optimized SQL statements.
Scan SQL
The Scan SQL identifies SQL statements from source code and database objects without
requiring the execution of the SQL statements. Once the SQL statements are identified, the Scan
SQL analyzes and categorizes them according to suspected levels of performance problems.
Inspect SGA
The Inspect SGA offers an easy way to view and analyze previously executed and currently
running SQL statements from Oracles system global area (SGA). You can specify your own
criteria to retrieve the SQL statements and their corresponding statistics to review SQL
performance.
The scanning process, by analyzing the operations in the execution plan, identifies potential
performance bottlenecks such as performing full table scans on large tables or multiple table
scans. These thresholds are user-defined under the SQL Classification definitions. The analysis
identifies the problematic SQL that should be optimization.
The Batch Optimize module automatically optimizes the problematic and complex SQL to find
alternative SQL statements that have unique execution plans. The optimization process explores
all possible ways to rewrite the original SQL statement. First, the syntax of the SQL statement is
analyzed along with the tables and indexes and it is rewritten to provide all the SQL alternatives
that produce the exact same result. It applies the optimization hints that are specific to Oracle,
such as ALL_ROWS, HASH, and ORDERED. The use of these Oracle hints is optional.
Once the optimization process has generated all the semantically equivalent SQL alternatives,
the Batch Optimize module determines which one is the most efficient for your database
environment by executing the original SQL statement and the SQL alternatives. It generates a
script that you can use to replace the original SQL statement with the better performing
alternatives.
Note: You can also use the Scan SQL module to extract and identify problematic SQL. Then
you can use the Optimize SQL and Batch Run functions to generate the SQL alternatives and
to test them.
2. Improve SQL coding skills and optimization knowledge
In an Optimization Session, use the Compare function after the original SQL statement is
optimized to view side-by-side the alternative SQL statements in order to learn what alternate
SQL syntax accomplishes the same result. Also, view the execution plans side-by-side to
improve your knowledge of how Oracle executes a SQL statement based on the SQL syntax. Use
the context sensitive help for each keyword in the execution plan to further your understanding
of execution plan steps.
3. Replace poor performing SQL
Once you have found the best SQL for your application, copy the SQL alternative to the
source code.
Note: The Batch Optimize module will create a replacement script for you.
4. Generate index alternatives
If optimizing a SQL statement does not improve the performance enough to meet your
performance requirements, index alternatives can be generated for a single SQL statement with
the Index Generation in an Optimization Session or for a group of SQL statements with the
Advise Indexes module to further enhance the database performance.
5. Predict and track changes to performance
You can predict the performance changes to your database before you migrate to another
database, make configuration changes, or add new indexes using the Analyze Impact module.
10
You can also track the changes that take place in the performances of SQL statements as the
result of changes like updating database statistics, changes in data volume, or program upgrades.
6. Improve Vendor Applications
You can use Oracle stored outlines to improve the performance of SQL statements when you
cannot replace the original SQL statement in your source. In the Optimize SQL module, you can
deploy an outline after you have optimized a SQL statement and then use the Manage Outlines
module to organize your stored outlines.
Database Privileges
Oracle database privileges limit the access of individual users. The following lists the
functionality that requires specific Oracle database privileges. If you do not have one of these
privileges, you can still use the functionality in the other features of the program.
Module
Functionality
Privilege
Optimize SQL
and Batch
Optimize
Execution
Method option:
Optimize SQL,
Advise Indexes,
and Batch
Optimize
Retrieve Run
Time Statistics
Optimize SQL,
Advise Indexes,
and Batch
Optimize
Retrieve time
related statistics
Optimize SQL
Index Generation
and Advise
Indexes
Generate
Virtual Indexes
Optimize SQL
Altering session
parameters for
executing SQL
All Modules
Run on Server
setting
Module
Functionality
11
Privilege
DICTIONARY privilege or the SELECT_
CATALOG_ROLE role is needed to access the
objects under SYS.
Inspect SGA
SQL to Collect:
Executed SQL
from SQL Area
SQL to Collect:
Currently
executing SQL
Manage Outlines
and Deploy
Outlines
Flush Oracle
shared pool
Execution Plan
Information
Creating and
managing
stored outlines
2
Use Quest SQL Optimizer
About Optimizing SQL and Generating Indexes
The Optimize SQL module contains the SQL optimization and index generation for a single SQL
statement along with the testing of the alternative SQL statements created by the optimization
process and the index candidates generated by the index generation process.
SQL Optimization
The SQL Optimization process automates the optimizing of SQL statements. It first analyzes the
original SQL statement and then exhaustively rewrites the syntax of the SQL statement and
applies the Oracle optimization hints. It produces a list of semantically equivalent and
syntactically correct SQL statements that produce the same result set as the original SQL
statement.
Find Best SQL Alternative
The execution of the SQL statements enables you to test run the original and optimized SQL
statements to select which SQL statement gives the best performance. The execution times and
run time statistics help you identify which SQL statement is most suitable for the needs of your
database application environment.
Index Generation
The Index Generation process enables you to determine the best possible indexes for your SQL
statements. It analyzes the syntax of a SQL statement and the relation between tables to
generate index alternatives. It provides all the alternative index sets that generate a unique
execution plan for the SQL statement. It creates these index sets without physical creation of
indexes in your database.
Find Best Index Alternative
The performance of a SQL statement with and without the index candidates can be tested to help
you determine which indexes should be permanently created in your database. This process does
create the indexes in your database.
13
The SQL Optimizer in the Optimize SQL module automates the optimization of SQL statements.
It employs a unique engine that uses Artificial Intelligence to generate all the possible SQL
alternatives that can be mathematically proven to be "semantically equivalent" to the original
SQL statement which guarantees that the SQL alternatives will produce the exact same results as
the original SQL statement. After the alternatives are generated, you can compare each SQL
statement to any other SQL statements to see the different SQL coding techniques for achieving
the same results. You can then test these alternative SQL statements in your environment to find
the best one for your database environment.
SQL Syntax Transformation
The first step of this engine transforms the original SQL statement and produces a group of
alternative SQL statements where the syntax was rewritten. Then, the SQL Optimizer rewrites
each newly created SQL statement to produce another group of alternatives. The engine
continues rewriting each alternative until all the SQL statements cannot be rewritten any further
or until the user-defined quota for the number of SQL statements generated by syntax
transformation is reached.
14
In the Optimization settings, you can also control whether the optimization process will merge
the SELECT statement from a VIEW used in the original SQL so that it is rewriting the original
SQL and the SELECT statements from all the views accessed by the SQL statement. You can
also specify to include a transformation rule that will transform the query to an inline view, that
is take a subquery and use it as a table in a FROM clause. You can also select to use the JOIN
clause (INNER JOIN, CROSS JOIN) from the Ansi-92 SQL standard or to use the original SQL
syntax for joining tables.
Applying Oracle Hints
After the SQL Optimizer has exhausted rewriting the syntax of the SQL statement, the Oracle
optimization hints which are selected in the Optimizer options are applied to the original SQL
statement and each of the SQL alternatives until all selected hints have been applied to all the
SQL alternatives or until the user-defined quota is reached.
Eliminating Duplicate Execution Plan
For each rewritten SQL statement, the execution plan is compared to all the other execution
plans.One SQL alternative is selected for each unique execution plan.Although the
optimization process may generate hundreds of SQL alternatives, you will see only some of the
alternatives since the alternatives with a duplicate execution plan are eliminated.
Testing for Best Alternative
Although all the SQL alternative statements produce the same result, Oracle will likely use a
different path to retrieve the data for each one. It is difficult to decide which SQL statement will
run faster without taking into account the database structure, indexes, and data volume, so it is
important to test the SQL alternatives in your database environment using the Batch Run
function to determine the best SQL alternative from the run time statistics.
15
16
Compare Scenarios
5. To compare the original SQL statement and the execution plan to the alternative SQL
statements, click the Compare tab.
Test Alternative SQL statements
The Batch Run function provides an efficient way of testing SQL. It runs the selected
SQL statements in the database and the SQL statements that exceed the termination time
are canceled. For SQL statements such as INSERT, DELETE and UPDATE, each
statement is run in a transaction that is ROLLBACK, therefore maintaining the
consistency of your data.
6. Click the SQLDetails tab.
7.
To prepare to execute the source and the alternative SQL statements, click
8. Select the Optimize SQL | Batch Run branch and review the settings.
9. Click
10. Once you have identified the alternative SQL statement you want to use, you can copy
and paste it back in your application.
17
Outline.
4. In the Outline name box, enter a name for the stored outline.
5. In the Category box, select a category name or enter a new name to create a new
category. The default category name is SQL_OPTIMIZER.
Note: At this point, it is a good idea to put this outline in a category that is disabled
until you have finished testing the execution of the SQL statement with and without the
use of the outline. You can move the stored outline to another category using the
Manage Outlines.
6. Click Deploy.
Moving the Outline to another Category
If you are satisfied with the performance improvement for the SQL statement with the
stored outline, then move the stored outline to a category that is enabled.
7. Click the Manage Outlines tab to open the Manage Outlines window.
8. In the Category/Outline pane, select the stored outline.
9. Click
10. Enter either a new category name or the name of an existing category.
Enabling an Outline Category
Outlines are stored in a category. A category is either set as enabled or disabled. If the
category is enabled, all outlines in the category will be used when corresponding SQL
statement is executing. If a category is disabled, then when the SQL statement is
executed, Oracle retrieves the execution in the normal manner at the time of execution.
11. Click the category name in the Category/Outline tree.
12. Click
Note: The category named DEFAULT is always enabled, so that outlines stored in the
DEFAULT category are always used when the corresponding SQL statement is executed.
18
The Index Generation in the Optimize SQL module enables you to determine the best possible
indexes for a SQL statement. The Index Generation generates multiple index sets for a single
SQL statement.
Index Set Generation
The process generates index sets by analyzing the syntax of a SQL statement and the tables it
references. It generates the individual index candidates and then groups these indexes into index
sets of one or more indexes.
In the Index Type options you can select to generate B-Tree and Bitmap indexes. You can
specify to parallelize the indexes and to what degree. For B-Tree indexes, you can specify keycompressed.
When generating the indexes, it determines the selectivity of the data from the sample data size
that you specific in the Index Options. You can also determine the maximum number of columns
that will be used in a composite index, the maximum number of indexes in an index set, along
with setting quotas for how many individual indexes and index sets are generated.
Note: Index Generation requires Oracle 8i or above. It also requires the use of the Oracle costbased optimizer. If your are using the rule-based optimizer, cost-based optimization will be
enforced by using the ALL_ROWS or FIRST_ROWS hint. This is required in order to create
virtual indexes in Oracle. If the SQL statement has the rule hint /*+ RULE */, you must remove
it before generating the Index sets.
19
20
5. The Select a Group window appears. Select the Analyze Impact Group which contains
the SQL Repository that you want to analyze.
6. The Analyze Impact window is opened and you are prompted with the Impact Analysis Add Snapshot wizard.
7. The Impact Analysis - Add Snapshot wizard consists of the following:
21
General Page
8. Select the Analyzer which contains the SQL statements you want to analyze in the
Analyzer tree.
Box
Description
Name
Type
Description
Last generated
Add to
Analyzer
Select an
Analyzer to
analyze its
SQL statements
Data distribution
System architecture
1.
Click
22
2. Select Optimize SQL | Best Practices | General. Check Include Best Practices module in
Optimize SQL. Click OK.
3. Click the Optimize SQL tab.
4. Click the Best Practices tab.
5. Enter a SQL statement into the SQL Text window.
6. In the Connection box, click
and select a previously created database connection or
click
to create a new Connection Profile. Select a Schema. Click OK.
7. Click
The Batch Optimize module combines the scanning of source code, the optimization of SQL
statement, and testing of the SQL alternatives with the original SQL into one simple process. So,
it automates the whole process of identifying problematic SQL in your database application,
rewriting the SQL statements, and executing the original SQL statement along with the
alternative SQL statements to find the fastest alternative. Then it creates a script from your
23
original source code in which the slower SQL statements are replaced with better performing
SQL alternatives.
Add Jobs to a Batch
To start the process, you must a add a job to a batch. A job consists of text which is expected to
contain one or more SQL statements. A job may be a block of text, a database object, an ASCII
file, a binary file, a Scan SQL job, a Inspect SGA job, or a Performance Analysis SQL repository.
You can use the Add Batch Optimize Jobs wizard to put the jobs into a batch. You can also
submit a job to the Batch Optimize from other Quest products, such as Toad, SQL Navigator,
Performance Analysis, or Spotlight. You can submit a SQL statement from the SQL Text window
of the Inspect SGA or the Scan SQL. modules.
Scanning
The first step of the Batch Optimize process is to scan through the text in each job to find the
INSERT, UPDATE, DELETE, and SELECT SQL statements. This scanning process works
exactly the same as the scanning process in the Scan SQL.
Optimization
The second step of the Batch Optimize process is to optimize the SQL statements that were
found during the scanning process. This optimization is the same process that is used in the
SQL Optimizer.
Execution
The third step of the Batch Optimize process is to execute the original SQL statement and the
alternative statements to see if any of the SQL alternatives outperform the original SQL
statement.
If a SQL statement has a bind variable, it is not executed until you enter the value for
the variable.
You may select to execute the SQL statements in a different schema or using a different database
connection from the one used for the scanning and optimizing processes.
Generate Optimized Script
After the SQL alternatives are executed, if one of the alternatives is faster than the original SQL
statement then a replacement script can be generated. This script is a copy of the original text
that was scanned with the poor performing SQL statements replaced with the best SQL
alternatives. You can then take this script and replace the code in the database object or
application source code file.
24
Options Settings
The Batch Optimize process can be fully automated by using the settings in the Batch Optimize
options. Or, can manually control the process.
Scanning Options
Jobs will be automatically scanned as soon as they are placed in a batch if you select the
Automatically start extracting SQL when job is added setting.
The jobs are scanned using the settings in the Scan SQLsettings.
Optimizing Options
When the scanning process is finished, the optimization process can automatically be started
based on the SQL classification that you select in the SQL to automatically optimize setting.
For example, if you select Problematic, only those SQL statements that are classified as
Problematic will automatically be optimized. If you do not select any of the SQL classifications,
then you must manually select each SQL statement you would like optimized.
The SQL statements are optimized using the Optimizer settings.
Executing Options
When the optimization process is finished, the execution of the original SQL statement and the
selected alternatives are automatically started if you select one type of SQL statement under the
Types of SQL statement to execution automatically after optimization option.
The SQL alternative that are executed are determined by these settings.
The Types of SQL statement to execution automatically after optimization enables you
to select whether the INSERT, UPDATE, DELETE, or SELECT statements are
automatically executed.
SQL alternatives to executeThe Number of SQL alternatives to select as the
representatives and Execute these additional SQL alternatives settings determine which SQL
alternatives are to executed.
When executing the SQL statements in the Batch Optimize module, the default execution
method is Run on server. By that, it is meant that all SQL statements are executed on the server
and do not return the data from the SELECT statements to the client. Executing the SQL
statements with this method provides you with the run time on the CPU for the SQL statement.
Using this method, your logon account must have the SYS.DBMS_SQL package privilege to
retrieve the run time from the server.
Selecting Best Alternative Options
The best alternative is selected based on the Total elapsed time or the First row elapsed time in
the Best SQL Alternative Selection Criteria setting. The Elapsed time is how long it takes to
25
retrieve all the records returned by a SELECT statement. The First row time is how long it takes
to retrieve only the first record.
c. Click Open to insert the files in the Add Scanner Jobs wizard.
d. Set the schema in the Scan using Schema list to correspond with the SQL that you
are scanning.
26
d. Set the schema in the Scan using Schema list to correspond with the SQL that you
are scanning. The scanning process will use this schema and not the database
connection that is associated with the Scanner group you select in step a.
Inspect SGA page
a. In the Group box, select the Inspector group which contains the SQL statement
you want to scan to identify the problematic SQL.
b. From the Available Inspectors box, select an Inspector job.
c.
d. Set the schema in the Scan using Schema list to correspond with the SQL that you
are scanning. The scanning process will use this schema and not the database
connection that is associated with the Inspector group you select in step a.
Performance Analysis page
a. Click Check for PA Repository.
b. Check Add the PA Repository as a job checkbox.
c. Enter the selection criteria for the SQL statement you would like to extract.
Batch Info page
a. Select Create a new batch.
b. In the Batch Name box, enter a name.
3. After you have made all your selections in the Add Batch Optimize Jobs wizard,
click Finish.
27
4. The Batch Optimize will automatically start scanning the jobs that you created.
Note: The scanning automatically starts when the Automatically start extracting SQL
when job is added option is checked on the Batch Optimize | Options page. The option
is checked by default.
5. The SQL statements that are classified as Problematic or Complex will automatically start
optimizing after the scanning process is finished.
Note: Which SQL statements are optimized is determined by the SQL classifications
selected in the SQL to automatically optimize option on the Batch Optimize | Options
page. By default, the Problematic and Complex SQL are optimized.
6. After the SQL statements are optimized, the original SQL statement and some of the
alternatives SQL statements are executed.
Note: The specific SQL statements that are executed is determined by the option selected
under the Number of SQL alternatives to select as the representatives and the Execute
these additional SQL alternatives settings on the Batch Optimize | Execution | SQL to
Execute Options page.
7. You can review the details of the an optimized SQL statement in an Optimization Session
by clicking the row for the SQL statement in the SQL List window and clicking
8. If a faster SQL alternative is found for a SQL statement, you can generate a replacement
script for the source code by click the job in the Job List window and clicking
Review the script before using it to replace your original source code.
28
Database applications typically contain thousands of SQL statements that may need to be
optimized for better performance. Without the Scan SQL, you have to find and extract each
SQL statement manually a very tedious and time-consuming task. Once you have found the
SQL statements, you need to analyze the execution plan of each SQL statement to see if the
execution plan represents a potential performance problem. The Scan SQL relieves you of this
tedious task.
The Scan SQL extracts SQL statements embedded in database objects, captured from the SGA,
stored in application source code and binary files, or saved in a Performance Analysis SQL
repository. It retrieves and analyzes the execution plans for the extracted SQL statements. It then
categorizes the SQL statements according to the complexity of the execution plan and
determines whether it has the characteristics that typically cause performance problems. The Scan
SQL allows you to quickly review SQL statements in existing code and detect potential
problems. With this approach, you can be proactive in the detection of performance problems
and identify the SQL statements that need to be optimized without executing the applications.
Once the problematic SQL statements have been identified, you can determine the best
solution by
l
Sending a SQL statement to the Optimize SQL module for index generation.
Saving a group of SQL statements to the SQL Repository for further analysis.
Each item that is scanned is referred to as a "job" which can be a database object, text file, binary
file, Inspect SGA file, or Performance Analysis SQL repository.
The Scanning options allow you to include SQL statements that are found in a comment or that
use only the SYS.DUAL table. If your code has tags at the beginning of each line, you can have
the scanning process skip them. You can specify a continuation character if your code uses one
at the end of each line of a SQL statement that is displayed on several lines. And you can
specify that it searches for the whole word when it looks for the INSERT, UPDATE, DELETE,
and SELECT statements, so that it does not try to build a SQL statement when it finds text like
UPDATERECORD.
29
Session or the Batch Optimize module to provide alternative SQL statements that may improve
the performance and/or examine the extracted SQL statements with their execution plans.
Best Practices: An effective use of the Scan SQL module is to review existing code to
proactively identify the SQL statements that can potentially cause performance problems without
the need of executing the applications. In this way, you can prevent performance degradation.
Another effective use of the Scan SQL module is to locate the SQL that is causing performance
problems in your applications. For example, if you know that you have a slow running report,
you can scan the program text or binary file to extract the SQL statements that it contains
without having to execute it. The Scan SQL identifies SQL statements that are likely to create
performance problems. You can then use the an Optimization Session or the Batch Optimize
module to provide alternative SQL statements that may improve the performance.
1. Click the SQL Scan tab.
2. In the Group
list, click
and select a group or click
3. Click
to open the Add Scanner Jobs wizard so you can select which files, database
objects, or Inspect SGA files you want to scan.
4. In the Add Scanner Jobs wizard, click Next until you are at the page for the item that you
want to scan.
Database Objects page
a. Expand the database user branch in the Database Objects box.
b. Highlight the schema, a database object type, or an individual database object,
and click
to move the item to the Select Objects box. (Whether or not you
can scan all of the selected database objects depends on your database privileges.)
Source Code page
a. Click the Text or binary files, Oracle SQL*Plus scripts, or COBOL
programming source code option.
b.
Click
c. Click Open to insert the files in the Add Scanner Jobs wizard.
d. Set the Scan using Schema in the Schema list to correspond with the SQL that
you are scanning.
Inspect SGA page
30
a. In the Group box, select the Inspector group which contains the SQL statement
you want to scan to identify the problematic SQL.
b. From the Available Inspectors box, select an Inspector job.
c.
Click
d. Set the Scan using Schema in the Schema list to correspond with the SQL that
you are scanning. The scanning process will use this schema and not the database
connection that is associated with the Inspector group you select in step a.
Performance Analysis page
a. Click Check for PA Repository.
b. Check Add the PA Repository as a job checkbox.
c. Enter the selection criteria for the SQL statement you would like to extract.
5. After you have made all your selections in the Add Scanner Jobs wizard, click Finish.
6. Click
7. Details are filled in the Job Grid as the scanning process completes each job. It shows
you how many SQL statements classified Problematic, Complex, or Simple.
8. To view the scanned SQL statements, highlight the job by clicking the row and then
click the individual SQL statement in the SQL List window to see the text SQL statement
in the SQL Text window, the execution plan in the Execution Plan window.
9. To view the classification, clicking the SQL Classification tab displaying the execution
plan to change the displayed window to the SQL Classification window.
10. Select one SQL statement you think can be improved. In the SQL Text window, click the
arrow to the right of
and select Optimize in Optimize
SQL to copy the SQL statement to the Optimize SQL module where you can optimize it
with the SQL Optimizer or generate index candidates with the Index Generation. Or,
click Optimize in Batch Optimize to send the SQL statement to the Batch Optimize
where the optimizing and testing process is automated.
11. To generate one index set that will maximize the performance of the SQL statements in
one or more jobs, select the arrow to the right of
31
The Inspect SGA module offers an easy way to capture, view, and analyze executed and
currently running SQL statements from Oracles system global area (SGA). You can specify your
own criteria to determine which SQL statements and statistics to retrieve from the SGA. Since
the information in the SGA is not static, all the SQL statements and information retrieved are
stored on your client computer for you to review now or a later time.
You can schedule the date and time of when the SQL statements and statistics are collected.
Then you can identify the impact of the SQL activities on database performance.
The SQL Scanner module can also be used to review the SQL statements after they are collected
from the SGA to classify the SQL statements based on the characteristics of the execution. Once
you have identified poor performing SQL statements, you can use the Batch Optimize or the
SQL Optimizer to rewrite the syntax of the SQL statement to find a better execution plan.
32
are displayed to help you identify the resource intensive SQL statements. After you have
identified these SQL statements, you can then move a specific SQL statement to an Optimization
Session so you can generate SQL alternatives or index candidates. Or, you can use the Scan SQL
module to enable you to identify potentially problematic SQL statements. You can also use the
Add Jobs function in the Batch Optimize module to automatically optimize all the collected
SQL statements.
Retrieve previously executed SQL statements from Oracle SQL Area
Note: To retrieve previously executed SQL statements, you must have the privilege to view
SYS.V_$SQLAREA, and either SYS.V_$SQLTEXT_WITH_NEWLINES or SYS.V_$SQLTEXT.
1. Click the Inspect SGA tab.
2. In the Group
list, click
and select a group or click
3. Click
4. On the General Information page, select Executed SQL from SQL Area for the Job Type.
5. Enter a Job name.
6. On the Collecting Criteria page, select Top n records and set the Number of records to
be displayed to your desired number.
7. In the First by box, select the statistic to use to extract the SQL statements when you are
not displaying all records. So if you are displaying only 100 records, it will extract the
top 100 records based on the statistic you select in this box.
Note: If you have a large SGA, it will take some time to sort the SQL statements before
the extraction is done.
8. On the SQL Filter page, select the type of SQL statements you want to collect.
9. On the Collection Time page, select Start collecting when you click the Inspect button.
10. On the Statistics page, review the selected statistics and remove any that you do not
want collected.
11. Click Finish.
12. Click
SQL Area.
to start retrieving the SQL statements and statistics from the Oracle
33
15. Select one SQL statement that you feel should be optimized. In the SQL Text window,
click Optimize in Batch Optimize and select Optimize in Optimize SQL and then
continue from the Optimize SQL Tutorial.
16. If you would like to optimize all the SQL statements in the collection, use the Batch
Optimize Tutorial and add an Inspector Job to the batch queue.
17. Another way of identifying problematic SQL statements is to scan the Inspector file using
the Scan SQL Tutorial.
Retrieve currently running SQL statements
Note: To retrieve previously executed SQL statements, you must have the privilege to view
SYS.V_$SESSION, SYS.V_$OPEN_CURSOR, and either SYS.V_$SQLTEXT_WITH_
NEWLINES or SYS.V_$SQLTEXT.
1. Click the Inspect SGA tab.
2. In the Group
list,
click
3. Click
4. On the General Information page, select Currently running SQL for the Job Type.
5. Enter a Job name.
6. On the Session page, select to collect the SQL from the Whole server, a specific Session
ID, or a particular Connection identity.
7. On the SQL Filter page, select the type of SQL statements you want to collect.
8. On the Collection Time page, set the amount of time you want to collect the executing
SQL statements.
9. On the Statistics page, review the selected statistics and remove any that you do not
want collected.
10. Click
11. The collecting process will stop according to the duration or end time defined in the Add
Inspector Job wizard. If you want to stop the monitor before the specified time, click
12. Select one SQL statement that you feel should be optimized. In the SQL Text window,
34
click Optimize and select Optimize in Optimize SQL and then continue from the
Optimize SQL Tutorial, Step 3.
13. If you would like to optimize all the SQL statements in the collection, use the Batch
Optimize Tutorial and add an Inspector Job to the batch queue.
14. Another way of identifying a problematic SQL statement is to scan the Inspector file
using the Scan SQL Tutorial.
Advise Indexes analyzes a group of SQL statements and determines the best common index set
for all of the SQL statements in the group. It does the analysis and index generation without
physically creating the indexes on the database. It is necessary to create the indexes if you want
to do a comparison of the run times with and without the indexes.
Note: Advise Indexes is only available for Oracle 8i or above.
Index Set Generation
Advise Indexes generates a set of indexes by analyzing all the SQL statements in a group of
statements and the tables that are referenced by all the statements. While generating the index
set, no indexes are physically created on the database. Instead, each index in the proposed set of
indexes is created as a virtual index and an virtual execution plan is retrieved for each SQL
statement in the group. This virtual execution plan simulates the execution plan that Oracle
would generate if the indexes were physically created.
Testing SQL Performance Improvement with the Index Set
The SQL statements can be executed first without and then with the index set to compare the run
times to see whether there would be any performance gain from creating the proposed index set.
The execution process executes the SQL statement before creating the indexes. Next, it
physically creates the indexes on the database, executes the SQL statements again, and then
35
drops the indexes from the database. You can compare the run times with and without the
indexes and also compare the virtual execution plan to the actual execution plan.
Index Impact Analysis
You can do an Index Impact Analysis to see the impact that creating the indexes would have on
the execution plans of other SQL statements used in your application before you permanently
create the indexes on your database. The Index Impact Analysis evaluates the effect of the
creation of the indexes in the database system without affecting database performance since it
uses virtual indexes instead of creating indexes on the database. It identifies the SQL statements
which have execution plans that are impacted by the creation of the indexes.
Note: The options for executing SQL statements are shared between the Optimize SQL and
Advise Indexes modules. The execution settings for Advise Indexes are found under the
Optimize SQL | Optimizer | Order and Termination and Execution Method options.
Some of the options for generating indexes are shared between the Optimize SQL | Index
Generation and Advise Indexes. These settings are found under the Optimize SQL | Index
Generation | Options and Index Type.
6. Click
to use the expert knowledge to formulate a set of
proposed indexes for the group of SQL statements. This retrieves the execution plan for
the SQL statements, creates all of the indexes as virtual indexes and then retrieves a
virtual execution plan for each SQL statement. When the index generation is finished, the
Advice layout displays. The changes in cost and optimizer paths can be seen in by
comparing the execution plan to the virtual execution plan retrieved while the virtual
index was present on the data.
7. Click
. This executes the all the SQL statement to obtain the run time. Then,
36
it creates the indexes in the tablespace you specify and executes all of the SQL statements
again. After the execution is finished, the indexes are dropped. The Results layout
displays showing execution statistics in the Scenario Explorer window.
Note: This physically creates the indexes on the database, runs the SQL statement, and
then drops the indexes. This may impact the performance of other SQL statements.
8. Before creating new indexes you can do an Index Impact Analysis.
9. Deploy the index advice into a production environment by using
. This
button sends the index scripts and statistic generation commands to the SQL Editor for
editing and final deployment opens another Quest product such as Toad or SQL
Navigator and copies a index script that you can use to create the set of indexes. If you
do not have a Quest product that can execute the script, the script is copied into a dialog
where you can save the it to a file or copy and paste it to another program.
Analyze Impact provides a way to determine the effects on SQL performance before a change is
made to the database or after a change has occurred. You can find out what will happen to the
performance of the SQL statements if you were to add an index or change a database
configuration parameter before you make the change in the database. You can also find the SQL
statements that have been affected as the result of changes that have occurred in the database
environment. The Analyze Impact helps you to ensure reliable database performance by tracking
execution plan and Oracle cost changes for SQL statements.
37
All kinds of changes can affect SQL performance. Before and after these changes take place, you
can predict and track the impact of changes. Analyze Impact helps you find where the SQL
statements that are effect by changes and to fix the problem quickly. The following are some of
the changes that can have significant impact on the performance of your SQL:
l
Hardware upgrades
Database upgrades
Database migration
Database restructure
Database reorganization
Fragmentations
SQL Repository
The Analyze Impact enables you to save the SQL statements whose performance you would like
to track in a SQL Repository. The execution plan is saved along with the SQL text. You can
then use those SQL statement in one or more "Analyzers."
Analyzer
An Analyzer is set up so that you can find the changes in the execution plans for SQL
statements that are critical to the performance of your production application. In an Analyzer,
you create a "Baseline Snapshot" which saves the execution plan for each SQL statement you
have placed in the Analyzer. The execution plans in the Baseline Snapshot are used as the bases
for comparison to execution plans for the same SQL statements under differing database
conditions.
Script
"Scripts" are used so that you can do various "what if" analysis to determine what impact
changing the database configuration would have on the performance of the SQL statements.
Use for Analyzer Changes that have occurred in the database
You can set up an Analyzer so that you can take a snapshot on a periodic bases to obtain the
current execution plan to find out if any of the execution plans have changed over a period of
time. You can also take a snapshot each time a change has taken place in the database such as a
updating of the statistics for tables and indexes. For those statements with changes, you can use
the SQL Optimizer to see if a SQL statement performance would be improved by optimizing it.
38
39
7. In the pane at the bottom of the Add SQL page, click the folder where you want to store
the SQL statement.
8. On the SQL Information page, enter your SQL statement.
9. Click
40
15. In the pane at the bottom of the General page, select the folder where you want to store
the Analyzer.
16. On the SQL page, select the SQL statements you would like to add to the Analyzer from
your predefined SQL statements, or you may add a statement to this Analyzer by clicking
in the right corner of this window.
17. On the Plan Snapshot page, the first time you are on this page, it brings up the Add
Baseline Snapshot wizard. This snapshot of the SQL statements and execution plans is
used as the comparison for all other snapshots in the Analyzer.
After the first execution plan is saved, if you would like to add another SQL snapshot to
this Analyzer, click
18. In the Add Baseline Snapshot or Add Plan Snapshot wizard under the General page, enter
a name for this Snapshot in the Name box.
19. Under the Connection Information page, select the options for retrieving your
execution plan.
l
Current connection
41
Get the execution plan from the current logon that you are using.
l
New connection
Get the execution plan with a different user logon.
20. If you would like to run one or more of the Oracle scripts, under the Script page, select
the script you would like to use. If you select to use scripts, the pre-script will be
executed after connecting to the database and before getting the execution plan. After
retrieving the execution plan, if there is a post-script it will be executed. You can use
scripts to change your database environment. For instance, you can use a pre-script to
change some of the dynamic init.ora parameters such as optimizer_mode, and then use the
post-script to reset the parameter to its original value. (See Script Tab, step 26.)
Note: You can add a new Oracle script by clicking
21. Click Finish to close the Add Baseline or Plan Snapshot wizard.
22. To add more snapshots, repeat from step 17.
23. Click Finish to close the Add Analyzer Wizard. The Analyzer makes the connection to
the database and retrieves the execution plan under the different snapshots.
24. The Plan Generation Summary window displays information regarding the retrieval of the
execution plans. There you can see if the retrieval is successful or if an error occurred.
Click OK to close the window.
25. To review the Plan Analyzer summary, see View the Execution Plan Changes, step 34.
Script Tab Creating Scripts for Analyzing Configuration Changes
26. Click the Script tab at the bottom left corner of the window.
27. Right-click in the Script pane and select Add Script to open the Add Script wizard.
28. On the General page, enter a name for your Script in the Name box.
29. One the Scripts page, you will see an area for a Pre-Script and a Post-Script.
30. In the Pre-Script area, enter the Oracle commands to be executed before the execution
plan is retrieved.
31. In the Post-Script area, enter the Oracle commands to be executed after the execution plan
is retrieved.
32. In order to check your script in a pre-selected database, click
verify that you your scripts execute.
33. Click Finish to save the scripts.
42
43
3. In the Save SQL to Impact Analyzer wizard, select the folder where you want the SQL
stored or click
You can also save one SQL statement at a time from within in the Analyze Impact module
or from the SQL Text window in the Batch Optimize, Scan SQL, Inspect SGA, or Optimize
SQL modules.
Statistics changes
Database parameter changes particularly those affecting the size of memory structures
When these changes occur, the Oracle optimizer may select a different execution plan which in
turn affects the performance of the SQL statement. By creating a stored outline for a SQL
statement, you can stabilize and preserve performance characteristics of the statement. Therefore,
using outlines can prevent performance degradation of SQL statements due to database
environment changes.
Caution: The SQL text that is saved with the outline needs to be identical to the SQL
statement in the source code or the outline will not be used. Oracle will consider two SQL
44
statements as not identical if there is any difference in spacing, carriage return, embedded
hints, comments, and upper/lowercase.
What is a stored outline category?
A stored outline is saved to a category. A category must be "enabled" before the stored outlines
that are saved in it are used when the SQL statements are executed. When a SQL statement is
executed, Oracle first searches the enabled category and then the DEFAULT category to see if
the SQL statement has a stored outline associated with it. If a stored outline is found, then Oracle
will use the hints in the outline to determine the execution path for the SQL statement instead of
using the execution plan.
Note: By default the Manage Outlines module is not displayed. You can specify to display this
module from the General page of the Outlines options.
The current plan is to remove the Manage Outlines module from SQL Optimizer for Oracle in
the next release.
Click
info@quest.com
Quest Software, Inc.
World Headquarters
5 Polaris Way
Aliso Viejo, CA 92656
USA
Web site
www.quest.com
See our web site for regional and international office information.
Index
D
database privileges
10
deploy outline
add jobs
tutorial
Batch Optimize
Batch Optimize tutorial
25
Scan SQL
6
16
E
execute
28
15
Advise Indexes
About Quest SQL Optimizer
overview
34
tutorial
35
Analyze Impact
About Quest SQL Optimizer
overview
36
tutorial
39
performance assurance
Analyzer
21
H
39
hints
optimization process
B
Batch Optimize
About Quest SQL Optimizer
22
process to find
tutorial
25
Index Generation
Best Practices
About Quest SQL Optimizer
14
overview
tutorial
25
overview
18
tutorial
19
outlines
20
Inspect SGA
43
6
31
performance assurance
privileges
8
10
Inspector
overview
31
tutorial
31
Q
Quest Software
45
R
M
rewrite SQL
Manage Outlines
About
43
6
44
optimization hints
14
28
30
S
Save SQL Statements to the SQL Repository tutorial42
overview
27
28
Scan SQL
About Quest SQL Optimizer
tutorial
optimize SQL
performance assurance
15
6
28
28
28, 31
SQL Optimizer
Optimize SQL
About Quest SQL Optimizer
14
scan
optimization process
process
Index Generation
18
optimization process
14
SQL Optimizer
13
tutorial
15
optimized script
25
Oracle hints
optimization process
T
test alternative SQL
14