Create the routine sequence
EXECUTE PROCEDURE update_log(log_name)
SELECT name, running_avg(price)
FROM stock_history
WHERE running_avg(price) > 5.00
In the preceding query, the WHERE clause causes the database server to invoke two functions: the running_avg() UDR and, implicitly, the built-in greaterthan() function. The database server calls the running_avg() function for each row that it processes and executes the function in its own separate routine sequence, independent from the routine sequence for running_avg() in the SELECT clause.
- One routine sequence for the primary thread
- Four routine sequences, one for each fragment in the table, for the secondary PDQ threads
Each individual call to a UDR within a routine sequence is called a routine invocation.
- Argument information:
- The number of arguments passed to the UDR
- The data types of each argument
- Return-value information (user-defined functions only):
- The number of return values passed from the UDR
- The data type of each return value
The routine-state space also includes private user-state information for use by later invocations of the routine in the same routine sequence. The UDR can use this information to optimize the subsequent invocations. The user-state information is stored in the routine-state space.
For a C UDR, the routine manager creates an MI_FPARAM structure to hold information about routine arguments and return values. The MI_FPARAM structure that the routine manager creates to hold information about routine arguments and return values can also contain a pointer to user-state information. For more information, see the topics about how to execute UDRs in the Informix® DataBlade® API Programmer's Guide.
For a Java™ UDR, the UDREnv interface provides most of the information that MI_FPARAM provides for a C UDR. This interface has public methods for returning the SQL data types of the return values, for iterator use, and for the user-state pointer. The interface also provides facilities for logging and tracing. For more information, refer to the J/Foundation Developer's Guide.