Interpreting query parallelism

You can examine plan table data to determine whether Db2 chooses access paths that take advantage of parallel processing.

About this task

Begin program-specific programming interface information.

To understand the likelihood that Db2 chooses parallelism, examine your PLAN_TABLE output. This information describes a method for examining PLAN_TABLE columns for parallelism and provides several examples.

End program-specific programming interface information.

Procedure

To interpret EXPLAIN output for parallelism:

  1. Determine the likelihood that Db2 chooses parallelism:
    For each query block (QBLOCKNO) in a query (QUERYNO), a non-null value in ACCESS_DEGREE or JOIN_DEGREE indicates that some degree of parallelism is planned.
  2. Identify the parallel groups in the query:

    All steps (PLANNO) with the same value for ACCESS_PGROUP_ID, JOIN_PGROUP_ID, SORTN_PGROUP_ID, or SORTC_PGROUP_ID indicate that a set of operations are in the same parallel group. Usually, the set of operations involves various types of join methods and sort operations. Parallel group IDs can appear in the same row of PLAN_TABLE output, or in different rows, depending on the operation being performed.

  3. Identify the parallelism mode.
    The PARALLELISM_MODE column indicates that type of parallelism that is planned.

Examples

The following examples illustrate some of the PLAN_TABLE values that represent parallelism.

Single table access
Assume that Db2 decides at bind time to initiate three concurrent requests to retrieve data from table T1. Part of PLAN_TABLE appears as shown in the following table. If Db2 decides not to use parallel operations for a step, ACCESS_DEGREE and ACCESS_PGROUP_ID contain null values.
Table 1. Part of PLAN_TABLE for single table access
TNAME METHOD
ACCESS_
DEGREE
ACCESS_
PGROUP_
ID
JOIN_
DEGREE
JOIN_
PGROUP_
ID
SORTC_
PGROUP_
ID
SORTN_
PGROUP_
ID
T1 0 3 1 (null) (null) (null) (null)
Nested loop join
Consider a query that results in a series of nested loop joins for three tables, T1, T2 and T3. T1 is the outermost table, and T3 is the innermost table. Db2 decides at bind time to initiate three concurrent requests to retrieve data from each of the three tables. Each request accesses part of T1 and all of T2 and T3. For the nested loop join method with sort, all the retrievals are in the same parallel group except for star join with ACCESSTYPE=T (sparse index). Part of PLAN_TABLE appears as shown in the following table:
Table 2. Part of PLAN_TABLE for a nested loop join
TNAME METHOD
ACCESS_
DEGREE
ACCESS_
PGROUP_
ID
JOIN_
DEGREE
JOIN_
PGROUP_
ID
SORTC_
PGROUP_
ID
SORTN_
PGROUP_
ID
T1 0 3 1 (null) (null) (null) (null)
T2 1 3 1 3 1 (null) (null)
T3 1 3 1 3 1 (null) (null)
Merge scan join
Consider a query that causes a merge scan join between two tables, T1 and T2. Db2 decides at bind time to initiate three concurrent requests for T1 and six concurrent requests for T2. The scan and sort of T1 occurs in one parallel group. The scan and sort of T2 occurs in another parallel group. Furthermore, the merging phase can potentially be done in parallel. Here, a third parallel group is used to initiate three concurrent requests on each intermediate sorted table. Part of PLAN_TABLE appears as shown in the following table:
Table 3. Part of PLAN_TABLE for a merge scan join
TNAME METHOD
ACCESS_
DEGREE
ACCESS_
PGROUP_
ID
JOIN_
DEGREE
JOIN_
PGROUP_
ID
SORTC_
PGROUP_
ID
SORTN_
PGROUP_
ID
T1 0 3 d (null) (null) d (null)
T2 2 6 2 3 3 d d
In a multi-table join, Db2 might also execute the sort for a composite that involves more than one table in a parallel task. Db2 uses a cost basis model to determine whether to use parallel sort in all cases. When Db2 decides to use parallel sort, SORTC_PGROUP_ID and SORTN_PGROUP_ID indicate the parallel group identifier. Consider a query that joins three tables, T1, T2, and T3, and uses a merge scan join between T1 and T2, and then between the composite and T3. If Db2 decides, based on the cost model, that all sorts in this query are to be performed in parallel, part of PLAN_TABLE appears as shown in the following table:
Table 4. Part of PLAN_TABLE for a multi-table, merge scan join
TNAME METHOD
ACCESS_
DEGREE
ACCESS_
PGROUP_
ID
JOIN_
DEGREE
JOIN_
PGROUP_
ID
SORTC_
PGROUP_
ID
SORTN_
PGROUP_
ID
T1 0 3 1 (null) (null) (null) (null)
T2 2 6 2 6 3 1 2
T3 2 6 4 6 5 3 4
Hybrid join

Consider a query that results in a hybrid join between two tables, T1 and T2. Furthermore, T1 needs to be sorted; as a result, in PLAN_TABLE the T2 row has SORTC_JOIN=Y. Db2 decides at bind time to initiate three concurrent requests for T1 and six concurrent requests for T2. Parallel operations are used for a join through a clustered index of T2.

Because the T2 RID can be retrieved by initiating concurrent requests on the clustered index, the joining phase is a parallel step. The retrieval of the T2 RID and the T2 rows are in the same parallel group. Part of PLAN_TABLE appears as shown in the following table:
Table 5. Part of PLAN_TABLE for a hybrid join
TNAME METHOD
ACCESS_
DEGREE
ACCESS_
PGROUP_
ID
JOIN_
DEGREE
JOIN_
PGROUP_
ID
SORTC_
PGROUP_
ID
SORTN_
PGROUP_
ID
T1 0 3 1 (null) (null) (null) (null)
T2 4 6 2 6 2 1 (null)