Creating a selectivity function

If you need to calculate the selectivity for a Boolean function at run time, create a selectivity function.

About this task

To create a selectivity function:

Procedure

  1. Write a C user-defined function to implement the selectivity function.
    The selectivity function has the following coding requirements:
    • The selectivity function must take the same number of arguments as its companion Boolean function.
    • Each argument of the selectivity function must be declared of type MI_FUNCARG.
    • The selectivity function must return the selectivity as a floating-point value (mi_real or mi_double_precision) that is between zero and one.
  2. Register the selectivity function with the CREATE FUNCTION statement.
    The SQL selectivity function has the following registration requirements:
    • The selectivity function must take the same number of arguments as its companion Boolean function.
    • Each argument of the selectivity function must be declared of type SELFUNCARG.
    • The selectivity function must return the selectivity as a FLOAT value.
  3. Associate the selectivity function with its companion UDR with the SELFUNC routine modifier when you register the companion UDR.