PL/SQL and Java Automatic Native Compilation
Up until the Oracle Database 11g release, the database always transformed PL/SQL code to C code first before executing it. This meant you needed a third-party C compiler to execute the C code. In Oracle Database 11g, the database skips the C compiler by directly translating PL/SQL source code to DLL for the server. The feature is called PL/SQL native compilation. Oracle also performs the linking and delinking itself and bypasses the file system directories for doing that. Oracle claims that its test show performance improvements as large as two-fold, with the native compilation of PL/SQL.
The really good news for DBAs is that it is extremely easy to take advantage of the native PL/SQL compilation capability. You simply set the appropriate value for the new initialization parameter plsql_code_type to turn automatic native PL/SQL compilation on, as the next section explains.
Using Real Native Compilation
Use the initialization parameter plsql_code_type to specify the compilation mode for PL/SQL library units. The parameter can take two values, interpreted and native.
- INTERPRETED: PL/SQL library units will be compiled to PL/SQL bytecode format. Such modules are executed by the PL/SQL interpreter engine.
- NATIVE: PL/SQL library units (with the possible exception of top-level anonymous PL/SQL blocks) will be compiled to native (machine) code. Such modules will be executed natively without incurring any interpreter overhead.
Setting the value of this parameter to compiled produces the default behavior where the database compiles PL/SQL code first to a PL/SQL bytecode format using the C compiler. The PL/SQL interpreter engine then executes the bytecode. By setting the parameter to the value native, you let the database compile the PL/SQL code to machine code and execute it natively without the need for an interpreter. The database stores the DLLs it generates from the PL/SQL source code in the database catalog, from where the Oracle executable loads the code directly without first using a file system to stage them.
When the value of this parameter is changed, it has no effect on PL/SQL library units that have already been compiled. The value of this parameter is stored persistently with each library unit.If a PL/SQL library unit is compiled native, all subsequent automatic recompilations of that library unit will use native compilation.
By default, the plsql_code_type parameter is set to the value interpreted, and you can turn native PL/SQL compilation on in the database by setting the plsql_code_type parameter to native, as shown here: plsql_code_type=native
You can check that the database is using the correct mode of PL/SQL compilation by issuing the following statement:
SQL> select name, value from v$parameter where
name like '%plsql%;
NAME VALUE
--------------------- ------------
plsql_code_type INTERPRETED
plsql_optimize_level 2
...
9 rows selected.
You can also use the alter system or alter session statements to change the value for the plsql_code_type parameter dynamically, without restarting the database. Any PL/SQL units that are already compiled won’t be affected by a change in the compilation mode. Also, even after you change the compilation mode, say from compiled to native, PL/SQL units that the database has already compiled will be recompiled in the original compilation mode.
Setting Up a PL/SQL Program Unit for Native Compilation
In order to set up a single PL/SQL program unit for native compilation, you must change the value of the plsql_code_type parameter to native from its default value of interpreted, by making the change and restarting the database or by using the alter system/session statement to change the value of the parameter. You can also issue the alter <PLSQL unit type> statement to enable native compilation for a single PL/SQL program unit. Let’s use a simple example that illustrates how to do this:
1. First, create a simple procedure, called TEST_NATIVE.
SQL> create or replace procedure test_native as
2 begin
3 dbms_output.put_line('Test Procedure.');
4* end test_native;
SQL> /
Procedure created.
2. Check the current PL/SQL compilation mode by issuing the following statement:
SQL> select plsql_code_type
2 from all_plsql_object_settings
3 where name='TEST_NATIVE';
PLSQL_CODE_TYPE
----------------
INTERPRETED
The query shows that, currently, the procedure TEST_NATIVE is set for interpreted compiling and not native compilation.
3. Issue the following alter procedure statement to change the compilation mode to native for just the TEST_NATIVE procedure.
SQL> alter procedure test_native compile plsql_code_type=native;
Procedure altered.
4. Confirm that the procedure TEST_NATIVE will now use native compilation, by issuing the following query on the DBA_PLSQL_OBJECT_SETTINGS view:
SQL> select plsql_code_type
2 from all_plsql_object_settings
3* where name='TEST_NATIVE';
PLSQL_CODE_TYPE
---------------
NATIVE
The value of native for the PLSQL_CODE_TYPE column means that from here on, the database will use native compilation for the TEST_NATIVE procedure. Recompiling a Database for PL/SQL Native Compilation You can use the dbmsupgnv.sql script provided with Oracle Database 11g to recompile all the PL/SQL modules in the database to compile natively. Follow these steps to recompile all the PL/SQL modules:
1.Shut down the database using the shutdown normal or shutdown immediate commands.
SQL> shutdown immediate;
In the initialization parameter file, set the plsql_code_type parameter to native so it will allow native compilation. plsql_code_type=native
2. You must also check to ensure that the value of the plsql_optimize_level parameter is at least 2. The default value for this parameter is 2.plsql_optimize_level=3 Because the value of the plsql_optimize_level parameter is more than 2, you don’t have to change the setting of this parameter.
3. Start the database with the startup upgrade command, which you specify when upgrading to a new release of the Oracle database.
SQL> connect sys/sammyy1 as sysdba
Connected to an idle instance.
SQL> startup upgrade
ORACLE instance started.
...
Database opened.
4.After the database is opened in the upgrade mode, execute the script dbmsupgnv.sql, located in the $ORACLE_HOME/rdbms/admin directory.
SQL> @$ORACLE_HOME/rdbms/admin/dbmsupgnv.sql
OC>#########################################################
DOC>########################################################
DOC> dbmsupgnv.sql completed successfully.
DOC> All PL/SQL procedures, functions, type bodies, triggers,
DOC> and type bodies objects in the database have been
DOC> invalidated and their settings set to native.
DOC>
DOC> Shut down and restart the database in normal mode and
DOC> run utlrp.sql to recompile invalid objects.
SQL>
When the dbmsupgnv.sql script completes executing, all PL/SQL procedures in the database are natively compiled.
5. Once the script finishes running, shut down the database and start it back up again. Run the utlrp.sql script located in the $ORACLE_HOME/rdbms/
admin directory to recompile the invalidated PL/SQL program units.
SQL> shutdown immediate;
SQL> startup
ORACLE instance started.
...
Database opened.
SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql
...
SQL> Rem END utlrp.sql
As a result of upgrading the database and compiling all PL/SQL units in the native mode, you don’t need to individually enable PL/SQL procedures for native compilation. You can always change the compilation mode back to the default value of interpreted by reversing the recompilation process shown here. You follow a procedure similar to the one shown here to compile all PL/SQL program units in the interpreted mode by running the script dbmsupgin.sql, also located in the $ORACLE_HOME/rdbms/admin directory.
Java Native Compilation
Oracle Database 11g uses the new initialization parameter java_jit_enabled to set the Java compilation mode. By default, the value of the java_jit_enabled initialization parameter is true, meaning Java native compilation is enabled in the database. As in the case of the PL/SQL native compilation, this feature allows the database to compile Java in the database natively without using a C compiler. Oracle claims that native compilation offers a 100 percent faster performance for both pure PL/SQL and Java code. Oracle’s Java native compilation is similar to that of the Java Development Kit and runs as an independent session in the server process that is transparent to the user. There’s only one compiler session per Oracle instance and the database stores the Java code for future recompilations. Java native compilation offers you the high performance of pure Java execution and is very easy to implement because you can enable it for the entire database, not merely when you actually execute the Java code in the database. The absence of a C compiler means you save on licensing and other costs involved in maintaining the compiler.
参考至: 《McGraw.Hill.OCP.Oracle.Database.11g.New.Features.for.Administrators.Exam.Guide.Apr.2008》
http://docs.oracle.com/cd/E11882_01/server.112/e40402/initparams196.htm#REFRN10253本文原创,转载请注明出处、作者
如有错误,欢迎指正
邮箱:czmcj@163.com
相关推荐
Thoroughly updated for Oracle Database 11g Release 2, this edition reveals new PL/SQL features and provides extensive code samples, ranging from simple examples to complex and complete applications, ...
- **JDeveloper**: An integrated development environment (IDE) provided by Oracle for building applications using Java and PL/SQL. This includes creating, editing, testing, and debugging PL/SQL code. ...
This section describes new features of PL/SQL release 10g, and provides pointers to additional information. The following sections describe the new features in PL/SQL: ■ New Features in PL/SQL for ...
- **Pre-Compilation**:Proc的主要任务是预编译PL/SQL代码,将其转换为C或FORTRAN可理解的形式,这样在运行时可以直接与Oracle数据库进行交互,而无需解析PL/SQL语句。 - **PL/SQL嵌入**:通过使用特定的语法,...
在Oracle 10g的第一个版本10.1中,PL/SQL的编译策略引入了“最佳编译”(Best Practices Compilation)的概念,这是为了提升代码的性能和优化。 “最佳编译”在10.1版本中默认启用,其主要目标是通过静态分析和优化...
Real Native PL/SQL and Java Compilation提供了更快的执行速度,通过将PL/SQL和Java代码编译成本地机器码,减少了解释执行的开销,提升了程序运行效率。 ### 可扩展存储 - **OLTP表压缩**:针对在线事务处理(OLTP...
1、适用于navicat等连接oracle所需oci.dll,包含orcale11g; 2、解决报错ORA-12737 Instant Client Light:unsupported server character set ZHS16GBK;3、解决报错 ORA-06552:PL/SQL:Compilation unit analysis ...
在使用IntelliJ IDEA(简称Idea)进行Java开发时,有时会遇到“Error:java: Compilation failed: internal java compiler error”的错误提示,这通常意味着编译过程中遇到了内部错误,可能是由于配置问题、环境问题...
在Oracle数据库管理中,"一键编译指定Oracle用户的所有无效对象"是一个常见的需求,尤其是在数据库迁移或升级过程中。无效对象通常是指由于依赖关系断裂、源代码丢失或与新环境不兼容等原因导致无法正常运行的对象,...
file_manager.sqlJava Layer TraceFileDisplay.java you need to compile this and use loadjava to deploy it into the TFMADMIN account sample compilation & load - see javacomp.txt test the Java layer - ...
javalang javalang 是一个用于处理 Java 源代码的纯 Python 库。javalang 提供了针对 Java 8 的词法分析器和解析器。该实现基于 http://docs.oracle.com/javase/specs/jls/se8/html/上的 Java 语言规范。下面对java...
Oracle SQL Hints是一种在Oracle数据库中用于优化SQL语句执行计划的辅助手段。通过在SQL语句中嵌入特定的指令,即HINT,可以向Oracle优化器强制指示使用特定的访问路径、关联方法等,以便绕过优化器的默认选择,从而...
JavaParser 是一个强大的开源库,专门用于解析、分析和修改 Java 源代码。这个工具在 Java 开发中尤其有用,因为它允许程序员在运行时或构建过程中动态处理和操作 Java 代码。`javaparser-core-3.6.16.jar` 文件是 ...
当遇到"PL/SQL: Compilation unit analysis terminated"这样的错误时,通常表示存储过程需要重新编译。 2. **赋权**: 在Oracle中,权限管理是通过GRANT和REVOKE语句实现的。GRANT用于赋予用户或角色执行特定操作...
在使用IntelliJ IDEA开发Java项目时,可能会遇到一个令人头疼的错误:“Error:java: Compilation failed: internal java compiler error”。这个错误通常意味着IDE在尝试编译代码时遇到了内部问题,可能是由于配置不...
### 批处理编译、重新编译与计划缓存问题详解 #### 概述 ...例如,当查询包含动态SQL时,SQL Server无法预先知道所有可能的参数值,因此可能不会对其进行参数化。理解这些例外情况对于优化性能至关重要。