Tuesday, June 22, 2010

PLSql_Optimize_Level or Pragma Inline for Subprogram Inlining

Subprogram Inlining - The compiler puts the actual code of a subprogram where the call is.

Pro: Improves performance of the program.
Con: Compile time is extended. Program size is larger.



PLSQL_OPTIMIZE_LEVEL controls the degree to which the compiler can rearrange code to make your PL/SQL code run faster.

Alter Procedure Proc_x 
          Compile Plsql_Optimize_Level = ?; 

Alter Session Set PlSql_Optimize_Level = ?;
Alter System  Set PlSql_Optimize_Level = ?;
0Forfeits most of performance gains of 10g
1Moderate optimization: May eliminate unnecessary computations and exceptions.
2Agressive optimization: (Default) Like 1, but may also move code.
3The compiler performs automatic subprogram inlining where appropriate. (new in 11g) 


PRAGMA INLINE ( identifier , { 'YES' | 'NO' } ) ;

Create Or Replace Procedure Inline_Test
     ( Fld Varchar2 ) Is
     Pragma Inline(Some_Function,'YES');
Begin
     For Idx In 1..10 Loop
          Dbms_Output.Put_Line(Some_Function('abc'));
     End Loop;
End;

Besides procedures, and functions, it also impacts every call to CASE, CONTINUE-WHEN, EXECUTE IMMEDIATE, EXIT-WHEN, LOOP, and RETURN statements.

No comments:

Post a Comment