0% found this document useful (0 votes)
8 views15 pages

Native PLSQLCompilation

This document discusses Oracle's native compilation feature for PL/SQL. It describes the parameters used to configure native compilation and compares the performance of interpreted, native compiled, Java, and C implementations of a PL/SQL function.

Uploaded by

taker223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views15 pages

Native PLSQLCompilation

This document discusses Oracle's native compilation feature for PL/SQL. It describes the parameters used to configure native compilation and compares the performance of interpreted, native compiled, Java, and C implementations of a PL/SQL function.

Uploaded by

taker223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 15

Native PL/SQL

Compilation

Julian Dyke
Independent Consultant

Web Version

1 © 2005 Julian Dyke 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


PLSQL_NATIVE_LIBRARY_DIR
PLSQL_NATIVE_MAKE_UTILITY
PLSQL_NATIVE_MAKE_FILE_NAME
PLSQL_NATIVE_C_COMPILER
PLSQL_NATIVE_LINKER
PLSQL_COMPILER_FLAGS

2 © 2005 Julian Dyke juliandyke.com


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

INTERPRETED compile in interpreted mode


NATIVE compile in native mode
DEBUG include debug information
NON_DEBUG no debug information

 Defaults are 'INTERPRETED','NON_DEBUG'


 Invalid combinations
 NATIVE and INTERPRETED
 DEBUG and NON_DEBUG
 NATIVE and DEBUG
3 © 2005 Julian Dyke juliandyke.com
Native PL/SQL Compilation
 PLSQL_COMPILER_FLAGS
 For example

ALTER SESSION
SET PLSQL_COMPILER_FLAGS = 'NATIVE';

ALTER SESSION
SET PLSQL_COMPILER_FLAGS = 'INTERPRETED', 'DEBUG';

4 © 2005 Julian Dyke juliandyke.com


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'

5 © 2005 Julian Dyke juliandyke.com


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';

6 © 2005 Julian Dyke juliandyke.com


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;

7 © 2005 Julian Dyke juliandyke.com


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

8 © 2005 Julian Dyke juliandyke.com


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

9 © 2005 Julian Dyke juliandyke.com


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 of some 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

1 © 2005 Julian Dyke juliandyke.com


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;

11 © 2005 Julian Dyke juliandyke.com


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;

1 © 2005 Julian Dyke juliandyke.com


Native PL/SQL Compilation
 The function was called using the statement

SELECT double (5000000)


FROM dual;

 Results were

Time (seconds)
Language
9.0.1 9.2.0
PL/SQL (Interpreted) 13.7 11.7
PL/SQL (Native Compiled) 6.0 5.9
Java Stored Procedure 1.6 1.6
C-based External Procedure 0.3 0.3

1 © 2005 Julian Dyke juliandyke.com


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

1 © 2005 Julian Dyke juliandyke.com


Thank you for your interest

For more information and to provide feedback

please contact me
My e-mail address is:
[email protected]

My website address is:

www.juliandyke.com

1 © 2005 Julian Dyke juliandyke.com

You might also like