Collect the statistics
The statcollect() user-defined function is an iterator function; that is, the database server calls statcollect() for each of the rows on whose column of a user-defined data type UPDATE STATISTICS is collecting statistics. As with other iterator functions, the database server uses an iterator-status constant to indicate when the statistics-collection function is called.
When is the statcollect() function called? | What does statcollect() need to do? | Iterator-status constant in MI_FPARAM |
---|---|---|
The first time that statcollect() is called | Perform any initialization operations, such as
allocating memory for a statistics-collection structure and initializing
values First argument (udt_arg) is a NULL value. |
SET_INIT |
Once for each row for which statistics are being collected | Return one item of the active set Read the column value from the first argument (udt_arg) and place it in your statistics-collection structure. |
SET_RETONE |
After all rows have been processed | Release iteration resources Put the statistics in the stat data type and perform any memory deallocation |
SET_END |
switch ( mi_fp_request(fparam_ptr) )
{
case SET_INIT:
...
case SET_RETONE:
...
case SET_END:
...
}
If statcollect() raises an error, UPDATE STATISTICS terminates the statistics collection for that column.
The following sections summarize the steps that statcollect() must take for each of these iterator-status constants. For general information about iterator-status constants, see Table 1.