Obtain information about column arguments

When the companion UDR receives an argument that is a column, you can obtain the following information about this column from the associated MI_FUNCARG argument of the cost or selectivity function.
MI_FUNCARG information DataBlade® API function
The column number of the column associated with the companion-UDR argument mi_funcarg_get_colno()
The table identifier of the table that contains the column associated with the companion-UDR argument mi_funcarg_get_tabid()
The data-distribution information for the column associated with the companion-UDR argument mi_funcarg_get_distrib()

The column number and table identifier are useful in a selectivity or cost function to obtain additional information about the column argument from the syscolumns or systables system catalog tables. The data distribution is useful if the determination of selectivity or cost depends on how the column values are distributed; that is, how many values in each range of values. Data distributions only make sense for data types that can be ordered.

The mi_funcarg_get_distrib() function obtains the contents of the encdat column of the sysdistrib system catalog table. The encdat column stores the data distribution for the column associated with the companion-UDR argument, as follows:
  • For columns of built-in data types, the data distribution is stored as an ASCII histogram, with a predetermined number of ordered bins that hold the sorted column values.
  • For columns of user-defined data types, this data distribution is in a user-defined statistics structure.

The mi_funcarg_get_distrib() function returns the data distribution in an mi_bitvarying structure as an mi_statret structure. The mi_statret structure can store the data distribution either directly in the structure (in the statdata.buffer field) or in a smart large object (in the statdata.mr field).

For more information about user-defined statistics, see Provide statistics data for a column.