CPI4325 - Temporary result file built for query

CPI4325
Message Text: Temporary result file built for query.
Cause Text: A temporary result file was created to contain the results of the query for reason code &4. This process took &5 minutes and &6 seconds. The temporary file created contains &7 records. The reason codes and their meanings follow:
  1. The query contains grouping fields (GROUP BY) from more than one file, or contains grouping fields from a secondary file of a join query that cannot be reordered.
  2. The query contains ordering fields (ORDER BY) from more than one file, or contains ordering fields from a secondary file of a join query that cannot be reordered.
  3. The grouping and ordering fields are not compatible.
  4. DISTINCT was specified for the query.
  5. Set operator (UNION, EXCEPT, or INTERSECT) was specified for the query.
  6. The query had to be implemented using a sort. Key length of more than 2000 bytes or more than 120 key fields specified for ordering.
  7. The query optimizer chose to use a sort rather than an access path to order the results of the query.
  8. Perform specified record selection to minimize I/O wait time.
  9. The query optimizer chose to use a hashing algorithm rather than an access path to perform the grouping for the query.
  10. The query contains a join condition that requires a temporary file.
  11. The query optimizer creates a run-time temporary file in order to implement certain correlated group by queries.
  12. The query contains grouping fields (GROUP BY, MIN/MAX, COUNT, and so on) and there is a read trigger on one or more of the underlying physical files in the query.
  13. The query involves a static cursor or the SQL FETCH FIRST clause.
Recovery Text: For more information about why a temporary result was used, refer to the Data access on DB2 UDB for iSeries: data access paths and methods.

A temporary result table was created to contain the intermediate results of the query. The results are stored in an internal temporary table (structure). This allows for more flexibility by the optimizer in how to process and store the results. The message help contains the reason why a temporary result table is required.

In some cases, creating a temporary result table provides the fastest way to run a query. Other queries that have many rows to be copied into the temporary result table can take a significant amount of time. However, if the query is taking more time and resources than can be allowed, consider changing the query so that a temporary result table is not required.