Selectivity functions

If you create a user-defined function and mark it as a selectivity function for another function, BladeSmith generates the selectivity function in the udr.c source code file.

The generated code

BladeSmith generates only templates for selectivity functions.

The generated code declares the function, its return type, and arguments. In addition to the arguments you specified when you created the function, BladeSmith also generates an MI_FPARAM argument, which is not used by the generated code.

Complete the code

You must add code to the selectivity function to call the statistics support functions and calculate the selectivity of the associated function for a given set of arguments. For built-in data types, call the built-in statistics functions, such as StatCollect(). For opaque data types, call the statistics support functions in the statistics.c file, such as OpaqueStatCollect().

For example, if you have a selectivity function on an OpaqueEqual() function that is overloaded for an opaque data type, the code for the selectivity function, OpaqueEqualSelectivity(), might perform the following tasks:
  • Determine if either of the arguments has a null value. If so, the selectivity of the OpaqueEqual() function is 0.
  • Determine if either of the arguments is greater than the maximum or minimum value of your opaque data type. If so, the selectivity of the OpaqueEqual() function is 0.
  • Determine where in the distribution one of the arguments falls. Because you know how many values are in each bin, from the location in the distribution you can estimate how many values are less than the argument. The selectivity of the OpaqueEqual() function is then the number of values less than the argument divided by the total number of values.

For more information about coding selectivity functions, see the Informix® DataBlade® API Programmer's Guide.

Example

The Box DataBlade module has selectivity functions.