Register the statcollect() function

As with any user-defined function, you register the statistics-collection function with the CREATE FUNCTION statement.

The registration of this function has the following requirements:
  • You must name this user-defined function statcollect.

    The database server handles routine resolution based on the data type of the first argument to statcollect(). If the name of your C statistics-collection function is not statcollect(), specify the C function name in the EXTERNAL NAME clause.

  • You must declare the statcollect() function with HANDLESNULLS routine modifier.

    Your statistics-collection function can choose whether to include the NULL value in the statistics data that it generates.

  • The data types of the parameters must be as follows.
    Parameter number Parameter data type
    1 SQL name for the user-defined data type
    2 FLOAT
    3 FLOAT
    • Do not include the declaration of the MI_FPARAM structure in the SQL registration.
    • The function must return a value of type stat.
The following CREATE FUNCTION statement registers the statistics-collection function that Sample declaration of a statistics-collection function declares:
CREATE FUNCTION statcollect(ll_arg longlong, num_rows FLOAT,
   resolution FLOAT)
RETURNING stat
WITH (HANDLESNULLS)
EXTERNAL NAME '/usr/udrs/bin/longlong.so(stat_collect_ll)'
LANGUAGE C;

After you register the statcollect() function, make sure those with the DBA privilege or the table owner has the Execute privilege on the function.