Control how the system runs the Open Query File (OPNQRYF) command

The optimization function allows you to specify how you are going to use the results of the query.

When you use the Open Query File (OPNQRYF) command, there are two steps where performance considerations exist. The first step is during the actual processing of the OPNQRYF command itself. This step decides if the OPNQRYF command is going to use an existing access path or build a new one for this query request. The second step when performance considerations play a role is when the application program is using the results of the OPNQRYF command to process the data.

For most batch type functions, you are usually only interested in the total time of both steps mentioned in the preceding paragraph. Therefore, the default for the OPNQRYF command is OPTIMIZE(*ALLIO). This means that the OPNQRYF command considers the total time it takes for both steps.

If you use the OPNQRYF command in an interactive environment, you might not be interested in processing the entire file. You might want the first screen full of records to be displayed as quickly as possible. For this reason, you want the first step to avoid building an access path, if possible. You can specify OPTIMIZE(*FIRSTIO) in such a situation.

If you want to process the same results of the OPNQRYF command with multiple programs, you might want the first step to make an efficient open data path (ODP). That is, you try to minimize the number of records that must be read by the processing program in the second step by specifying OPTIMIZE(*MINWAIT) on the OPNQRYF command.

If the KEYFLD or GRPFLD parameter on the OPNQRYF command requires that an access path be built when there is no access path to share, the access path is built entirely regardless of the OPTIMIZE entry. Optimization mainly affects selection processing.

Related concepts
Database performance and query optimization