DB2 Version 9.7 for Linux, UNIX, and Windows

Choosing an optimization class

Setting the optimization class can provide some of the advantages of explicitly specifying optimization techniques.

This is true, particularly when:

Most statements can be adequately optimized with a reasonable amount of resource by using the default optimization class 5. Query compilation time and resource consumption are primarily influenced by the complexity of a query; in particular, by the number of joins and subqueries. However, compilation time and resource consumption are also affected by the amount of optimization that is performed.

Query optimization classes 1, 2, 3, 5, and 7 are all suitable for general use. Consider class 0 only if you require further reductions in query compilation time, and the SQL and XQuery statements are very simple.

Tip: To analyze a long-running query, run the query with db2batch to determine how much time is spent compiling and executing the query. If compilation time is excessive, reduce the optimization class. If execution time is a problem, consider a higher optimization class.
When you select an optimization class, consider the following general guidelines:
Complex queries might require different amounts of optimization to select the best access plan. Consider using higher optimization classes for queries that have:

Decision support queries or month-end reporting queries against fully normalized databases are good examples of complex queries for which at least the default query optimization class should be used.

Use higher query optimization classes for SQL and XQuery statements that were produced by a query generator. Many query generators create inefficient queries. Poorly written queries require additional optimization to select a good access plan. Using query optimization class 2 or higher can improve such queries.

For SAP applications, always use optimization class 5. This optimization class enables many DB2® features optimized for SAP, such as setting the DB2_REDUCED_OPTIMIZATION registry variable.

In a federated database, the optimization class does not apply to the remote optimizer.