Specifying the query performance goal

You can optimize user response time for your entire database server system, within a session, or for individual queries.

The default behavior is for the optimizer to choose query plans that optimize the total query time. You can specify optimization of user-response time at several different levels:
  • For the database server system
    To optimize user-response time, set the OPT_GOAL configuration parameter to 0, as in the following example:
    OPT_GOAL 0

    Set OPT_GOAL to -1 to optimize total query time.

  • For the user environment

    The OPT_GOAL environment variable can be set before the user application starts.

    UNIX™ Only

    To optimize user-response time, set the OPT_GOAL environment variable to 0, as in the following sample commands:

    Bourne shell                OPT_GOAL = 0
                   export OPT_GOAL
    
    C shell               setenv OPT_GOAL 0 

    For total-query-time optimization, set the OPT_GOAL environment variable to -1.

  • Within the session

    You can control the optimization goal with the SET OPTIMIZATION statement in SQL. The optimization goal set with this statement stays in effect until the session ends or until another SET OPTIMIZATION statement changes the goal.

    The following statement causes the optimizer to choose query plans that favor total-query-time optimization:

    SET OPTIMIZATION ALL_ROWS

    The following statement causes the optimizer to choose query plans that favor user-response-time optimization:

    SET OPTIMIZATION FIRST_ROWS
  • For individual queries

    You can use FIRST_ROWS and ALL_ROWS optimizer directives to instruct the optimizer which query goal to use. For more information about these directives, see Optimization-goal directives.

The precedence for these levels is as follows:
  • Optimizer directives
  • SET OPTIMIZATION statement
  • OPT_GOAL environment variable
  • OPT_GOAL configuration parameter

For example, optimizer directives take precedence over the goal that the SET OPTIMIZATION statement specifies.