![]() |
|
Use the SET EXPLAIN statement to display the query plan the optimizer chooses, an estimate of the number of rows returned, and a relative cost of the query.
The SET EXPLAIN statement provides various measurements of the work involved in performing a query.
Option | Purpose |
---|---|
ON | Generates measurements for each subsequent query and writes the results to an output file in the current directory. If the file already exists, new explain output is appended to the existing file. |
OFF | Terminates the SET EXPLAIN statement so that measurements for subsequent queries are no longer generated or written to the output file. |
FILE TO | Generates measurements for each subsequent query and allows you to specify the location for the explain output file. If the file already exists, new explain output overwrites the contents of the file unless you use the WITH APPEND option. |
When you issue a SET EXPLAIN ON statement, the output is directed to the appropriate file until you issue a SET EXPLAIN OFF statement or until the program ends. If you do not enter a SET EXPLAIN statement, the default behavior is OFF. The database server does not generate measurements for queries.
The SET EXPLAIN statement executes during the database server optimization phase, which occurs when you initiate a query. For queries that are associated with a cursor, if the query is prepared and does not have host variables, optimization occurs when you prepare it. Otherwise, optimization occurs when you open the cursor.
When you execute a SET EXPLAIN FILE TO statement, explain output is implicitly turned on. The default filename for the output is sqexplain.out until changed by a SET EXPLAIN FILE TO statement. Once changed, the filename remains set until the end of the session or until changed by another SET EXPLAIN FILE TO statement.
The filename may be any valid combination of optional path and filename. If no path component is specified, the file is placed in your current directory. The permissions for the file are owned by the current user.
The output file that you specify in the SETEXPLAIN statement can be a new file or an existing file.
If you specify an existing file, the current contents of the file are purged when you issue the SET EXPLAIN FILE TO statement. The first execution of a FILE TO command sends output to the beginning of the file.
However, if you include the WITH APPEND option, the current contents of the file are preserved when you issue the SET EXPLAIN FILE TO statement. The execution of a WITH APPEND command appends output to the end of the file.
If you specify a new file in the SET EXPLAIN FILE TO statement, it makes no difference whether you include the WITH APPEND option. The first execution of the command sends output to the beginning of the new file.
On UNIX, when you issue a SET EXPLAIN ON statement, the plan that the optimizer chooses for each subsequent query is written to the sqexplain.out file by default.
If the output file does not exist when you issue the SET EXPLAIN ON statement, the database server creates the output file. If the output file already exists when you issue the SET EXPLAIN ON statement, subsequent output is appended to the file.
If the client application and the database server are on the same computer, the sqexplain.out file is stored in your current directory. If you are using a version 5.x or earlier client application and the sqexplain.out file does not appear in the current directory, check your home directory for the file.When the current database is on another computer, the sqexplain.out file is stored in your home directory on the remote host.
On Windows NT, when you issue a SET EXPLAIN ON statement, the plan that the optimizer chooses for each subsequent query is written to the file %INFORMIXDIR%\sqexpln\username.out where username is the user login.
By examining the SET EXPLAIN output file, you can determine if steps can be taken to improve the performance of the query.
The following table contains terms that can appear in the output file and their significance.
Related statements: SET OPTIMIZATION and UPDATE STATISTICS
For discussions of SET EXPLAIN and of analyzing the output of the optimizer, see your Performance Guide.