Creating a cost function

If you need to calculate the cost for a UDR at runtime, create a cost function.

About this task

To create a cost function:

Procedure

  1. Write a C user-defined function to implement the cost function.
    The cost function has the following coding requirements:
    • The cost function must take the same number of arguments as its companion UDR.
    • Each argument of the cost function must be declared of type MI_FUNCARG.

      For more information, see The MI_FUNCARG data type.

    • The cost function must return the cost as an integer value (mi_integer or mi_smallint).
  2. Register the cost function with the CREATE FUNCTION statement.
    The SQL cost function has the following registration requirements:
    • The cost function must take the same number of arguments as its companion UDR.
    • Each argument of the cost function must be declared of type SELFUNCARG.
    • The cost function must return the cost as an INTEGER or SMALLINT value.
  3. Associate the cost function with its companion UDR with the COSTFUNC routine modifier when you register the companion UDR.