Uses of PER_STMT_EXEC memory duration

The PER_STMT_EXEC memory duration is useful for communications between UDRs, parallel execution, user-defined aggregates, and named memory, and for memory allocations within an end-of-statement callback (if you have information to pass to the callback).

Important: Any memory with a duration higher than PER_COMMAND can have multiple threads access it. Consider whether you need to handle concurrency issues for any PER_STMT_EXEC memory you allocate. For more information, see Handling concurrency issues.
Several constructor functions allocate their data type structure with a PER_STMT_EXEC memory duration. The following table lists data type structures that have a memory duration of PER_STMT_EXEC.
Table 1. data type structures with a PER_STMT_EXEC memory duration
data type structure constructor function destructor function
Connection descriptor (MI_CONNECTION) mi_open() mi_close()
Save-set structure (MI_SAVE_SET) mi_save_set_create() mi_save_set_destroy()
Switching the current memory duration before one of the constructor functions in data type structures with a PER_STMT_EXEC memory duration does not change the PER_STMT_EXEC memory duration of the allocated structure. These data type structures are freed by their destructor function or when execution of the current SQL statement completes. To retain access to some of these data type structures after the statement completes, you must save them at the per-session level.
Tip: The supports the ability to save information at a per-session level. This ability, however, is an advanced feature of the . For more information, see Obtain a session-duration connection descriptor.