DB2 Version 9.7 for Linux, UNIX, and Windows

Dynamically explaining an SQL or an XQuery statement

Use the Explain Query Statement window to dynamically explain an SQL or XQuery statement and to produce an access plan graph. If explain tables do not exist, they will be created.

Before you begin

To dynamically explain query statements, you will need at least the INSERT privilege on the explain tables.

About this task

An explained statement record is added to the Explained Statements History for all successful operations.

Procedure

To dynamically explain an SQL or XQuery statement:

  1. Open the Explain Query Statement window: From the Control Center, expand the object tree until you find the Databases folder, expand the Databases folder until you find the database that you want, and then do one of the following:
    • Right-click the database, and click Explain Query from the pop-up menu. Highlight a database, and click Selected > Explain Query. The Explain Query Statement window opens.
    • Open the Viewing explainable statements for a package, the Viewing the history of previously explained query statements, or the Viewing a graphical representation of an access plan window. Select Statement > Explain Query. The Explain Query Statement window opens.
      Note:
      • If you select Explain Query from the Control Center, the Query text field will be empty.
      • If you selected Explain Query from the Explainable Statements or Explained Statements History windows and selected an entry in that window, the Query text field will be populated with the SQL or XQuery statement related to that entry. If you did not select an entry, the Query text field will be empty.
      • If you selected Explain Query from the Access Plan Graph window, the Query text field will contain text for the SQL or XQuery statement whose access plan was shown in the graph.
  2. In the Query text field, you can:
    • Type an SQL or XQuery statement that you want explained.
    • Change the text of an SQL or XQuery statement that already appears in the text field.
    • Get an SQL or XQuery statement from a specified file.
    • Save the SQL or XQuery statement to a specified file.
  3. Optional: In the Query number or Query tag fields, type new values.
  4. Optional: In the Query optimization class field, type new values.
  5. Optional: Select the Populate all columns in Explain tables check box to populate all of the columns of the explain tables from the dynamic explain; otherwise, only the few columns needed by Visual Explain will be populated from the dynamic explain.