Plsql Just Got Faster

27
PL/SQL Just Got Faster An Oracle White Paper 22 nd December 2003 Bryn Llewellyn, PL/SQL Product Manager Charles Wetherell, Consulting Member of Technical Staff Oracle Corporation Posted for download on otn.oracle.com/tech/pl_sql/htdocs/New_In_10gR1.htm Please check the site for updated versions.

description

Plsql Just Got Faster

Transcript of Plsql Just Got Faster

  • PL/SQL Just Got Faster An Oracle White Paper 22nd December 2003 Bryn Llewellyn, PL/SQL Product Manager Charles Wetherell, Consulting Member of Technical Staff Oracle Corporation Posted for download on otn.oracle.com/tech/pl_sql/htdocs/New_In_10gR1.htm Please check the site for updated versions.

  • PL/SQL Just Got Faster

    Executive Overview.............................................................................. 3 1. Introduction....................................................................................... 3 2. Improvements to the PL/SQL system............................................... 4

    2.1. PL/SQL compilation and execution........................................... 4 2.1.1. The front-end ...................................................................... 4 2.1.2. The back-end (a.k.a. code generator).................................. 5 2.1.3. The PL/SQL virtual machine .............................................. 5 2.1.4. Native compilation of PL/SQL ........................................... 6 2.1.5. Run time considerations...................................................... 6

    2.2. How to make PL/SQL programs run faster ............................... 6 2.3. What changes were made in Oracle10g? ................................... 8

    2.3.1. Front-end support for new language features ..................... 8 2.3.2. Brand new code generator using state-of-the-art optimizing technology..................................................................................... 9 2.3.3. Substantial PVM upgrade ................................................. 10 2.3.4. Changes in the regime for native compilation .................. 11

    3. Performance results......................................................................... 12 3.1. Results from the downloadable Performance Measurement Harness............................................................................................ 12

    3.1.1. Baseline_80 results ........................................................... 14 3.1.2. Baseline_9iR2 results ....................................................... 15 3.1.3. Baseline_10g results ......................................................... 15 3.1.4. Effect of new PL/SQL features......................................... 16

    3.2. Oracle Database 10g in action: performance data from IFS AB measured during the beta program.................................................. 16 3.3. The Oracle Corp Applications Development Teams benchmark suite .............................................................................. 17

    4. New possibilities for Application Desgin....................................... 18 5. Conclusion ...................................................................................... 18 Appendix: Charts generated by the test harness reporting program... 19

    PL/SQL Just Got Faster Page 2

  • PL/SQL Just Got Faster

    This is a revised version of paper # 40168 delivered at Oracle OpenWorld, San Francisco, September 2003.

    EXECUTIVE OVERVIEW Oracle Database 10g brings a new PL/SQL compiler and a newly tuned PL/SQL execution environment to Oracle users who can expect that PL/SQL programs will execute twice as fast as before. This paper describes the nature of these changes and presents performance experiments which substantiate the factor of two speedup.

    1. INTRODUCTION PL/SQL is a programming language with two purposes: first, to access SQL and second, to write procedural programs ranging in size from small fragments all the way up to complete applications. When PL/SQL is a carrier for SQL statements, the performance of the PL/SQL portion of the combination is generally not very important; execution of even the simplest interesting SQL operation takes much more time than does the typical PL/SQL statement. When PL/SQL is used as a conventional programming language, then its performance is important, just as is that of any other programming language. This paper addresses this second case only.

    Substantial changes have been made in Oracle Database 10g to the system for compiling and running PL/SQL programs and the result is dramatic performance improvements. This paper describes the general nature of these changes and presents some performance results which come from three distinct sources:

    Tests done at Oracle HQ using a PL/SQL performance measurement harness and a suite of about thirty test programs downloadable for customers from the OTN site.

    Customer tests conducted during the Oracle10g Beta Program by the Oracle Partner IFS.

    Tests using the benchmark suite developed and owned by the Applications Development Team at Oracle HQ.

    PL/SQL Just Got Faster Page 3

  • They all tell the same story PL/SQL programs run about twice as fast in Oracle Database 10g as they did in Oracle9i Database and about three times as fast as they did in Oracle8 Database.

    In Section 2 we explain the process of PL/SQL compilation and what can be done and by whom customer or PL/SQL Development Team to make PL/SQL programs run faster. Against that background, we explain the actual changes that have been made, both in Oracle Database 10g and in earlier database versions.

    In Section 3 we present the performance results. These are supplemented in the Appendix by copies of some of the charts that are automatically generated by the downloadable performance measurement harness.

    Well use the terms Oracle8.0, Oracle8i, Oracle9iR1, Oracle9iR2 and Oracle10g for brevity thus:

    Oracle8.0 Oracle8 Database version 8.0.6

    Oracle8i Oracle8i Database version 8.1.7

    Oracle9iR1 Oracle9i Database Release 1 version 9.0.1

    Oracle9iR2 Oracle9i Database Release 2 version 9.2.0

    Oracle10g Oracle Database 10g version 10.1.0

    2. IMPROVEMENTS TO THE PL/SQL SYSTEM This section describes how PL/SQL is compiled and executed. The innards of the PL/SQL system are exposed (at a high level) so that the changes made in Oracle10g can be understood. This understanding will allow us, in passing, to note some other Oracle10g PL/SQL enhancements.

    2.1. PL/SQL compilation and execution At a high level, the following account is applicable to the compilation and execution of a wide class of programming languages (especially interpreted ones for example, Java).

    2.1.1. The front-end

    The compiler front-end analyzes the source code for a single PL/SQL compilation unit, checking it for syntactical and semantic correctness. (A classic example of a semantic error is a syntactically correct reference to an element in a non-existent package.) If syntax or semantic errors are found, the front-end outputs an error report and compilation of the unit is aborted. The output for an error-free unit is an internal representation that exactly captures the source codes semantics. The PL/SQL compiler uses Diana (for Descriptive Intermediate Attributed Notation for Ada) for its internal representation, reflecting PL/SQLs historical debt to the Ada language. The front-end

    PL/SQL Just Got Faster Page 4

  • guarantees that when it doesnt report an error, the Diana it generates is correct and needs no further downstream correctness checking.

    The front-end always needs to be enhanced when new language features (like the CASE statement) are introduced. Depending on the new feature, it may be that the changes needed to support it are confined to the front-end.

    2.1.2. The back-end (a.k.a. code generator)

    The compiler back-end consumes the Diana and generates an executable representation of the program in the machine code of the target machine. Before Oracle9iR1, the output was always code for the PL/SQL Virtual Machine (a.k.a. PVM). You sometimes hear the term MCode used for the output that runs on the PVM. Oracle9iR1 introduced the option (via native compilation) to generate code for the hardware of the underlying computer.

    The terms Diana and MCode are both used occasionally in Oracle documentation. Neither is usually in the vocabulary of ordinary PL/SQL programmers unless size limits are encountered, but it will be convenient to use them in this paper.

    The compiler back-end plays a critical role in generating fast run-time code.

    2.1.3. The PL/SQL virtual machine

    The instruction set of the PVM is exactly analogous to that of a computer chip. The difference, of course, is that the PVM is implemented in software (it is written in C and linked into the ORACLE executable) while the instruction set of a chip is implemented directly in hardware. A computer implemented in software is commonly called a virtual machine and any interpreted language has such a machine.

    Each of PL/SQL and Java are compiled to run on its own specific virtual machine. And this is for the same reason: to simplify the task of implementing the language on a new hardware platform. Note that neither for PL/SQL nor for Java is the actual source code interpreted at run-time; both execute compiled machine code on a virtual machine implemented in software.

    Just as for the instruction set for any chip, the PVMs set has been designed to support the efficient execution of the kinds of program it typically runs. And just as with chips, successive revisions of the Oracle database bring changes to the PVM and for the same reasons: greater efficiency, both generically and specifically for common source-code idioms.

    There are two common kinds of change. An architectural change modifies the way the PVM operates. The most common changes add, remove, or modify instructions; but sometimes the layout of instructions, the way memory is organized or accessed, and other more fundamental changes are made. An implementation change simply improves performance through better

    PL/SQL Just Got Faster Page 5

  • programming of the virtual machine itself. A real example of this is to do the cheaper of two logical tests first if that keeps the more expensive test from being executed most of the time.

    2.1.4. Native compilation of PL/SQL

    The back-end can generate its output code in two different representations. In both cases it consumes the Diana for the current PL/SQL unit and computes the MCode. In the interpreted mode, it simply stores the MCode in system-managed structures in the SYS schema. In the native mode, it translates the MCode into C source code with the same semantics. (The MCode is not retained in this mode.) Broadly speaking, the housekeeping tasks that the PVM does on the fly (setting up and destroying temporary variables, managing stack frames for subprogram invocation, and so on) are now expressed at compile time in C. And the real work that the PVM does on the fly (by branching to call the appropriate routine that implements the current instruction) is expressed, again now at compile time, by calling that same routine from the generated C. The generated C is translated for execution as a dynamically linkable shared library for the ORACLE executable by automatically calling the appropriate platform-specific tools. Well call this a DLL for brevity. (The term varies from platform to platform.) New in Oracle10g, this DLL is stored, just as the MCode is, in system managed structures in the SYS schema.

    A PL/SQL unit will execute faster when compiled native than when compiled interpreted precisely because of the increased efficiency of the housekeeping tasks. The real work remains the same and is done by service routines shared with the PVM.

    2.1.5. Run time considerations

    The object code for a PL/SQL unit (whether MCode or a native DLL) is fetched on demand according to execution flow. The run-time system discovers just in time if the unit was compiled interpreted or native and sets it up for execution accordingly. The two flavors of object code are fully interoperable, but there is a performance cost for the context switch between the two execution modes. Thus the greatest benefits from native compilation will be seen when both the caller and the called PL/SQL unit are compiled native, even when the real work each or both does is trivial.

    2.2. How to make PL/SQL programs run faster Obviously the performance characteristics of a PL/SQL unit are influenced by how the author chooses and expresses the algorithm in PL/SQL. Without a psychic subsystem in the front-end, the compiler can do nothing to determine the programmers ultimate high-level intent! These two programs which calculate the nth term in the Fibonacci series a useful academic exercise although probably uncommon in PL/SQL applications illustrate the point.

    PL/SQL Just Got Faster Page 6

  • function Fib_N ( n in pls_integer ) return pls_integer -- Recursive solution is begin if n = 1 then return 1; elsif n = 2 then return 1; else return Fib_N ( n 1 ) + Fib_N ( n 2 ); end if; end Fib_N; function Fib_N ( n in pls_integer ) return pls_integer -- Iterative solution is current pls_integer; last_but_one pls_integer; last pls_integer; begin if n = 1 then return 1; elsif n = 2 then return 1; else last_but_one := 1; last := 1; for j in 3..n loop current := last_but_one + last; last_but_one := last; last := current; end loop; return current; end if; end Fib_N; Its not hard to see that the two functions compute the same value for all positive values of n. However, the recursive version takes about 2n steps to do the calculation and the iterative version takes about n steps. Even for the moderate value of n=25, the recursive version will be about 1,000,000 times slower than the iterative version. Unfortunately computer science theory shows that there will never be a compiler that turns a slow program like the recursive Fibonacci version automatically into its faster iterative cousin.

    Thus the best way to improve PL/SQL program performance is to choose the right algorithms and data structures in the first place!

    A second way to improve performance is to use the new language features provided in each release. For example, index-by-varchar2 associative arrays (new in Oracle9iR2) execute much more quickly than any alternative mechanisms that solve the same problems. PL/SQL programmers who use such new features appropriately will be rewarded with faster programs. Well list the changes for Oracle10g below.

    The remaining two ways to improve PL/SQL performance lie in the domain of the team that builds the PL/SQL compiler and the PVM. The speed of a PL/SQL

    PL/SQL Just Got Faster Page 7

  • program depends on the quality of the code the PL/SQL compiler generates measured roughly by the number of instructions generated and the speed at which each instruction executes. Oracle10g improves both of these substantially.

    The relative potential for improvement in program performance due to changes in the code generator or in the PVM can be understood by analogy with what determines the speed of a car journey. The choice of route (as the crow flies or hugely circuitous) is analogous to the code generation phase. And the speed at which you drive is analogous to the expressiveness and the efficiency of the PVM. Famously, choosing the optimal route, even when you drive conservatively in a modest car, gets you there much quicker than choosing a poor route and driving flat out in a sports car. Of course, driving a sports car flat out on the optimal route is quickest of all.

    2.3. What changes were made in Oracle10g? The forgoing Section 2.1 and Section 2.2 give us the framework to understand the changes made in Oracle10g.

    2.3.1. Front-end support for new language features

    These changes are necessarily evolutionary. Oracle10g introduces support for these new language features:

    the binary_float and binary_double datatypes (the IEEE datatypes).

    the regexp_like, regexp_instr, regexp_substr and regexp_replace builtins to support regular expression manipulation with standard POSIX syntax.

    multiset operations on nested table instances supporting operations like equals, union, intersect, except, member, and so on.

    the user-defined quote character.

    INDICES OF and VALUES OF syntax for FORALL.

    the distinction between binary_integer and pls_integer vanishes.

    Of course, these features all have efficient implementations. For example, the IEEE datatypes enjoy the benefit of machine arithmetic for mathematical real numbers. An appropriate algorithmic task that is expressed in PL/SQL using any of these new features will run very much faster than one that avoided them. (Note that the user-defined quote character is not a performance feature; rather, its a convenience feature for the programmer.)

    In the above list, all but the FORALL feature and the change concerning PL/SQL integers are, formally speaking, new features in SQL. PL/SQL has an obligation to support all such SQL features in a PL/SQL context (for example in PL/SQL assignment statements). This is a unique strength of PL/SQL and is closely related to the fact that it shares the same datatype system as SQL. The

    PL/SQL Just Got Faster Page 8

  • PL/SQL Development Team works to enable users to be able to use SQL and PL/SQL seamlessly together.

    That PL/SQL has two datatypes, binary_integer and pls_integer, for nominally the same purpose is an historical anomaly. The high order purpose is to represent mathematical integers compactly (in 32 bits) and to implement their arithmetic operations optimally by using machine arithmetic. The SQL datatype integer is in fact a constrained subtype of number and thus even in the context of a pure PL/SQL program, its representation is rather large (roughly speaking, a binary coded decimal in several bytes) and its arithmetic operations are implemented by C routines (library arithmetic) rather than in hardware. Both these features of integer are required to support the semantics defined in the SQL standard semantics that are not needed very often in a typical PL/SQL program!

    Unfortunately, before Oracle10g, binary_integer and pls_integer meet the stated purpose to different extents. The binary_integer datatype is older in the history of PL/SQL and is represented in 32 bits. However, its arithmetic operations are implemented using the library software routines for number. The younger pls_integer is also represented in 32 bits, but its arithmetic operations are implemented in hardware. Again unfortunately, the PL/SQL programmer is not always free to choose the ideal pls_integer. For example, a program may need to call extant subprograms whose formals are declared as binary_integer. Or a program may use the constrained subtypes naturaln and positiven to enjoy the benefits of the compiler generated constraint checking. It turns out that naturaln and positiven are subtypes of binary_integer!

    Oracle10g removes this confusion by redefining binary_integer to be identical to pls_integer. This has both a usability benefit and an immediate performance benefit for extant programs that accidentally or unavoidably use binary_integer. The effect is to speed up integer arithmetic in PL/SQL by a factor of 2.5 to 3. Further, the rules for the evaluation of expressions involving only a PL/SQL integer and small (less than 231) constants are simple the computation is done as machine integer arithmetic, not as SQL number arithmetic.

    2.3.2. Brand new code generator using state-of-the-art optimizing technology

    This change is revolutionary. Before Oracle10g, the code generator was relatively mechanical. Roughly speaking, what you wrote in PL/SQL is what ultimately the PVM executed for you. If you gave instructions that amounted to driving by back roads to get from A to B, then using the analogy from Section 2.2 your program followed that circuitous route at run time. The old code generator has been surgically removed and replaced by a brand new one that has the intelligence to spot that theres a direct route from A to B and to produce the correspondingly more efficient MCode.

    PL/SQL Just Got Faster Page 9

  • In this analogy, it is the result getting to B from A that counts. How you get there doesnt matter. Thus the exceptions you might raise if you followed an indirect route and could not raise by following the direct route are defined not to matter. It follows that a specially contrived program can be written whose Oracle10g behavior is detectably different from its pre-Oracle10g behavior. Having said that, no such cases have been detected in extensive regression testing and most would agree that such programs are badly written.

    This topic and others are the subject of a detailed technical white paper, Freedom, Order, and PL/SQL Optimization, published on OTN as a companion to this paper.

    The essential characteristic of an optimizing compiler is that it takes as broad a view as possible of what the source expresses and removes any computations which it can prove are not necessary to guarantee the final correct result. This is what gives the potential for huge performance benefits.

    The new code generator has a knob to control the effort it applies to eliminating superfluous computations. This is exposed as a new instance parameter plsql_optimize_level and has the allowed values 2, 1 and 0. Level 2 means apply most effort and it does therefore imply slightly longer compilation times. Nevertheless it is the default. Oracle Corporation recommends using level 1 only in situations where time becomes critical (for example, the run-time compilation of dynamically generated trivial PL/SQL). Level 0 means preserve the pre-Oracle10g execution order by taking no short cuts. It should be used only as a stopgap until badly written programs are debugged and rewritten because to use it is to sacrifice most of the performance benefits due to the new code generator.

    By the way, the new code generator existed side-by-side with the old one in the ORACLE executable for quite some time and a switch allowed choosing between the one or the other. This was possible because the input and the output for this subsystem are precisely defined. The switch was not exposed for customers, but the huge suites of regression tests used by various development groups at Oracle HQ were routinely run under both regimes during the period of co-existence before the old code generators final removal from Oracle10g. This allows us to be completely confident about the semantic correctness of the new code generator.

    2.3.3. Substantial PVM upgrade

    The PVM has been significantly reworked in Oracle10g in the ways outlined above.

    Obsolete instructions have been removed and new ones have been added. For example before Oracle10g, an assignment like this s := 'a' || 'b' || 'c' || ... || 'z';

    PL/SQL Just Got Faster Page 10

  • was implemented as a series of pairwise concatenations with the need to manage temporary intermediate results. Because concatenation is an extremely common PL/SQL idiom (for example in connection with populating actual parameters for Htp.Print), Oracle10g introduces new PVM instructions specifically to support one-shot concatenation of many terms. Another example, driven by the front-end enhancement to support binary_float and binary_double, is the new instructions to support IEEE conformant arithmetic operations directly via hardware arithmetic.

    The system for consuming the instructions has been streamlined (analogous to a more efficient scheme for handling registers in a new revision of a chip).

    The C routines that implement the instructions have been tuned (analogous to basing a new revision of a chip on smaller and therefore faster integrated circuitry).

    Note that theres a reciprocal relationship between code generator enhancements and machine enhancements. Design work for the code generator can require new PVM instructions. And changes to the PVM can suggest changes that could be made with advantage to the code generator. In fact the new code generator has been under design and construction since the release of Oracle 8.0. Though it has been formally released only now in Oracle10g, PVM changes from the same project have been leaked into successive Oracle releases from Oracle8i onwards in order to make performance improvements available as soon as possible.

    2.3.4. Changes in the regime for native compilation

    Before Oracle10g, the DLL generated by the back-end was stored canonically as a file on an operating system directory. This meant that special (manual) consideration had to be given to online backup, and that PL/SQL native compilation and RAC were interoperable only when the platform supported a genuine shared file system. In Oracle10g, the DLL is stored canonically in the database and is cached as a file on an operating system directory only on demand. Of course, all the necessary cache invalidation support is in place so that all instances participating in a RAC configuration will see the new copy of a DLL when a particular PL/SQL unit is recompiled native, exactly as they see the corresponding new copy of the MCode when the unit is recompiled interpreted.

    The configuration steps that the DBA follows to set up for native PL/SQL compilation have been radically simplified. The dependency on the platforms make utility has been removed. In Oracle10g, the corresponding logic is implemented directly in the ORACLE executable, and the requirement for configuration data has thus been correspondingly simplified. The only surviving

    PL/SQL Just Got Faster Page 11

  • degrees of freedom for DLL generation are the locations of the C compiler and linker. These are given in a configuration file which must be located at a non-negotiable location in the $ORACLE_HOME tree. The only supported tools are those supplied by the platform vendor and these are typically in a standard locations, so the DBA is very unlikely to need to access the configuration file.

    The instance parameters plsql_native_make_utility, plsql_native_make_file_name, plsql_native_c_compiler, and plsql_native_linker are now redundant. As a usability enhancement, the choice of native or interpreted mode is now governed by the new instance parameter plsql_code_type. (The old parameter plsql_compiler_flags is retained for backwards compatibility.)

    The subsystem that derives the C code from the MCode has been reworked to generate more efficient C and, of course, to acknowledge the new C routines that implement the new PVM instructions. Oracle10g also provides supported utilities to convert all PL/SQL units in a database to native or to interpreted to make it simple to gain the benefits of native execution.

    3. PERFORMANCE RESULTS The goal of the above changes was to speed up computational PL/SQL programs. The only way to know if that goal is met is by measuring PL/SQL execution performance.

    3.1. Results from the downloadable Performance Measurement Harness The performance test kit will be downloadable from here:

    otn.oracle.com/tech/pl_sql/htdocs/New_In_10gR1.htm It provides

    a suite of test programs.

    a harness to time them mechanically in various environments and to record the timings in a database table.

    a utility to analyze the timings and to produce a nicely formatted report.

    The report may optionally be generated with markup tags to allow it to be read into an Excel spreadsheet (using the Data > Get External Data command). Some of the resulting charts are included in the Appendix. The harness can be used by anybody on local equipment after a fully mechanical install. Moreover, its straightforward to add new programs (and to remove the shipped ones).

    The downloadable kit includes the performance report generated at Oracle HQ for the set of supplied test programs.

    The mechanical testing explores these degrees of freedom:

    PL/SQL Just Got Faster Page 12

  • Oracle version:

    Oracle8 Database version 8.0.6.0 Oracle8i Database version 8.1.7.4 Oracle9i Database Release 2 version 9.2.0.3 Oracle Database 10g, version 10.1.0.1

    plsql_code_type:

    interpreted native

    plsql_optimize_level:

    1 2

    Because the code type degree of freedom was introduced in Oracle9iR1 and because the optimize level degree of freedom was introduced in Oracle10g, there are eight distinct compilation conditions:

    Oracle8.0 Oracle8i Oracle9iR2 interpreted Oracle9iR2 native Oracle10g interpreted level 1 Oracle10g interpreted level 2 Oracle10g native level 1 Oracle10g native level 2

    The kit is described fully in a separate paper included with the kit itself. That paper presents and interprets the results. We direct the reader to that paper for all detail and limit ourselves here to presenting summary statistics for the improvement factors across the set of test programs.

    The set of test programs includes the so-called PLSMarks suite designed by the PL/SQL Development Team and consisting of twelve programs intended to cover a wide range of common PL/SQL programming tasks. Consistent with the aim of improving purely computational PL/SQL programs, these are independent of a connection to a database. The PLSMarks programs can be run in all database versions from Oracle8.0 onwards. These are supplemented by some extra programs, some of which run only in Oracle9iR2 and later and some of which (designed to test the performance benefit of new features like IEEE arithmetic) run only in Oracle10g.

    The improvement factor for each program running under the various compilation conditions is characterized using the CPU time to complete one execution on a quiet machine. We present the results in terms of speed by dividing the CPU time measured at the baseline version by that measured under the current conditions. The ratio represents the speed improvement factor for the

    PL/SQL Just Got Faster Page 13

  • current version with respect to the baseline version; the larger is the ratio, the greater is the improvement. For example, for an experiment with baseline Oracle8.0, a ratio of three means that the speed of the program is three times greater under the current measurement conditions than when run under Oracle8.0. Using the analogy from Section 2.2, the improved car goes three time as fast, so you get to your destination in one third of the time. We prefer to express our results in terms of speed rather than time because the improvement factors that characterize speed carry over to characterize throughput (number of tasks completed in unit time).

    The results below summarize measurements made with respect to three baselines: Oracle8.0, Oracle9iR2, and Oracle10g.

    3.1.1. Baseline_80 results

    The Baseline_80 results were measured using a set of eighteen test programs all of which compile and run in Oracle8.0 and therefore in all later versions.

    Each program was timed under each of the eight compilation conditions listed above. Table 1 shows the summary for a subset of these results measured under Oracle8.0, Oracle8i, Oracle9iR2 native, and Oracle10g native optimize level 2. (Full results for all the available compilation conditions are included with the download kit.) The figures in Table 1 are depicted as a box-and-whisker chart in Figure 2 in the Appendix and the underlying results (the speed of each of the eighteen test programs at each of the four compilation conditions) are depicted as a bar chart in Figure 1.

    Here the improvement factor is calculated with respect to Oracle8.0. We emphasize this by including the column of values 1.0 under the heading 8.0 the time at Oracle8.0 divided by the time at Oracle8.0 is unity!

    8.0 8i 9iR2 Nat 10g Nat L2 Min 1.00 0.94 1.54 1.64 1st quartile 1.00 1.08 1.85 2.94 Median 1.00 1.13 2.27 3.94 3rd quartile 1.00 1.40 2.63 5.36 Max 1.00 2.07 3.33 10.57 Table 1: Baseline_80 results

    We see that when we compare the speed at Oracle10g under the optimum conditions of code type and optimizer level with that at Oracle8.0, 75% of the tested programs are at least three times faster and 25% of them are at least five times faster. The median value is a factor of about four.

    The full results for all the available compilation conditions show that Oracle9iR2 interpreted is already faster than Oracle8.0 by virtue of the

    PL/SQL Just Got Faster Page 14

  • incremental release of PVM improvements as explained in Section 2.3.3. The median is a factor of about 1.4. Native compilation, new in Oracle9iR1, is responsible for boosting the median to the factor of about 2.3 seen in Table 1.

    3.1.2. Baseline_9iR2 results

    The Baseline_9iR2 results were measured by adding three more programs to the set used for the Baseline_80 measurement. The additional test programs use index-by-varchar2 associative arrays, new in Oracle9iR2.

    Each program was timed under each of the six compilation conditions listed above starting from Oracle9iR2 interpreted. Table 2 shows the summary for a subset of these results measured under Oracle9iR2 interpreted, Oracle9iR2 native, and Oracle10g native optimize level 2. (Full results for all the available compilation conditions are included with the download kit.) The Appendix includes the corresponding box-and-whisker chart (Figure 4) and bar chart (Figure 3).

    Here we focus on the improvement factor calculated with respect to Oracle9iR2 interpreted. We emphasize this by including the column of values 1.0 under the heading 9iR2 Int.

    9iR2 Int 9iR2 Nat 10g Nat L2

    Min 1.00 1.12 1.19

    1st quartile 1.00 1.36 2.13

    Median 1.00 1.50 2.64

    3rd quartile 1.00 1.61 3.66

    Max 1.00 2.88 7.57

    Table 2: Baseline_9iR2 results

    We see that when we compare the speed at Oracle10g under the optimum conditions of code type and optimizer level with that at Oracle9iR2 under the default compilation conditions, 75% of the tested programs are at least twice as fast and 25% of them are at least three and a half times faster. The median value is a factor of about two and a half.

    3.1.3. Baseline_10g results

    The Baseline_10g results were measured by adding seven more programs to the set used for the Baseline_9iR2 measurement. These are reimplementations of seven of the Baseline_80 test programs written using new features like IEEE arithmetic and index-by-varchar2 associative arrays.

    Each program was timed under each of the four available Oracle10g compilation conditions: Oracle10g interpreted optimize level 1, Oracle10g interpreted

    PL/SQL Just Got Faster Page 15

  • optimize level 2, Oracle10g native optimize level 1, and Oracle10g native optimize level 2. Table 3 shows the summary for these results. The Appendix includes the corresponding box-and-whisker chart (Figure 6) and bar chart (Figure 5).

    We see that when we compare the speed at Oracle10g under the optimum conditions of code type and optimizer level with that under the least favorable conditions, 75% of the tested programs are at least 1.2 times as fast and 25% of them are at least 1.6 times faster. The median value is a factor of about 1.4.

    10g Int L1 10g Int L2 10g Nat L1 10g Nat L2 Min 1.00 1.00 1.05 1.05 1st quartile 1.00 1.03 1.17 1.26 Median 1.00 1.09 1.35 1.41 3rd quartile 1.00 1.13 1.49 1.67 Max 1.00 1.38 2.32 2.42 Table 3: Baseline_10g results

    3.1.4. Effect of new PL/SQL features

    The speed of each of the seven reimplemented programs was compared to that of the corresponding original using measurements made in the Oracle10g native level 2 environment. The improvement factor from the new features ranged between a factor of 1.2 and a factor of 13.2. These are depicted in a bar chart in Figure 7 in the Appendix.

    In each of Table 1, Table 2, and Table 3, the median value in the last column is impressive. And in each, the maximum value is dramatically large!

    3.2. Oracle Database 10g in action: performance data from IFS AB measured during the beta program IFS (www.ifsworld.com) develops and supplies component-based business applications for medium and large enterprises. IFS Applications offers 60+ enterprise application components used in manufacturing, supply chain management, customer relationship management, service provision, financials, product development, maintenance, and human resource administration.

    IFS is a leading global business applications supplier with sales in 45 countries and more than 350,000 users worldwide. The company is listed on the Stockholm Stock Exchange (XSSE: IFS).

    IFS Applications uses Oracle extensively and most of the business logic is written in PL/SQL. It has about 3000 tables, about 5000 views, and about 5000 packages with about 4.2 million lines of PL/SQL code. All PL/SQL code is executed in the database.

    PL/SQL Just Got Faster Page 16

  • At the time of writing, IFS is actively participating in the Oracle10g Beta Program. They have conducted extensive PL/SQL performance tests.

    They conducted two types of tests:

    They timed two specially written pure PL/SQL test programs which emulate the kinds of computation (especially string manipulation) that are typical in their applications.

    They timed a mechanical scenario which repeatedly executes a large number of distinct business transactions to emulate the profile of a typical workload. These transactions spend appreciable time in SQL.

    They confirmed that the results from these programs were identical in Oracle10g and in Oracle9iR2.

    The timings from the pure PL/SQL tests showed an overall speed improvement, comparing Oracle9iR2 interpreted with Oracle10g native level 2 ranging between a factor of 1.76 and a factor of 2.59. They reported:

    We are very excited about the figures we saw in our initial tests.

    The timings from the mixed SQL PL/SQL scenario showed an overall average speed improvement of about 18% (a factor of 1.18). They reported:

    We are excited over the figures. This overall performance increase is really good for our customers.

    Note that further performance improvements were made for the Oracle10g production release after the distribution of the Beta code which IFS used in their testing. It is likely that their results will be noticeably better when remeasured using the production release.

    3.3. The Oracle Corp Applications Development Teams benchmark suite The Applications Development Team at Oracle HQ has several benchmark suites which model a range of typical scenarios covering, for example, simulated high concurrency manual data entry and end-of-month payroll batch processing. The benchmarks yield appropriate figures of merit, typically throughput in transactions per second. (The batch processing is inherently parallelizable.)

    They also have instrumented programs in a test environment to isolate the time spent in PL/SQL for compute-intensive processing.

    They have informally provided some preliminary results measured for Oracle10g Beta2 versus Oracle9iR2. The improvement for throughput for the simulated data entry processing is about 15% (a factor of 1.15). And the improvement factor for pure PL/SQL processing is on the order of a factor of 2. We expect these values to increase when they are remeasured in the Oracle10g production release.

    PL/SQL Just Got Faster Page 17

  • 4. NEW POSSIBILITIES FOR APPLICATION DESGIN Because of the speedup of PL/SQL in Oracle10g, we believe that new classes of application that until now have been implemented in a 3GL Oracle client (especially, for example, written in Pro*C) will enjoy a net speedup if re-implemented in database PL/SQL. Such applications extract large quantities of data from a database, carry out computationally intensive processing, and insert large volumes of derived data back into the database.

    If the computation is carried out entirely in PL/SQL, the cost of the data transformation and transport to and from the other language is saved. Even though the computation will probably still be slower in PL/SQL than in, for example, C, the speedup of PL/SQL in Oracle10g will probably make the entire process faster when the transformation time is eleminated. Further, the applictaion will probaly be smaller and less prone to error if only because it is implemented in one language rather than two. Obviously, the decision to design an applictaion this way requires study and judgement, but it appears that faster PL/SQL makes new design opprotunities available.

    5. CONCLUSION PL/SQL has indeed just gotten faster, and dramatically so, because Oracle Database 10g introduces

    an entirely new optimizing PL/SQL code generator,

    a redesigned and tightly tuned PL/SQL Virtual Machine,

    usability and performance improvements to native compilation,

    performance oriented PL/SQL features notably IEEE numeric types and revised PL/SQL integer computations.

    PL/SQL computational programs should run at least three times as fast as they did in Oracle8 Database version 8.0.6, and at least twice as fast as they did in Oracle9i Database Release 2 version 9.2.0. (Oracle9iR2 is already about one and a half times as fast as Oracle8.0 because of the evolutionary PVM improvements that were leaked in to successive releases before the revolutionary introduction of the new code-generator in Oracle10g.)

    Focusing on the Oracle9iR2 to Oracle10g improvement, even when mixed with heavy doses of SQL, overall application speedups of at least 15% were observed. And programs which happen to be especially suitable for improvement speed up by factors of four to seven! All in all,

    PL/SQL just got faster its twice as fast in Oracle10g as in Oracle9iR2.

    PL/SQL Just Got Faster Page 18

  • APPENDIX: CHARTS GENERATED BY THE TEST HARNESS REPORTING PROGRAM The following pages show sample output from the test harness reporting program.

    The first bar chart shows the improvement factor for each program in the Baseline_80 set under the indicated compilation conditions. The second shows the corresponding data for the Baseline_9iR2 set, and the third shows the corresponding data for the Baseline_10g set. Each is followed by its statistical summary (minimum, first quartile, median, third quartile, and maximum values) shown as a box and whisker plot.

    The final bar chart shows the improvement factor for the reimplementation (using new features like IEEE arithmetic) for each of the seven programs that allowed such reimplementation.

    Here is the list of charts:

    Figure 1: Baseline_80 barchart

    Figure 2: Baseline_80 boxplot

    Figure 3: Baseline_9iR2 barchart

    Figure 4: Baseline_9iR2 boxplot

    Figure 5: Baseline_10g barchart

    Figure 6: Baseline_10g boxplot

    Figure 7: Benefit due to reimplementation using new features

    The full explanation is given in the white paper PL/SQL Performance Measurement Harness that ships with the downloadable kit.

    PL/SQL Just Got Faster Page 19

  • Figure 1: Baseline_80 barchart

    0.00

    2.00

    4.00

    6.00

    8.00

    10.00

    12.00

    PlsMa

    rks_W

    hetst

    one

    PlsMa

    rks_W

    s_No

    _Math

    Euler

    _Pi_S

    eries

    PlsMa

    rks_C

    enter

    Leibn

    iz_Pi_

    Serie

    s

    Varch

    ar2_C

    atena

    tion

    PlsMa

    rks_B

    inSea

    rch6

    PlsMa

    rks_K

    ernel_

    03Tri

    angle

    s

    PlsMa

    rks_B

    ool2

    Fib_N

    _Rec

    ursive

    PlsMa

    rks_F

    lexfie

    lds

    PlsMa

    rks_N

    etmod

    el

    PlsMa

    rks_K

    ernel_

    01Pls

    Marks

    _Top

    PlsMa

    rks_C

    odeit

    PlsMa

    rks_S

    ieve

    PlsMa

    rks_K

    ernel_

    02

    808i9iR2 Nat10g Nat L2

  • Figure 2: Baseline_80 boxplot

    0.00

    2.00

    4.00

    6.00

    8.00

    10.00

    12.00

    80 8i 9iR2 Nat 10g Nat L2

  • Figure 3: Baseline_9iR2 barchart

    0.00

    1.00

    2.00

    3.00

    4.00

    5.00

    6.00

    7.00

    8.00

    PlsMa

    rks_W

    hetst

    one

    Euler

    _Pi_S

    eries

    Leibn

    iz_Pi_

    Serie

    s

    PlsMa

    rks_W

    s_No

    _Math

    Lex_

    Via_T

    ransla

    te

    PlsMa

    rks_C

    enter

    PlsMa

    rks_K

    ernel_

    03

    Varch

    ar2_C

    atena

    tion

    Trian

    gles

    PlsMa

    rks_F

    lexfie

    lds

    Lex_

    Via_S

    ubstr

    _Inlin

    ed

    PlsMa

    rks_B

    inSea

    rch6

    Lex_

    Via_S

    ubstr

    PlsMa

    rks_K

    ernel_

    01

    PlsMa

    rks_B

    ool2

    Fib_N

    _Rec

    ursive

    PlsMa

    rks_C

    odeit

    PlsMa

    rks_T

    op

    PlsMa

    rks_N

    etmod

    el

    PlsMa

    rks_S

    ieve

    PlsMa

    rks_K

    ernel_

    02

    9iR2 Int9iR2 Nat10g Nat L2

  • Figure 4: Baseline_9iR2 boxplot

    0.00

    1.00

    2.00

    3.00

    4.00

    5.00

    6.00

    7.00

    8.00

    9iR2 Int 9iR2 Nat 10g Nat L2

  • Figure 5: Baseline_10g barchart

    0.00

    0.50

    1.00

    1.50

    2.00

    2.50

    3.00

    PlsMa

    rks_W

    hetst

    one

    Varch

    ar2_C

    atena

    tion

    Euler

    _Pi_S

    eries

    PlsMa

    rks_C

    enter

    Leibn

    iz_Pi_

    Serie

    s

    PlsMa

    rks_W

    s_No

    _Math

    PlsMa

    rks_K

    ernel_

    03

    Trian

    gles_

    10g

    Trian

    gles

    Lex_

    Via_T

    ransla

    te

    PlsMa

    rks_F

    lexfie

    lds

    Lex_

    Via_S

    ubstr

    _Inlin

    ed

    PlsMa

    rks_B

    ool2

    Lex_

    Via_S

    ubstr

    PlsMa

    rks_K

    ernel_

    03_1

    0g

    PlsMa

    rks_C

    odeit

    PlsMa

    rks_B

    inSea

    rch6

    PlsMa

    rks_K

    ernel_

    01

    PlsMa

    rks_K

    ernel_

    02

    PlsMa

    rks_S

    ieve

    PlsMa

    rks_N

    etmod

    el

    PlsMa

    rks_N

    etmod

    el_10

    g

    Leibn

    iz_Pi_

    Serie

    s_10

    g

    PlsMa

    rks_W

    hetst

    one_

    10g

    Euler

    _Pi_S

    eries

    _10g

    PlsMa

    rks_W

    s_No

    _Math

    _10g

    PlsMa

    rks_T

    op

    Fib_N

    _Rec

    ursive

    10g Int L110g Int L210g Nat L110g Nat L2

  • Figure 6: Baseline_10g boxplot

    0.00

    0.50

    1.00

    1.50

    2.00

    2.50

    3.00

    10g Int L1 10g Int L2 10g Nat L1 10g Nat L2

  • Figure 7: Benefit due to reimplementation using new features

    0.00

    2.00

    4.00

    6.00

    8.00

    10.00

    12.00

    14.00

    PlsMa

    rks_N

    etmod

    el

    PlsMa

    rks_K

    ernel_

    03

    Trian

    gles

    Leibn

    iz_Pi_

    Serie

    sPls

    Marks

    _Ws_No

    _Math

    Euler

    _Pi_S

    eries

    PlsMa

    rks_W

    hetston

    e

    oldnew

  • PL/SQL Just Got Faster December 2003 Authors: Bryn Llewellyn, PL/SQL Product Manager, Oracle Corporation Charles Wetherell, Consulting Member of Technical Staff, Oracle Corporation The authors acknowlege invaluable contributions from Hkan Arpfors, Senior Software Architect, IFS AB, Linkping, Sweden Oracle Corporation World Headquarters 500 Oracle Parkway Redwood Shores, CA 94065 U.S.A. Worldwide Inquiries: Phone: +1.650.506.7000 Fax: +1.650.506.7200 www.oracle.com Oracle Corporation provides the software that powers the internet. Oracle is a registered trademark of Oracle Corporation. Various product and service names referenced herein may be trademarks of Oracle Corporation. All other product and service names mentioned may be trademarks of their respective owners. Copyright 2003 Oracle Corporation All rights reserved.