Recompiling and Redistributing an Existing Function | ALTER FUNCTION | Vantage - Recompiling and Redistributing an Existing Function - Advanced SQL Engine - Teradata Database

SQL Data Definition Language Detailed Topics

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
imq1591724555718.ditamap
dita:ditavalPath
imq1591724555718.ditaval
dita:id
B035-1184
lifecycle
previous
Product Category
Teradata Vantage™

The COMPILE option is used by DBAs to recompile functions that have been moved to a platform, system, or restored database other than the one in which they were created.

Specify the COMPILE option to recompile an existing function. If the source code is present, the system recompiles it, generates the object, recreates the .so file for functions written in C or C++, and distributes the .so files to all nodes of the system. If the procedure is written in Java, the COMPILE option recompiles the existing function, generates the object, and distributes the associated JAR files to all nodes of the system. The object is replaced with the recompiled version.

If the function was created with the object only (that is, there is no source code present to be recompiled), the function object is used to recreate the .so file and distribute it to all nodes of the system.

If the function is restored from a different platform to a new platform whose objects are not compatible, the COMPILE option fails. When this happens, you must recreate the function with the correct object or source code.

You cannot specify this option if the function was installed as part of a package.

Functions defined to run in unprotected mode and recompiled with this option do not retain the ability to run in unprotected mode unless you specify EXECUTE NOT PROTECTED as part of a follow-up ALTER FUNCTION request. See When to Specify Unprotected Mode.

For example, suppose you have a UDF named WriteMQ, which has been set to run in EXECUTE NOT PROTECTED mode by an ALTER FUNCTION request that was submitted after the function was created using a CREATE FUNCTION request and then thoroughly debugged. See CREATE FUNCTION and REPLACE FUNCTION (External Form). Later, it becomes necessary for WriteMQ to be recompiled for some reason, so you must perform the following multistep procedure if WriteMQ is to be recompiled and to retain its ability to run in unprotected mode. You cannot specify both COMPILE [ONLY] and EXECUTE [NOT] PROTECTED in the same ALTER FUNCTION request.

  1. You first submit the following ALTER FUNCTION request to recompile the WriteMQ UDF:
    ALTER FUNCTION WriteMQ COMPILE;
  2. After the successful completion of this request, the system resets the protection mode for WriteMQ to EXECUTE PROTECTED, so you must run a second ALTER FUNCTION request to set its protection mode back to EXECUTE NOT PROTECTED:
    ALTER FUNCTION WriteMQ EXECUTE NOT PROTECTED;

When you specify COMPILE ONLY, then only the UDF is recompiled and no new dynamic linked library are distributed to database nodes. The COMPILE ONLY option is not available for Java functions.

When a UDF is loaded onto another platform of a different type, it is marked as non-valid. All non-valid UDFs must be recompiled. If there are many UDFs in one database, you can save time by specifying the ONLY option for all but the last compilation in that database to avoid having to generate and distribute a new library. When you do this, make certain not to specify the ONLY option for the last UDF you recompile in that database.

One .so file is built for all C or C++ UDFs in each application category per database per node. The .so files are stored outside the database on the system disk of each node. If a .so file becomes corrupted on one node, you can regenerate it by issuing an ALTER FUNCTION request with the COMPILE option to rebuild the .so file.

To regenerate a corrupted .so file, you only need to compile one function in that database. The system regenerates the .so file, and includes all other user-defined functions defined in that database in the regenerated .so file.

Changing the protection mode for a UDT-related UDF also causes the system-generated UDT constructor function to be recompiled invisibly (invisible in that the system does not return any compilation messages unless the compilation fails for some reason, in which case the system returns an appropriate error message to the requestor).