Context Storage of Aggregate User-Defined Functions

The context area is used to transfer or communicate data between multiple invocations of the UDF within the same query (particularly within OLAP-style queries).

Context variables control whether the intermediate results of aggregate functions are to be managed by the UDF itself (forcing the SAP Sybase IQ server to run the UDFs serially), or whether the memory is to be managed by the SAP Sybase IQ server.

If the _calculation_context_size is set to 0, then the UDF is required to manage all interim results in memory, (forcing the SAP Sybase IQ server to invoke the UDF sequentially over the data (instead of being able to invoke many instances of the UDF in parallel during an OLAP query).

If the _calculation_context_size is set to a nonzero value, the SAP Sybase IQ server manages a separate context area for each invocation of the UDF, allowing multiple instances of the UDF to be invoked in parallel. To make the most efficient use of memory, consider setting the _calculation_context_alignment a value smaller than the default (depending on the size of the context storage needed).

For details on context storage, refer to the description of _calculation_context_size and _calculation_context_alignment in the section Aggregate UDF descriptor structure. These variables are near the end of the descriptor structure.

For a detailed discussion about the use of context storage, see Calculation context.

Important: To store intermediate results in memory within an aggregate UDF, initialize the memory with the _start_extfn function, and clean up and de-allocate any memory with the _finish_extfn function.
Related tasks
Declaring an Aggregate UDF
Defining an Aggregate UDF