Best practices for UDXs with SPUPads

When your UDX uses a SPUPad, consider these important programming practices:
  • If a UDX modifies the contents of a SPUPad, the UDX should use the isUserQuery() function to guard against Just In Time (JIT) statistics effects if the SPUPad contents can be used across queries or across rows. The JIT statistics process runs sample tests of user queries to identify the best plan for the query. For queries which modify SPUPad contents, the JIT statistics sampling can cause unintended modifications of the SPUPad contents. Thus, make sure that SPUPad operations occur only when isUserQuery() returns true.

    If the contents are used only by other UDFs or UDAs within the same row of the current query (such as for caching a complicated calculation or returning multiple columns), the UDX does not need to call isUserQuery() to guard the SPUPad.

  • If a UDF or UDA uses a SPUPad, but it does not modify the contents, you do not need to guard against JIT statistics effects.
  • Any UDF that uses a SPUPad and that guards against JIT statistics must not be used in a WHERE clause of a query. The JIT statistics evaluation of the query would ignore the UDF and the query plan might not reflect the actual cost or size of the query.
  • In all SPUPad cases, the UDXs must be robust enough to error gracefully when the SPUPad is not populated.
  • If you have two or more UDXs that can be used in the same query, and one or more or them uses SPUPad, use caution to avoid symbol name overlaps with the struct and class objects that are placed in the SPUPad. Symbol name collisions can cause SPU resets.