Getting Started with Tuning SQL Statements in IBM Data Studio and
IBM Data Studio (stand-alone), Version 2.2.1
Note Before using this information and the product it supports,
read the information in “Notices” on page 63.
Contents
Configuring a DB2 for z/OS subsystem for query tuning . . . . . . .
. . . . 11
Setting global preferences . . . . . . 25
Tuning SQL statements . . . . . . . 43
Additional resources. . . . . . . . . 61
iii
iv Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Introduction
This document explains the basics of using IBM® Data Studio and IBM
Data Studio (stand-alone), Version 2.2.1 for tuning SQL
statements.
Note: For simplicity, this guide refers to both IBM Data Studio and
IBM Data Studio (stand-alone) as IBM Data Studio, except in the
section that is specific to installing IBM Data Studio
(stand-alone).
To help you get started with tuning, this document shows you how to
complete these tasks: 1. Install IBM Data Studio (stand-alone). 2.
Configure a DB2® for z/OS® subsystem, so that you can tune SQL
statements
that run on that subsystem. 3. (Optional) Set global preferences
for tuning. 4. Select an SQL statement to tune. 5. Run the
Statistics Advisor and analysis tools, and generate reports. 6.
Capture the runtime environment of an SQL statement.
1
2 Getting Started with Tuning SQL Statements in IBM Data Studio and
IBM Data Studio (stand-alone), Version 2.2.1
Installing IBM Data Studio (stand-alone), Version 2.2.1
This chapter explains how to download the IBM Data Studio
(stand-alone) product and install it. The procedure involves
ensuring that your system meets the requirements, downloading and
extracting the product package, and then running an installation
wizard.
Here are the steps: 1. Ensure that your Linux® or Windows® system
meets the requirements that are
documented here: http://www-01.ibm.com/support/docview.wss?rs=3360
&uid=swg27016061
2. Download IBM Data Studio (stand-alone), Version 2.2.1 from this
location. You will need an IBM ID and password, which you can
create at this location if you do not already an account.
https://www14.software.ibm.com/webapp/
iwm/web/preLogin.do?lang=en_US&source=swg-idssa
3. Extract the product package to a temporary directory on your
computer, such as c:\temp.
4. (Optional) The product installation program requires a JRE at
level 1.6 or higher. To use the JRE that is bundled with the
product, configure the JAVA_HOME and PATH environment variables as
follows, replacing temp with the path and name of the directory
where you extracted the product.
On Windows set JAVA_HOME=C:\temp\datastudio\eclipse\jreset
PATH=C:\temp\ datastudio\eclipse\jre\bin;%PATH%
On Linux export JAVA_HOME=/root/temp/datastudio/eclipse/jre export
PATH=/root/temp/datastudio/eclipse/jre/bin:$PATH
5. From the directory where you extracted the product, run the
executable file.
Figure 1. The extracted product package in a temporary
directory
3
On Windows On Windows, run install.exe.
On Linux On Linux, run ./install.bin.
6. In the wizard, select the language that you want the
installation wizard to use and click OK.
7. On the Introduction page, click Next. The Next button always
appears in the bottom-right corner of the wizard.
Figure 2. The splash screen for the installation wizard, where you
can select a language
4 Getting Started with Tuning SQL Statements in IBM Data Studio and
IBM Data Studio (stand-alone), Version 2.2.1
8. On the Software License Agreement page, read and accept the
license agreement. Then, click Next.
Figure 3. The Introduction page
Installing IBM Data Studio (stand-alone), Version 2.2.1 5
9. On the Choose Install Folder page, select a directory for the
installation. If you do not accept the default directory, ensure
that you do not choose a directory that has a path that is long,
deep, or both. An example of a long path on Microsoft Windows is
c:\
this_is_the_directory_where_I_want_to_install_IBM_Data_Studio_standalone.
An example of a deep path is c:\this\is\an\example\of\a\deep\path.
If the directory that you choose has a path that meets either or
both of these criteria, you might encounter problems when you are
using the product. After selecting the directory, click Next.
Figure 4. The software license agreement
6 Getting Started with Tuning SQL Statements in IBM Data Studio and
IBM Data Studio (stand-alone), Version 2.2.1
10. On the Pre-Installation Summary page, click Install in the
bottom-right corner.
Figure 5. The Choose Install Folder page
Installing IBM Data Studio (stand-alone), Version 2.2.1 7
11. When the installation is finished, click Done in the
bottom-right corner to start IBM Data Studio (stand-alone).
Figure 6. The Pre-Installation Summary page
8 Getting Started with Tuning SQL Statements in IBM Data Studio and
IBM Data Studio (stand-alone), Version 2.2.1
At other times when you want to use the product, in Windows you can
click Start and select Programs > IBM Data Studio Standalone
> IBM Data Studio 2.2.
Figure 7. The final page of the installation wizard
Installing IBM Data Studio (stand-alone), Version 2.2.1 9
10 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Configuring a DB2 for z/OS subsystem for query tuning
Configuring a DB2 for z/OS subsystem for query tuning involves
these tasks. v Binding packages that the Statistics Advisor and
other features require, and
grant privileges on those packages v Creating a set of EXPLAIN
tables, if your subsystem does not have a set of them
already, and grant privileges on them v Creating a set of Query
Tuner tables
You can complete these tasks by following these steps: 1. Define a
database connection profile, connect to a DB2 for z/OS
subsystem,
and set the default SQL ID and schema. 2. Follow either of these
procedures to configure the DB2 for z/OS subsystem for
query tuning: v Configure the subsystem by using the Configure
Subsystem for SQL Tuning
wizard v Configure the subsystem by running JCL
Defining a database connection profile, connecting to a DB2 for
z/OS subsystem, and setting the default SQL ID and schema 1. In the
Data Source Explorer, right-click Database connections and select
New.
2. In the New Connection wizard, complete these steps, using this
image for reference:
Figure 8. Creating a new connection in the Data Source
Explorer
11
a. Under Select a database manager, select DB2 for z/OS. b. To the
right in the Properties box, specify the location of the subsystem,
the
name of the host where the subsystem is located, and the port
number to use when connecting to the host.
c. Deselect the Use default naming convention check box and specify
a new name for the connection, if you do not want to use the
location as the default name.
d. Specify the user name (authorization ID) and password to use for
connections to the subsystem.
e. Click the Test Connection button. f. Click Finish if the test of
the connection was successful. When you click
Finish, the Data Source Explorer shows that a connection to the
subsystem is open. From this point on, whenever you want to open a
connection to the subsystem, right-click the connection profile and
select Connect.
3. Set the default SQL ID and schema to use for configuring the
subsystem by using Data Studio and for tuning SQL statements a. In
the Data Source Explorer, right-click the subsystem and select
Query
Tuner > Change Default SQL ID and Schema.
Figure 9. The New Connection wizard
12 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
b. Edit the values. The SQL ID is always folded to uppercase. You
cannot use quotation marks to preserve mixed case or lowercase. The
case in which you type the schema is preserved, however. If you
type sChEmA, the default schema is sChEmA.
c. Click OK.
Configure the subsystem by using the Configure Subsystem for SQL
Tuning wizard
Before completing these steps, ensure that you have the necessary
authorities and privileges, which are listed here in the Data
Studio information center. 1. Ensure that you have the required
authorities and privileges.
Table 1. Authorities and privileges required to connect to and
configure a DB2 for z/OS subsystem for tuning, when configuring
from IBM Data Studio
Task Authorities or privileges required
Connect to a DB2 for z/OS subsystem All of the following
authorities and privileges: v Underlying DB2 access authority v
EXECUTE privilege on the following
packages:
basic packages (DSN5OADM, DSN5OEPJ (DB2 for z/OS Version 8),
DSN5OEPK (DB2 for z/OS Versions 9 and 10), DSN5ONPT,
DSN5OPKG)
Figure 10. Right-clicking the subsystem in the Data Source Explorer
and opening the Change Default SQL ID and Schema window
Configuring a DB2 for z/OS subsystem for query tuning 13
Task Authorities or privileges required
Bind packages One of the following authorities and privileges: v
SYSADM or DBADM authority v BINDADD privilege if required
packages
do not exist, and CREATEIN privilege on the schema
v ALTERIN privilege on the schema if the required packages
exist
v BIND privilege on the required packages if they exist
Free packages One of the following authorities and privileges: v
Ownership of the packages v BINDAGENT privilege that is granted
by
the owner of the packages v SYSCTRL authority v SYSADM authority v
PACKADM authority for the collection or
for all collections
Browse subsystem parameters All of the following authorities and
privileges:
v EXECUTE privilege on the SYSPROC.DSNWZP stored procedure
v At least MONITOR1 system privilege
Manage users One of the following privileges or authorities: v The
privilege WITH GRANT OPTION on
required packages v Ownership of the packages v SYSADM
authority
14 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Table 2. Authorities and privileges required to enable the EXPLAIN
function on a DB2 for z/OS subsystem, when configuring from IBM
Data Studio
Task Authorities or privileges required
Create EXPLAIN tables If you want to create the EXPLAIN tables in a
new database, one or more of the following privileges or
authorities for creating the database: v CREATEDBA privilege v
CREATEDBC privilege v SYSADM or SYSCTRL authority
For creating the table space, one or more of the following
privileges or authorities: v CREATETS privilege for the database v
DBADM, DBCTRL, or DBMAINT
authority for the database v SYSADM or SYSCTRL authority
For creating the tables, one or more of the following privileges or
authorities: v CREATETAB privilege for the database v DBADM,
DBCTRL, or DBMAINT
authority for the database v SYSADM or SYSCTRL authority
Create aliases for existing EXPLAIN tables One of the following
privileges or authorities: v The CREATEALIAS privilege v SYSADM or
SYSCTRL authority v DBADM or DBCTRL authority on the
database that contains the table, if the alias is for a table and
the value of field DBADM CREATE AUTH on installation panel DSNTIPP
is YES
2. In the Data Source Explorer, right-click the subsystem and
select Query Tuner > Configure for Tuning > Guided
Configuration. The Configure Subsystem for SQL Tuning wizard
opens.
Configuring a DB2 for z/OS subsystem for query tuning 15
The first page lists all of the steps for configuring the
subsystem. You complete these steps on the subsequent pages of the
wizard. Click Next to go to the first step.
3. On the Bind Packages page, specify the package owner for all the
Query Tuner packages, which the Statistics Advisor and other tuning
features require. If other users are going to be tuning SQL
statements that run on this subsystem, select the check box Grant
or revoke authorization on packages. You can grant authorizations
to those other users on a subsequent page of the wizard.
Figure 11. The Introduction page
16 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
When you are finished on this page, click Next. 4. On the Create
EXPLAIN Tables page, specify the SQL ID that is authorized to
create the EXPLAIN tables. You can change the qualifier for the
EXPLAIN tables by clicking the Select button. Specify unique names
for the LOB table spaces to be created and, if necessary, edit the
parameters for allocating the table spaces. The buffer pools and
storage groups must already exist. They are not allocated
automatically. Everyone who tunes SQL statements must be authorized
to select from, insert into, and update the EXPLAIN tables. If you
know of people who need these authorities, select the check box
Grant or revoke authorizations on EXPLAIN tables. If you want to
share the EXPLAIN tables under an alias, select the check box
Create aliases for EXPLAIN tables.
Figure 12. The Bind Packages page
Configuring a DB2 for z/OS subsystem for query tuning 17
When you are finished on this page, click Next. 5. On the Create
Query Tuner Tables page, specify the storage group and buffer
pool in which to create tables that the Statistics Advisor
accesses. Then, click Next.
Figure 13. The Create EXPLAIN Tables page
18 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
6. If you selected the Grant or revoke authorization on packages
check box on the Bind Packages page, the Grant Privileges on Query
Tuner Packages page appears next. Grant privileges to each
authorization ID that will be used for tuning SQL statements. Then,
click Next.
Note: Because you are using IBM Data Studio (stand-alone), ignore
the warning that appears at the bottom of the page.
Figure 14. The Create Query Tuner Tables page
Configuring a DB2 for z/OS subsystem for query tuning 19
7. If you selected the Grant or revoke authorizations on EXPLAIN
tables check box on the Create EXPLAIN Tables page, the Grant
Privileges on EXPLAIN Tables page opens next. Specify the SQL ID
that is authorized to grant these privileges. Specify the qualifier
of the set of EXPLAIN tables that you want to grant privileges on.
Then, grant privileges to each authorization ID that will be used
for tuning SQL statements. When you are finished on this page,
click Next.
Figure 15. The Grant Privileges on Query Tuner Packages page
20 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
8. If you selected the Create aliases for EXPLAIN tables check box
on the Create EXPLAIN Tables page, the Create Aliases for EXPLAIN
Tables page opens. Create an alias for each authorization ID that
will have access to the EXPLAIN tables. You can enter multiple
aliases with a comma separator. When you are finished on this page,
click Next.
Figure 16. The Grant Privileges on EXPLAIN Tables page
Configuring a DB2 for z/OS subsystem for query tuning 21
9. On the Summary page, review the list of tasks that you
specified. You can click Back to return to previous pages in the
wizard and change values. When you are finished reviewing the
tasks, click Finish. The wizard attempts to complete each task in
the list.
Figure 17. The Create Aliases for EXPLAIN Tables page
22 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Configuring the subsystem by running JCL
Perform the following steps on the DB2 for z/OS subsystem to
configure it for tuning SQL statements: 1. Upload the required DBRM
and JCL job files to the subsystem. The files are
installed with Data Studio. You can find these files in the
following location: Installation_directory\
dsrcp\ZOS\z/OS_version_number_and_mode
Figure 18. The Summary page
Configuring a DB2 for z/OS subsystem for query tuning 23
Note: Use binary format when you upload these DBRM files to the
subsystem. 2. Modify the corresponding AOCDDL JCL job file in the
following table to
conform to your environment, and submit the job to install the DBRM
files and create EXPLAIN tables.
Subsystem JCL job file
DB2 Version 10 for z/OS conversion mode from Version 9
AOCDDLX9
DB2 Version 10 for z/OS conversion mode from Version 8
AOCDDLX8
DB2 for z/OS Version 8 new-function mode AOCDDL8N
DB2 for z/OS Version 8 compatibility mode AOCDDL8C
24 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Setting global preferences
Every time that you run the Statistics Advisor and analysis tools,
or generate reports, you can set values for preferences that modify
how these features work. However, you can also set default values
for these preferences ahead of time in the Preferences
window.
Important: If you set default values for these preferences while
one or more instances of workflow assistant are open, you must
close those instances and then reopen them for the default values
to take effect.
To open the Preferences window, in the menubar at the top of IBM
Data Studio click Window. Then, select Preferences.
In the Preferences window, expand Data Management and select Query
Tuner. The parent page for the tuning preferences opens. All of the
preferences on this page are applicable to tuning in IBM Data
Studio, except for the Check user privileges before monitoring or
scheduling snapshots for Monitor Profiles preference.
Figure 19. Opening the Preferences window
25
For help with the preferences about the trace settings and
migrating EXPLAIN
tables, refer to their tooltips. For help with the other
preferences, click the icon in the lower-left corner of the
Preferences window.
Of the pages under the Query Tuner page, only those that are
highlighted in yellow in this image are applicable to IBM Data
Studio.
Figure 20. The Query Tuner page
26 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
On the EXPLAIN Query page of the preferences, you can set options
that are related to collecting EXPLAIN information about the SQL
statements that you want to tune. For help with these preferences,
refer to their tooltips.
Select the Always refresh catalog information from the data server
check box so that the local cache of the catalog is updated before
EXPLAIN information is collected for SQL statements. The Statistics
Advisor, access plan graphs, and access plan reports depend on
current EXPLAIN information. When you start the EXPLAIN process for
an SQL statement that you want to tune, the process uses catalog
information that is locally cached. If the SQL statement references
any tables that change after you explain that statement for the
first time, you should refresh the local cache of the catalog
before you explain the statement again. You can refresh the cache
automatically by selecting this check box. If you do not select it,
you can refresh the cache manually before you run the Statistics
Advisor and tools on the statement. In the Data Source Explorer,
right-click the subsystem and select Query Tuner > Refresh
Catalog for Tuning.
The preference Use the stored procedure to execute EXPLAIN for the
statement cache refers to the DB2 for z/OS dynamic statement cache,
from which you can
Figure 21. Preference pages that are applicable to IBM Data
Studio
Setting global preferences 27
capture SQL statements to tune.
On the Access Plan Report page, you can specify which reports to
generate and their formats.
Figure 22. The EXPLAIN Query page
28 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
On the Statistics Advisor page, choose defaults for the Statistics
Advisor to use when generating RUNSTATS commands to recommend.
Select the Custom option to set a default value for each
preference. For help with the preferences, refer to
tooltips and click the icon in the lower-left corner of the
Preferences window.
Figure 23. The Access Plan Report page
Setting global preferences 29
Figure 24. The general preferences for the Statistics Advisor
30 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Figure 25. The first set of preferences for the Statistics Advisor
for DB2 for z/OS
Setting global preferences 31
Figure 26. The second set of preferences for the Statistics Advisor
for DB2 for z/OS
32 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Selecting an SQL statement to tune
Now that the subsystem is set up to support tuning SQL statements,
you can select an SQL statement to tune.
There are many locations from which you can choose an SQL statement
to tune. You can access most of those locations from within the
workflow assistant, which is the part of the Data Studio interface
where the tuning features are collected together. You will learn
more about choosing an SQL statement while you are in the workflow
assistant shortly.
Selecting an SQL statement from outside of the workflow
assistant
First, here is a list of locations outside of the workflow
assistant in which you can select an SQL statement to tune.
SQL editor and routine editor Place the cursor on an SQL statement,
right-click, and select Start Tuning.
You can also right-click anywhere in one of these editors and
select Start Tuning.
View, SQL stored procedure, user-defined function, or trigger in
the Data Source Explorer
Right-click any of these objects and select Query Tuner > Start
Tuning.
Figure 27. Right-clicking a view in the Data Source Explorer
33
If you select Start Tuning after right-clicking on a view, a SELECT
statement is reverse engineered from the view. The workflow
assistant then opens so that you can tune this statement.
If you select Start Tuning from any of the other locations, this is
how the workflow assistant responds: v If the object contains one
SQL statement, the workflow assistant opens so that
you can tune the statement. v If the object contains more than one
SQL statement, the workflow assistant
allows you to select one of the statements to tune.
Selecting an SQL statement from inside the workflow assistant
Open the workflow assistant from the Data Source Explorer in either
of two ways. v Right-click the database connection and select Start
Tuning.
v Expand the database connection, right-click the subsystem, and
select Query Tuner > Start Tuning.
Figure 28. Right-clicking the database connection and selecting
Start Tuning
34 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
The workflow assistant opens to the Capture SQL from File page of
the Capture section.
Figure 29. Right-clicking the subsystem and selecting Query Tuner
> Start Tuning
Figure 30. The Capture SQL from File page of the Capture section of
the workflow assistant
Selecting an SQL statement to tune 35
The left side of the Capture section lists the different locations
that you can capture SQL statements from.
The goal of capturing SQL statements is to bring SQL statements
into the workflow assistant and then to sort them to find
statements that require tuning. For an example of capturing SQL
statements from one of the sources in DB2 for z/OS, click Statement
Cache. The Capture SQL from Statement Cache page opens.
The dynamic statement cache, as well as any other source in DB2 for
z/OS, can contain a very large number of SQL statements. Therefore,
the first step in capturing is to define a filter in which you
specify criteria that the statements that you want to examine must
match. In the Filter section, click the Create Filter icon.
Figure 31. Locations that you can capture SQL statements from
Figure 32. The Capture SQL from Statement Cache page
36 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
When you create a filter for capturing from the dynamic statement
cache, you name it and specify the maximum number of SQL statements
that you want the filter to capture. For this example, leave the
name as Default_1.
The filter runs against the DSN_STATEMENT_CACHE_TABLE table, so you
must specify the qualifier for that table. For this example, ignore
the two check boxes.
You set the criteria for the filter in the table. SQL statements
that the filter captures must match every criterion that you set a
value for in this table.
In the next page of the wizard, select the columns that you want
the captured statements to be sorted by when the workflow assistant
presents them. They will appear in a table in the Capture SQL from
Statement Cache page.
Figure 33. The Create Filter icon
Figure 34. The Filter Rows page of the wizard for creating a filter
for capturing SQL from the dynamic statement cache
Selecting an SQL statement to tune 37
On the Customize Columns page, select the columns that you want to
display in the table that lists the captures SQL statements.
Figure 35. The Sort Rows page of the wizard for creating a filter
for capturing SQL from the dynamic statement cache
38 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
After you click Finish in the wizard, you return to the Capture SQL
from Statement Cache page. The filter that you created appears as
the selected filter in the Filter name field.
Optional: When you capture SQL statements from the dynamic
statement cache, you can also capture runtime metrics for those
statements. If you capture those metrics, you can sort on them and
more easily identify statements that need tuning than if you
captured the SQL statements alone. Click the Enable Cache Trace
button to ensure that the metrics are included in the statement
cache. Select the Disable cache trace after capturing check box, so
that runtime metrics are not cached unnecessarily after you have
captured statements. Then, wait while the statements are run and
added to the statement cache. When you are sure that the statements
of interest to you are cached, you can capture those
statements.
Figure 36. The Customize Columns page of the wizard for creating a
filter for capturing SQL from the dynamic statement cache
Figure 37. The new filter in the Filter name field
Selecting an SQL statement to tune 39
Click Capture. After a few moments, the SQL statements that match
the filter criteria appear in a new section: Captured
Statements.
If you set any sort columns in the filter wizard, the statements
are sorted accordingly. For example, if you chose to sort by the
STAT_CPU column in descending order, the statements with the
highest CPU cost are at the top of the table. You can also click
column headers to sort by individual columns.
If you know that you want to tune a statement that, for example,
references a particular table, click the Search for SQL Text icon.
In the Find SQL Text window, type the name of the table and click
Find Next until you find the right statement.
Figure 38. The Captured Statements section and table of captured
SQL statements
40 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
After you locate a statement that you want to tune, right-click it
and select Invoke Advisors and Tools. You can also click on the
statement and then click the Invoke Advisors and Tools icon.
When you capture SQL statements from other sources in DB2 for z/OS,
you follow the same steps: 1. Create a filter or use an existing
one. You can also edit an existing filter. 2. Click Capture. 3.
Look in the table in the Captured Statements section for a
statement to tune. 4. Select the statement and click the Invoke
Advisors and Tools icon or right-click
the statement and select the Invoke Advisors and Tools
option.
The workflow assistant opens to the Run Single-Query Advisors and
Analysis Tools page of the Review section. The next chapter
explains what to do there.
Figure 39. The Find SQL Text window
Figure 40. The Invoke Advisors and Tools icon and menu option
Selecting an SQL statement to tune 41
42 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Tuning SQL statements
After you select the Invoke Advisors and Tools option for an SQL
statement, the workflow assistant opens the Run All Single-Query
Advisors and Analysis Tools page in the Review section.
The statement appears in the Query Text field at the bottom of the
page. The name that the workflow assistant assigns to the statement
is in the title of the Query Text field. In the image below, the
name of the statement is Query 3.
From this page, you can run the Statistics Advisor, format the
statement so that you can read it easily, and generate a graph of
the access plan for the statement.
If you want to modify any of the options for the Statistics
Advisor, select Set Advisor Options in the top-left corner of the
workflow assistant. The options that appear are the same options
that appear in the global preferences. If you modify the values for
the options here, you override the values that are set in the
global preferences. The values will be in effect only for the
current instance of the workflow assistant. If you run the
Statistics Advisor and then save the recommendations to a project,
the values are stored in that project.
Figure 41. The SQL statement in the Query Text field
43
After you finish modifying options, select Run All Advisors and
Analysis Tools in the top-left corner of the workflow assistant to
return to the page where the SQL statement is located.
The first time that you run the Statistics Advisor and analysis
tools on a statement, the workflow assistant gathers EXPLAIN
information for the statement, if EXPLAIN information is not
already available for the statement. You can set values to use for
special registers, or you can accept the default values. If EXPLAIN
information already exists for the statement, but you modified the
objects that the statement references or modified the statement in
some way since EXPLAIN information was last collected for it, you
can specify to recollect EXPLAIN information.
To the left of the special registers are the SQL ID that has
authority to run the statement and the default schema for objects
in the statement. If you set the SQL ID and schema in the Change
Default SQL ID and Schema window, the values that you specified
appear in these fields. However, if you did not set the default SQL
ID and schema in that window, these values are used: v If you did
not set a default SQL ID, the authorization ID that you are using
to
connect to the subsystem is used. v If you did not set a default
schema and the objects that are referenced by the
SQL statement are unqualified, the current authorization ID is
used. v If you did not set a default schema and the objects that
are referenced by the
SQL statement are qualified, the schema from the SQL statement is
used.
Figure 42. Setting options locally for the Statistics Advisor
44 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
With a check box below these values, you can also specify whether
to convert them to uppercase or keep them exactly as you typed
them.
When you are ready to run the Statistics Advisor and Analysis
Tools, click the Select What To Run button.
The Select Query-Tuning Activities window appears.
Figure 43. Options for the EXPLAIN command, SQL ID, default schema,
and the Select What To Run button
Tuning SQL statements 45
For this example, keep the current selection and click OK.
After a few moments, the workflow assistant opens the Review
Single-Query Advisor Recommendations page of the Review
section.
Figure 44. The Select Query-Tuning Activities window
46 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
This page shows that the Statistics Advisor has recommendations.
However, before looking at them, select Open Formatted Query in the
top-left corner of the workflow assistant. The Review Formatted
Query page appears. It shows two versions of the SQL statement: the
original statement and the statement as it was revised by the DB2
optimizer. You can save or print the statement.
Figure 45. The Review Single-Query Advisor Recommendations page of
the Review section
Tuning SQL statements 47
In the top-left corner of the workflow assistant, select Open
Access Plan Graph. The Review Access Plan page displays the graph
of the access plan for the statement.
Figure 46. The Review Formatted Query page of the Review
section
48 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
On the left, click Overview of Diagram for tools for navigating to
different areas of a large access plan.
In the diagram, select a node and click Description of Selected
Node on the left to see the attributes of that node.
Return to the Review Single-Query Advisor Recommendations by
selecting Open Single-Query Recommendations in the top-left corner
of the workflow assistant. Then, double-click the row for the
Statistics Advisor. The section Statistics Advisor Details opens to
show the RUNSTATS commands that the advisor recommends. You can run
those commands directly from this section or save them to a file to
run them later.
Figure 47. The Review Access Plan page of the Review section
Tuning SQL statements 49
To see the problems that the advisor found with the statistics,
expand the section Statistics Advisor report, which is just under
the recommended RUNSTATS commands. Expand the section Conflicts
detail to learn more about any conflicting statistics that the
advisor found. Expand the RUNSTATS Result section if you run the
recommended RUNSTATS commands here and want to see whether the
commands ran successfully.
Figure 48. The Statistics Advisor Details section
50 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Finally, you can generate two different types of reports to help
you decide how to tune the SQL statement.
Summary report In the top-left corner of the workflow assistant,
click Open Summary Report. The workflow assistant generates a
report that includes this information: v The RUNSTATS commands that
are recommended by the Statistics
Advisor v Information about the access plan for the SQL statement v
Catalog information about the tables that the statement references
and
the indexes that are on those tables
You can save the report to a file. You can also right-click the
node and select Print to print the report.
Figure 49. The Statistics Advisor report, Conflicts detail, and
RUNSTATS Result sections
Tuning SQL statements 51
Access path reports In the top-left corner of the workflow
assistant, click Open Access Path Reports. The workflow assistant
opens a window for you to select which reports to generate. You can
generate three reports that contain information that the DB2
optimizer uses when generating an access plan for the statement. v
A report that contains information about the tables that the
statement
references v A report about the predicates that are in the
statement v A report about the indexes that are on the tables that
the statement
references
After you run the RUNSTATS commands that the Statistics Advisor
recommends, you can regenerate the access plan graph of the SQL
statement to see how the access plan has changed. If any changes
occur, however, to the objects that the SQL statement references,
you must refresh the local cache of the system catalog. Then,
re-run the Statistics Advisor to find out whether there are any new
recommendations. To refresh the local cache of the system catalog,
in the Data Source Explorer right-click the subsystem and select
Query Tuner > Refresh Catalog for Tuning.
Figure 50. The Open Summary Report option and a sample summary
report
52 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Figure 51. Refreshing the local cache of the system catalog
Tuning SQL statements 53
54 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Capturing the environment of an SQL statement
When you are working with IBM Support to resolve a problem with
tuning an SQL statement, or when you want to recreate the
environment of an SQL statement on a different DB2 for z/OS
subsystem, you can capture the statement's environment in a set of
files. You can then upload the files to IBM Support or to the other
subsystem.
Remember: This feature is available only when you are connected to
a DB2 for z/OS subsystem. It is not available when you are
connected to a DB2 for Linux, UNIX, and Windows database.
There are two areas in the workflow assistant where you can capture
and send the environment of an SQL statement. The first area is in
the upper-left corner of every page in the Capture section. In that
location is the Capture Query Environment icon.
You can select a captured statement and click the icon to import
the statement into the Query Environment window, You can also paste
a statement into the window directly, or import a statement from a
file.
Figure 52. The Capture Query Environment icon
55
If a statement is particularly long and complex, including the
creators and names of the tables that the statement references,
which you can do in the Table information section, can aid IBM
Support in understanding your problem better.
After specifying the SQL statement, click Next to specify options
for the files that you will generate. If you plan to recreate the
query environment on a DB2 for z/OS subsystem that is at a version
different from the version of the currently connected subsystem,
select the version of the target subsystem in the Convert for
different version of DB2 for z/OS field.
If you are working with IBM Support and have a PMR number, type the
number in the PMR or ETR Number field.
If you are recreating the query environment on another subsystem
and are not working with IBM Support, you can just type zeros in
the three entry fields for the PMR number.
Then, click the Generate Report button to create the files that can
be used to recreate the query environment.
Figure 53. The Query Environment window
56 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
The files are listed in the Files to upload field. Ensure that the
FTP settings are correct for the target location of the files.
Then, click the Upload Files button.
Figure 54. The Generate Report button
Capturing the environment of an SQL statement 57
After you receive notification that the file transfer is complete,
click Finish.
The second area in the workflow assistant where you can capture and
send the environment of an SQL statement is in the Review section.
After you run or attempt to run the Statistics advisor or to
generate an access plan graph or reports, the Review section opens.
On the left side of the workflow assistant is the Capture Query
Environment option.
Figure 55. The Upload Files button
58 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Clicking on the option opens the Collect data about the query
environment page of the Review section. This page works almost
identically to the Query Environment window. The first difference
is that the SQL statement is not visible. The second difference is
the layout. There are two subsections: Options and FTP Server
Settings. In the first section, you can add information about
tables referenced in the statement, set options for generating the
files for recreating the environment, enter a PMR number, generate
the report, and upload the files.
In the second section, you can specify the connection information
for the target FTP server. This second section also lists the files
that you generate.
Figure 56. The Capture Query Environment option in the Review
section of the workflow assistant
Figure 57. The Options section in the Collect data about the query
environment page of the Review section
Capturing the environment of an SQL statement 59
Figure 58. The FTP Server Settings section in the Collect data
about the query environment page of the Review section
60 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
Additional resources Information center for IBM Data Studio
http://publib.boulder.ibm.com/infocenter/idmhelp/ds-v2r2/index.jsp
http://www.ibm.com/developerworks/forums/forum.jspa?forumID=1086
Optim™ Query Tuner for DB2 for Linux, UNIX, and Windows
http://www-01.ibm.com/software/data/optim/query-tuner-luw/
Optim Query Tuner for DB2 for z/OS
http://www-01.ibm.com/software/data/optim/query-tuner-z/
Optim Query Workload Tuner for DB2 for z/OS
http://www-01.ibm.com/software/data/optim/query-workload-
tuner-z/
Notices
This information was developed for products and services offered in
the U.S.A.
IBM may not offer the products, services, or features discussed in
this document in other countries. Consult your local IBM
representative for information on the products and services
currently available in your area. Any reference to an IBM product,
program, or service is not intended to state or imply that only
that IBM product, program, or service may be used. Any functionally
equivalent product, program, or service that does not infringe any
IBM intellectual property right may be used instead. However, it is
the user's responsibility to evaluate and verify the operation of
any non-IBM product, program, or service.
IBM may have patents or pending patent applications covering
subject matter described in this document. The furnishing of this
document does not grant you any license to these patents. You can
send license inquiries, in writing, to:
IBM Director of Licensing IBM Corporation North Castle Drive
Armonk, NY 10504-1785 U.S.A.
For license inquiries regarding double-byte (DBCS) information,
contact the IBM Intellectual Property Department in your country or
send inquiries, in writing, to:
Intellectual Property Licensing Legal and Intellectual Property Law
IBM Japan Ltd. 1623-14, Shimotsuruma, Yamato-shi Kanagawa 242-8502
Japan
The following paragraph does not apply to the United Kingdom or any
other country where such provisions are inconsistent with local
law: INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS
PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE. Some states do not allow disclaimer of express or implied
warranties in certain transactions, therefore, this statement may
not apply to you.
This information could include technical inaccuracies or
typographical errors. Changes are periodically made to the
information herein; these changes will be incorporated in new
editions of the publication. IBM may make improvements and/or
changes in the product(s) and/or the program(s) described in this
publication at any time without notice.
Any references in this information to non-IBM Web sites are
provided for convenience only and do not in any manner serve as an
endorsement of those Web sites. The materials at those Web sites
are not part of the materials for this IBM product and use of those
Web sites is at your own risk.
63
IBM may use or distribute any of the information you supply in any
way it believes appropriate without incurring any obligation to
you.
Licensees of this program who wish to have information about it for
the purpose of enabling: (i) the exchange of information between
independently created programs and other programs (including this
one) and (ii) the mutual use of the information which has been
exchanged, should contact:
IBM Corporation _Department number/Building number_ _Site mailing
address_ _City, State; Zip Code_ _U.S.A. (or appropriate
country)
Such information may be available, subject to appropriate terms and
conditions, including in some cases, payment of a fee.
The licensed program described in this document and all licensed
material available for it are provided by IBM under terms of the
IBM Customer Agreement, IBM International Program License Agreement
or any equivalent agreement between us.
Any performance data contained herein was determined in a
controlled environment. Therefore, the results obtained in other
operating environments may vary significantly. Some measurements
may have been made on development-level systems and there is no
guarantee that these measurements will be the same on generally
available systems. Furthermore, some measurements may have been
estimated through extrapolation. Actual results may vary. Users of
this document should verify the applicable data for their specific
environment.
Information concerning non-IBM products was obtained from the
suppliers of those products, their published announcements or other
publicly available sources. IBM has not tested those products and
cannot confirm the accuracy of performance, compatibility or any
other claims related to non-IBM products. Questions on the
capabilities of non-IBM products should be addressed to the
suppliers of those products.
All statements regarding IBM's future direction or intent are
subject to change or withdrawal without notice, and represent goals
and objectives only.
All IBM prices shown are IBM's suggested retail prices, are current
and are subject to change without notice. Dealer prices may
vary.
This information is for planning purposes only. The information
herein is subject to change before the products described become
available.
This information contains examples of data and reports used in
daily business operations. To illustrate them as completely as
possible, the examples include the names of individuals, companies,
brands, and products. All of these names are fictitious and any
similarity to the names and addresses used by an actual business
enterprise is entirely coincidental.
COPYRIGHT LICENSE:
This information contains sample application programs in source
language, which illustrate programming techniques on various
operating platforms. You may copy,
64 Getting Started with Tuning SQL Statements in IBM Data Studio
and IBM Data Studio (stand-alone), Version 2.2.1
modify, and distribute these sample programs in any form without
payment to IBM, for the purposes of developing, using, marketing or
distributing application programs conforming to the application
programming interface for the operating platform for which the
sample programs are written. These examples have not been
thoroughly tested under all conditions. IBM, therefore, cannot
guarantee or imply reliability, serviceability, or function of
these programs. The sample programs are provided "AS IS", without
warranty of any kind. IBM shall not be liable for any damages
arising out of your use of the sample programs.
Each copy or any portion of these sample programs or any derivative
work, must include a copyright notice as follows:
© your company name) (year). Portions of this code are derived from
IBM Corp. Sample Programs.
© Copyright IBM Corp. _enter the year or years_. All rights
reserved.
If you are viewing this information softcopy, the photographs and
color illustrations may not appear.
Trademarks IBM, the IBM logo, and ibm.com are trademarks or
registered trademarks of International Business Machines Corp.,
registered in many jurisdictions worldwide. Other product and
service names might be trademarks of IBM or other companies. A
current list of IBM trademarks is available on the Web at
“Copyright and trademark information” at
www.ibm.com/legal/copytrade.shtml.
Notices 65
Configuring a DB2 for z/OS subsystem for query tuning
Setting global preferences
Tuning SQL statements
Additional resources