SET_INIT in statcollect()

When the iterator-status constant is SET_INIT, the database server has invoked the initial call to statcollect(). Usually, in this initial call, your statcollect() function allocates and initializes an internal C structure, called a statistics-collection structure. The statistics-collection structure is a holding area for the statistics data that statcollect() gathers on a row-by-row basis.

Take the following actions:

  • Define your a statistics-collection structure to hold statistics data.
  • Allocate and initialize this statistics-collection structure within the SET_INIT case of your statcollect() function.

Your statcollect() function can use the MI_FPARAM structure to store this statistics-collection structure (and any other state information) between iterations of statcollect(). Allocate any memory used across multiple iterations of statcollect() from the PER_COMMAND pool and free it as soon as possible. Allocate any memory not used across multiple invocations of statcollect() from the PER_ROUTINE memory pool.

Use the mi_fp_setfuncstate() function to save a pointer to the user-state memory in the MI_FPARAM structure of your statcollect() function. For more information, see Saving a user state.