The a_v4_extfn_state enumerated type represents the query processing state of a UDF.
typedef enum a_v4_extfn_state {
    EXTFNAPIV4_STATE_INITIAL,                   // Server initial state, not used by UDF
    EXTFNAPIV4_STATE_ANNOTATION,                // Annotating parse tree with UDF reference
    EXTFNAPIV4_STATE_OPTIMIZATION,              // Optimizing
    EXTFNAPIV4_STATE_PLAN_BUILDING,             // Building execution plan
    EXTFNAPIV4_STATE_EXECUTING,                 // Executing UDF and fetching results from UDF
    EXTFNAPIV4_STATE_LAST
} a_v4_extfn_state;
| Member | Description | 
|---|---|
| EXTFNAPIV4_STATE_INITIAL | Server initial state. The only UDF method that is called during this state is _start_extfn. | 
| EXTFNAPIV4_STATE_ANNOTATION | Annotating parse tree with UDF reference. The UDF is not invocated during this state. | 
| EXTFNAPIV4_STATE_OPTIMIZATION | Optimizing. The server calls the UDF’s _start_extfn method, followed by the _describe_extfn function. | 
| EXTFNAPIV4_STATE_PLAN_BUILDING | Building a query execution plan. The server calls the UDF’s _describe_extfn function. | 
| EXTFNAPIV4_STATE_EXECUTING | Executing UDF and fetching results from UDF. The server calls the _describe_extfn function before starting to fetch data from the UDF. The server then calls _evaluate_extfn to start the fetch cycle. During the fetch cycle, the server calls the functions defined in a_v4_extfn_table_func. When fetching finishes, the server calls the UDF’s _close_extfn function. | 
| EXTFNAPIV4_STATE_LAST | First illegal value for v4 API. Out-of-band value. | 
The a_v4_extfn_state enumeration indicates which stage of UDF execution the server is in. When the server makes a transition from one state to the next, the server informs the UDF it is leaving the previous state by calling the UDF’s _leave_state_extfn function. The server informs the UDF it is entering the new state by calling the UDF’s _enter_state_extfn function.
The query processing state of a UDF restricts the operations that the UDF can perform. For example, in the Annotation state, the UDF can retrieve the data types only for constant parameters.