DBAs use the COMPILE option to recompile functions that were 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 to recompile), the system uses the function object to recreate the .so file and distribute it to all system nodes.
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 (ALTER FUNCTION External Form).
- You first submit the following ALTER FUNCTION request to recompile the WriteMQ UDF:
ALTER FUNCTION WriteMQ COMPILE;
- 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 you load a UDF onto another platform of a different type, it is marked invalid, and you must recompile it. If there are many invalid UDFs in a database, save time by specifying the ONLY option for all but the last compilation in that database, to avoid generating and distributing a new library.
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.