150 likes | 297 Views
Native PL/SQL Compilation. Julian Dyke Independent Consultant. Web Version. juliandyke.com . Native PL/SQL Compilation. Oracle 9.0.1 and above includes support for native compilation of PL/SQL into a shared library (DLL) in the file system
E N D
Native PL/SQL Compilation Julian Dyke Independent Consultant Web Version juliandyke.com
Native PL/SQL Compilation • Oracle 9.0.1 and above includes support for native compilation of PL/SQL into a shared library (DLL) in the file system • A C compiler is required to use native compilation of PL/SQL. This can be a GNU C compiler • New parameters include
Native PL/SQL Compilation • PLSQL_COMPILER_FLAGS • Determines whether PL/SQL code is compiled native or interpreted • Determines whether debug information is included • Can be set at system or session level • Possible values • Defaults are 'INTERPRETED','NON_DEBUG' • Invalid combinations • NATIVE and INTERPRETED • DEBUG and NON_DEBUG • NATIVE and DEBUG
Native PL/SQL Compilation • PLSQL_COMPILER_FLAGS • For example ALTER SESSION SET PLSQL_COMPILER_FLAGS = 'NATIVE'; ALTER SESSION SET PLSQL_COMPILER_FLAGS = 'INTERPRETED', 'DEBUG';
Native PL/SQL Compilation • PLSQL_NATIVE_MAKE_FILE_NAME • Determines full path to makefile used to create shared libraries containing natively compiled PL/SQL code • Set at SYSTEM level • Mandatory if PLSQL_COMPILER_FLAGS = 'NATIVE' • Should specify full pathname of makefile • Sample makefile is • $ORACLE_HOME/plsql/spnc_makefile.mk • No default value - must be set explicitly • For example: ALTER SESSION SET PLSQL_NATIVE_MAKE_FILE_NAME = '/u01/app/oracle/product/9.0.1/plsql/spnc_makefile.mk'
Native PL/SQL Compilation • PLSQL_NATIVE_MAKE_UTILITY • Determines full path to make utility used to process makefile specified by PLSQL_NATIVE_MAKE_FILE_NAME • Set at SYSTEM level • Mandatory if PLSQL_COMPILER_FLAGS = 'NATIVE' • Should specify full pathname of make utility • No default value - must be set explicitly • For example: ALTER SESSION SET PLSQL_NATIVE_MAKE_UTILITY = '/usr/ccs/bin/make';
Native PL/SQL Compilation • PLSQL_NATIVE_LIBRARY_DIR • Determines directory name used to store shared libraries that contains natively compiled PL/SQL code • Set at SYSTEM level • Mandatory if PLSQL_COMPILER_FLAGS = 'NATIVE' • Should be set to full pathname of specified directory • Oracle user must have write permissions on specified directory • Access by other users should be restricted • Directory must be created manually at operating system level • No default value - must be set explicitly • For example: ALTER SESSION SET PLSQL_NATIVE_LIBRARY_DIR = '/usr/app/oracle/product/9.0.1/plsql_libs;
Native PL/SQL Compilation • PLSQL_NATIVE_C_COMPILER • Should not be set • with an ALTER SYSTEM command • in init.ora • in stored parameter file (SPFILE) • Should be set in spnc_makefile.mk • For example: # Specify C Compiler#CC=/opt/SUNWspro/bin/cc
Native PL/SQL Compilation • PLSQL_NATIVE_LINKER • Should not be set • with an ALTER SYSTEM command • in init.ora • in stored parameter file (SPFILE) • Should be set in spnc_makefile.mk • For example: # Specify Linker#LD=/usr/ccs/bin/ld
Native PL/SQL Compilation • PLSQL_NATIVE_LIBRARY_SUBDIR_COUNT • Determines number of subdirectories to be created in directory specified by PLSQL_NATIVE_LIBRARY_DIR • Performance ofsome file operations degrades if there are a large number of files in a directory • Use this parameter to specify number of subdirectories that should be created • Directories should be called d0, d1, d2... dN where N is the value specified for this parameter • Set at SYSTEM level • Default value is 0 - do not use subdirectories
Native PL/SQL Compilation • To compile an interpreted function ALTER SESSION SET PLSQL_COMPILER_FLAGS = ‘INTERPRETED’;ALTER FUNCTION f1 COMPILE; • To compile a native function ALTER SESSION SET PLSQL_COMPILER_FLAGS = ‘NATIVE’;ALTER FUNCTION f2 COMPILE;
Native PL/SQL Compilation • Four tests were performed using the same user-defined function written in different languages • The PL/SQL version of the function was CREATE OR REPLACE FUNCTION double (n NUMBER) RETURN NUMBER IS v_total NUMBER;BEGIN v_total := 0; FOR f IN 1..n LOOP v_total:= v_total + 2; END LOOP; RETURN v_total;END;
Native PL/SQL Compilation • The function was called using the statement SELECT double (5000000) FROM dual; • Results were
Native PL/SQL Compilation • In Oracle 10.1 and above compiled native PL/SQL libraries are stored in BLOBs • Advantages • Libraries can be backed up using RMAN • Libraries compiled on primary database will be automatically propagated to standby
Thank you for your interest For more information and to provide feedback please contact me My e-mail address is: info@juliandyke.com My website address is: www.juliandyke.com