EXTFNAPIV4_DESCRIBE_COL_IS_USED_BY_CONSUMER (Set)

The EXTFNAPIV4_DESCRIBE_COL_IS_USED_BY_CONSUMER attribute indicates if the column in the result table is used by the consumer. Used in a describe_column_set scenario.

Data Type

a_sql_byte

Description

Used either to determine whether a column in the result table is used by the consumer, or to indicate that a column in an input is not needed. Valid for table arguments. Allows the user to set or retrieve information about a single column, whereas the similar attribute EXTFNAPIV4_DESCRIBE_PARM_TABLE_UNUSED_COLUMNS sets or retrieves information about all columns in a single call.

Usage

The UDF sets EXTFNAPIV4_DESCRIBE_COL_IS_USED_BY_CONSUMER on columns in an input table to inform the producer that it does not need values for the column.

Returns

On success, returns the sizeof(a_sql_byte) or:
  • EXTFNAPIV4_DESCRIBE_NOT_AVAILABLE – if the attribute was not available to set. This can happen if the column was not involved in the query.

On failure, returns one of the generic describe_column errors, or:

Query Processing States

Valid during:
  • Optimization state

Example 1

The PROCEDURE definition and code fragment in the _describe_extfn API function:

CREATE PROCEDURE my_tpf( col_char char(10), col_table TABLE( c1 INT, c2
INT ) )
      RESULTS ( r1 INT, r2 INT, r3 INT )
      EXTERNAL ‘my_tpf_proc@mylibrary’;

CREATE TABLE T( x INT, y INT, z INT );

select r2,r3 from my_tpf( 'test', TABLE( select x,y from T ) )

When this TPF runs, it is beneficial for the server to know if column y is used by this TPF. If the TPF does not need y, the server can use this knowledge for optimization and does not send this column information to the TPF.

my_tpf_describe(a_v4_extfn_proc_context *cntxt)
{
    if( cntxt->current_state == EXTFNAPIV4_STATE_OPTIMIZATION ) {
      a_sql_byte  col_is_used = 0;
      a_sql_int32 ret = 0;

      ret = cntxt->describe_column_get( cntxt, 2, 2,
            EXTFNAPIV4_DESCRIBE_COL_IS_USED_BY_CONSUMER,
            &col_is_used,
            sizeof(a_sql_byte) );

      if( ret < 0 ) {
          // Handle the error.
      }

    }
}