Any user who runs a query can use the SET EXPLAIN statement or the EXPLAIN directive to display the query plan that the optimizer chooses. For information on how to specify the directives, see EXPLAIN Directives. The user enters the SET EXPLAIN ON statement or the SET EXPLAIN ON AVOID_EXECUTE statement before the SQL statement for the query, as the following example shows.
SET EXPLAIN ON AVOID_EXECUTE; SELECT * FROM customer, orders WHERE customer.customer_num = orders.customer_num AND customer.lname = "Higgins";
If a user does not have any access to SQL code source, the Database Administrator can set dynamically the SET EXPLAIN using the onmode -Y command running the SQL code. See information on SET EXPLAIN in the IBM Informix: Dynamic Server Administrator's Reference.
After the database server executes the SET EXPLAIN ON statement or sets dynamically the SET EXPLAIN with onmode -Y command, it writes an explanation of each query plan to a file for subsequent queries that the user enters. For a description of the output, see EXPLAIN Output Description.
On UNIX, the database server writes the output of the SET EXPLAIN ON statement or the EXPLAIN directive to the sqexplain.out file.
If the client application and the database server are on the same computer, the sqexplain.out file is stored in the 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, the database server writes the output of the SET EXPLAIN ON statement or the EXPLAIN directive to the file %INFORMIXDIR%\sqexpln\username.out.
When you use the onmode -Y command to turn on SET EXPLAIN, the output is displayed in the sqexplain.out.sessionid file. If an sqexplain.out file already exists, the database server stops to use it until the administrator turns off the dynamic SET EXPLAIN for the session.
The sqexplain.out file tells you if external directives are in effect.
The SET EXPLAIN output contains the following information:
These units represent a relative time for query execution, with each unit assumed to be roughly equivalent to a typical disk access. The optimizer chose this query plan because the estimated cost for its execution was the lowest among all the evaluated plans.