Explain data can be captured by request when an SQL or XQuery statement is compiled.
If incremental bind SQL or XQuery statements are compiled at run time, data is placed in the explain tables at run time, not at bind time. For these statements, the inserted explain table qualifier and authorization ID are that of the package owner, not of the user running the package.
Explain information is captured only when an SQL or XQuery statement is compiled. After initial compilation, dynamic query statements are recompiled when a change to the environment requires it, or when the explain facility is active. If you issue the same PREPARE statement for the same query statement, the query is compiled and explain data is captured every time that this statement is prepared or executed.
If a package is bound using the REOPT ONCE or REOPT ALWAYS bind option, SQL or XQuery statements containing host variables, parameter markers, global variables, or special registers are compiled, and the access path is created using real values for these variables if they are known, or default estimates if the values are not known at compilation time.
If the REOPT ONCE option is used, an attempt is made to match the specified SQL or XQuery statement with the same statement in the package cache. Values for this already re-optimized and cached query statement will be used to re-optimize the specified query statement. If the user has the required access privileges, the explain tables will contain the newly re-optimized access plan and the values that were used for re-optimization.
In a multi-partition database system, the statement should be explained on the same database partition on which it was originally compiled and re-optimized using REOPT ONCE; otherwise, an error is returned.
Specify either EXPLAIN ALL or EXPLAIN YES options on the BIND or the PREP command, or include a static EXPLAIN statement in the source program.
When an explain snapshot is requested, explain information is stored in the SNAPSHOT column of the EXPLAIN_STATEMENT table.
An explain snapshot is captured when either the EXPLSNAP ALL or the EXPLSNAP YES clause is specified on the BIND or the PREP command, or when the source program includes a static EXPLAIN statement that uses a FOR SNAPSHOT or a WITH SNAPSHOT clause.