EXPLAIN

The EXPLAIN statement obtains information about access path selection for a SELECT statement. The information obtained is placed in a user table named DB2ePLANTABLE.

The EXPLAIN statement is supported on the following platforms:

Invocation

This statement can be used in an application program using the DB2 CLI functions or issued through the CLP.

Syntax

>>-EXPLAIN--SET QUERYNO=integer--FOR--SELECT-statement---------><
 
 

Description

SET QUERYNO = integer
Associates integer with the SELECT statement. The column QUERYNO is given the value integer in every row inserted into the plan table by the EXPLAIN statement.
SELECT-statement
Specifies a set of new rows in the form of the result table of a select statement.

Rules

The integer value must be positive.

Notes

Example

When developing a new application, it is desirable to determine what access path is chosen for a SELECT statement. In this example, a new application queries the SALES and EMPLOYEES tables. The EXPLAIN statement shows whether the appropriate indexes are chosen for the SELECT statement.

 EXPLAIN SET QUERYNO = 100 FOR
  SELECT E.EMPNAME, S.SALES_AMOUNT
      FROM SALES S, EMPLOYEES E
            WHERE S.EMPNO = E.EMPNO
                   AND S.MONTH = ?
 
Index XSALES on SALES(MONTH)
Index XEMP on EMPLOYEES(EMPNO)
 
SELECT QUERY_NO, PLAN_NO, TABLE_NAME, INDEX_NAME,  SORT_TEMP 
   FROM "DB2ePLANTABLE"
 
QUERY_NO  PLAN_NO  TABLE_NAME  INDEX_NAME  SORT_TEMP
-------------------------------------------------------------------------------------------
   100     1        SALES        XSALES        -
   100     2        EMPLOYEE     XEMP          -
 

Related reference