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.

BladeSmith generates the OpaqueStatCollect() function (in which Opaque is the name of your opaque data type), which allocates a statistics-collection structure Opaque_stat_t (declared in a file with the .h extension). This structure contains the following information.
Element of statistics-collection structure Description Data type
count Current® number of rows mi_integer
max Maximum value mi_integer
min Minimum value mi_integer
distribution[] An array to hold the “in-progress” statistics data An array of mi_integer values whose size is the number of elements that can fit into the text distribution area (usually 256 bytes)

BladeSmith generates statistics code under the assumption that the minimum, maximum, and distribution of values are appropriate for your opaque data type. The SET_INIT case in the OpaqueStatCollect() function calls the Opaque_SetMaxValue() and Opaque_SetMaxValue() functions (which you must implement) to initialize maximum and minimum values, respectively. It initializes the current row count and the elements of the distribution array to zero.

If this statistics data is not appropriate for your opaque type, 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.


Copyright© 2019 HCL Technologies Limited