Recompiling and Redistributing an Existing Function
The COMPILE option is intended to be 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 its source code is
present, then 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
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 (see “When to Specify Unprotected Mode” on page 15) as part of a follow‑up ALTER FUNCTION request.
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 (see “CREATE FUNCTION (External Form)/ REPLACE FUNCTION (External Form)” on page 240) and then thoroughly debugged. Some time 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 both recompiled and to retain its ability to run in unprotected mode (because 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.
.so file is built for all C or C++ UDFs in each application category per database per
.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
To regenerate a corrupted
.so file, you only need to compile one function in that database. The system regenerates
.so file, and includes all other user‑defined functions defined in that database in the
Note that 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).