Everyone is looking for an edge. With PL/SQL that edge is
compiling the PL/SQL code into native code. This article will show you how to
setup and compile your PL/SQL procedures and packages.
The default behavior for creation of PL/SQL code execution
is purely interpretive. If you want to skip the interpreted aspect of PL/SQL
and jump through to native C code, then you must use a C compiler on the
system. When you do this Oracle generates native C code, then compiles it with
the C compiler on your system, turns it into shared libraries, and then it is
linked into the Oracle process. This means that when these procedures are
called they are immediately available for execution. All of this is dynamic and
you do not need to restart the database to take advantage of this feature. Just
remember, the only speed increase you will achieve is PL/SQL code execution,
not SQL execution. Therefore, if your PL/SQL code is laced with SQL statements
and not logical statements, the switch to C code will not buy you much speed.
Setup to Compile
1. Within
the $ORACLE_HOME/plsql directory, there is a makefile called spnc_makefile.mk.
You will need to change this file for the appropriate paths for the C compiler.
A quick look at this file and a few verifications proved un-eventful as Oracle
had all the paths set for my Linux installation. Table 1
will show the paths I verified and what command I used to verify them.
TABLE 1:
Verification of path entries in
$ORACLE_HOME/plsql/spnc_makefile.mk file
Entery in file |
Unix command to verify |
Output to Unix command |
PLSQLHOME= |
ls -d $ORACLE_HOME/plsql |
/u01/app/oracle/product/ |
PLSQLINCLUDE= |
ls -d $ORACLE_HOME/plsql/include |
/u01/app/oracle/product/ |
PLSQLPUBLIC= |
ls -d $ORACLE_HOME/plsql/public |
/u01/app/oracle/product/ |
RM=/bin/rm -f |
which rm |
/bin/rm |
CC=/usr/bin/gcc |
which gcc |
/usr/bin/gcc |
LD=/usr/bin/ld |
which ld |
/usr/bin/ld |
2. The
initialization parameter PLSQL_COMPILER_FLAGS must be set to NATIVE.
The default value for this parameter is INTERPRETED.
You can verify your current setting by issuing the ‘SHOW PARAMETER plsql_compiler_flags’
command. You can change the setting by issuing an ALTER SESSION or ALTER SYSTEM
command. Listing A shows my session to verify my
current setting and set this parameter to NATIVE.
LISTING A:
Session to set initializatio
parameter PLSQL_COMPILER_FLAGS
SQL> connect sys/<password> as sysdba
Connected.
SQL> show parameter plsql_compiler_flags
NAME TYPE VALUE
———————————— ———– ————————-
plsql_compiler_flags string INTERPRETEDSQL> ALTER SYSTEM SET plsql_compiler_flags = NATIVE SCOPE = both;
System altered.SQL> show parameter plsql_compiler_flags
NAME TYPE VALUE
———————————— ———– ————————-
plsql_compiler_flags string NATIVE
3. Listing B gives more parameters that you must set to
control the compiling of PL/SQL. Read through them and take appropriate action
according to your environment. Each of these parameters may be set through the
ALTER SYSTEM or ALTER SESSION commands. Listing C
gives my session for setting these parameters.
LISTING B:
Parameters for controlling PL/SQL compiling to Native C
Parameter |
Description |
Value |
PLSQL_NATIVE_LIBRARY_DIR |
is |
/u01/app/oracle/product/ |
PLSQL_NATIVE_C_COMPILER |
gives |
Use default in |
PLSQL_NATIVE_ |
Use If |
I set this to 500 and |
PLSQL_NATIVE_LINKER |
is |
Use default in |
PLSQL_NATIVE_MAKE_ |
this is the full path of the spnc_makefile.mk |
/u01/app/oracle/product/ |
PLSQL_NATIVE_MAKE_UTILITY |
is |
/usr/bin/gmake |
LISTING C:
Script for setting additional parameters for Native C
compiling
SQL> connect sys/<password> as sysdba
Connected.
SQL> show parameter native
NAME TYPE VALUE
———————————— ———– ——————————
plsql_native_c_compiler string
plsql_native_library_dir string
plsql_native_library_subdir_count integer 0
plsql_native_linker string
plsql_native_make_file_name string
plsql_native_make_utility stringSQL> alter system set PLSQL_NATIVE_LIBRARY_DIR =
‘/u01/app/oracle/product/9.2/plsql/lib’ scope=both;
System altered.
SQL> alter system set PLSQL_NATIVE_LIBRARY_SUBDIR_COUNT = 500 scope=both;
System altered.SQL> alter system set PLSQL_NATIVE_MAKE_FILE_NAME =
‘/u01/app/oracle/product/9.2/plsql/spnc_makefile.mk’ scope=both;
System altered.SQL> alter system set PLSQL_NATIVE_MAKE_UTILITY = ‘/usr/bin/gmake’ scope=both;
System altered.SQL> show parameter native
NAME TYPE VALUE
——————————— —— ——————————
plsql_native_c_compiler string
plsql_native_library_dir string /u01/app/oracle/product/9.2/plsql/lib
plsql_native_library_subdir_count integer 0
plsql_native_linker string
plsql_native_make_file_name string /u01/app/oracle/product/9.2/plsql/spnc_makefile.mk
plsql_native_make_utility string /usr/bin/gmake