Usage Notes - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
qwr1571437338192.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantage™

FNC_free is the equivalent of free for use by UDFs, UDMs, table operator, contract function and external stored procedures.

The sqltypes_td.h header file redefines free to call FNC_free.

WHEN you … THEN …
develop, test, and debug a UDF, UDM, or external stored procedure standalone include the malloc.h header file and use the standard malloc and free C library functions.
install your UDF, UDM, or external stored procedure on the server do not include the malloc.h header file and use the definitions of malloc and free from the sqltypes_td.h header file.

Note that the definitions are used when submitting source code to the server, but not when submitting objects.

FNC_free checks to make sure the UDF, UDM, or external stored procedure releases all memory before exiting and gives an exception on the transaction if the UDF, UDM, or external stored procedure does not release all temporary memory it allocated. This is to prevent memory leaks in the database.

If you circumvent the logic to call malloc and free directly, then there is a good chance that a memory leak could occur even if the UDF, UDM, or external stored procedure frees up memory correctly. The reason is that a UDF, UDM, or external stored procedure can abort while it is running if a user aborts the transaction, or if the transaction aborts because of some constraint violation that might occur on another node unbeknownst to the running UDF, UDM, or external stored procedure.