The statcollect() and statprint() functions support the collection of statistics. If you want UPDATE STATISTICS to generate statistics for a UDT, you must create these functions.
The statcollect() and statprint() functions use an SQL data type called stat.
The corresponding C language structure is called mi_statretval. For an exact description of mi_statretval, see the libmi header file.
Most of the information in mi_statretval is manipulated internally. However, two fields must be filled in by statcollect():
When you run UPDATE STATISTICS, the database server calls the appropriate statcollect() function for each column that the database server scans.
The statcollect() function takes four arguments:
The database server uses this argument to resolve the function and to pass in values.
The first time the database server invokes this function, it sets this parameter to null. On subsequent invocations, this argument contains the column value.
On the first call to statcollect(), MI_FPARAM contains a SET_INIT value. Check for this value in statcollect() and perform any initialization operations, such as allocating memory and initializing values.
On subsequent calls to statcollect(), MI_FPARAM contains a SET_RETONE value. At this point, statcollect() should read the column value from the first argument and place it in your distribution structure.
After all rows have been processed, the last call to statcollect() puts a value of SET_END in MI_FPARAM. For this final call, statcollect() should put the statistics in the stat data type and perform any memory deallocation.
You must declare the statcollect() function with HANDLESNULLS, but the function itself can ignore nulls if desired.
Allocate any memory used across multiple invocations of statcollect() from the PER_COMMAND pool and free it as soon as possible. Any memory not used across multiple invocations of statcollect() should be allocated from the PER_ROUTINE pool.
The statprint() function converts the statistics data that the statcollect() function collects to an LVARCHAR value that the database server can use to display information. The dbschema utility executes the statprint() function.
The statprint() function has two arguments. The first argument is a dummy argument of the required data type. The database server uses this argument to resolve the function. The first time the database server executes this function, it sets the first parameter to null.
The second argument is a value of the stat data type. The stat data type is a multirepresentational data type that the database server uses to store data that the statcollect() function collects.
The statprint() function must take the histogram, which is stored in multi-representational form, and convert it to a printable form.
After you register the functions, make sure those with DBA privilege or the table owner can execute the statcollect() and statprint() UDRs.
For examples of statprint() and statcollect() functions written in C, refer to the \%INFORMIXDIR\dbdk\examples\Types\dapi\Statistics\Box\src\c directory, after you install the DataBlade Developer's Kit.
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]