The INIT function
The INIT aggregate support function performs the initialization for the user-defined aggregate.
Initialization task | More information |
---|---|
Setup for any additional resources outside the state that the aggregation might need | Aggregate support functions that the algorithm requires |
Initial calculations that the user-defined aggregate might need | Aggregate support functions that the algorithm requires |
Allocation and initialization of the aggregate state that the rest of the aggregation computation might need | Aggregate support functions for the aggregate state |
Handling of an optional setup argument | Implement a setup argument |
The INIT support function is an optional aggregate support function. If your aggregate algorithm does not require any of the tasks in Table 1, you do not need to define an INIT function. When you omit the INIT function from your user-defined aggregate, the database server performs the state management for the aggregate state. For more information, see Handling a simple state.
agg_state init_func(dummy_arg, set_up_arg)
agg_arg_type dummy_arg;
set_up_type set_up_arg; /* optional */
- agg_state
- The data type of the aggregate state.
- dummy_arg
- A dummy parameter that has the same data type as the aggregate argument that this aggregate support function is to handle for the user-defined aggregate.
- init_func
- The name of the INIT aggregate support function.
- set_up_arg
- An optional parameter for the setup argument. For more information, see Implement a setup argument.
In the execution of a UDA, the database server calls the INIT function before it begins the actual aggregation computation. It passes in any optional setup argument (set_up_arg) from the user-defined aggregate and copies any initialized aggregate state that INIT returns into the state buffer. For more information about the state buffer, see Aggregate support functions for the aggregate state.
agg_state init_func(NULL, optional setup argument)
/* SQSUM1 INIT support function on INTEGER */
mi_integer init_sqsum1(dummy_arg)
mi_integer dummy_arg;
{
return (0);
}